- renamed isValueEqual() to isFieldValueEqual() as this method does check a class field (aka. attribute)
- now search criteria can be limit and skip found matches
- added support for string criteria
Signed-off-by:Roland Häder <roland@mxchange.org>
* @throws java.lang.reflect.InvocationTargetException Any other problems?
*/
@Override
- public boolean isValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ public boolean isFieldValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Not implemented
throw new UnsupportedOperationException(MessageFormat.format("Not implemented. columnName={0},bool={1}", columnName, bool)); //NOI18N
}
* @throws java.lang.IllegalAccessException If the method cannot be accessed
* @throws java.lang.reflect.InvocationTargetException Any other problems?
*/
- public boolean isValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException;
+ public boolean isFieldValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException;
/**
* Some "getter for a value from given column name. This name will be
* @return Whether all conditions are met
*/
@Override
- public boolean isValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ public boolean isFieldValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
// Trace message
this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool));
this.criteria.put(key, value);
}
+ @Override
+ public void addCriteria (final String key, final String value) {
+ // Add to map
+ this.criteria.put(key, value);
+ }
+
/**
* Gets all entries as a key-value pair
*
*/
public interface Criteria extends FrameworkInterface {
/**
- * Adds a binary criteria
+ * Adds a boolean criteria
*
* @param key Key of criteria
* @param value Value of criteria
*/
public void addCriteria (final String key, final boolean value);
+ /**
+ * Adds a string criteria
+ *
+ * @param key Key of criteria
+ * @param value Value of criteria
+ */
+ public void addCriteria (final String key, final String value);
+
/**
* Gets all values from underlaying map in an iterator.
*
* @author Roland Haeder
*/
public class SearchCriteria extends BaseCriteria implements SearchableCritera {
+ /**
+ * Limit of matches
+ */
+ private int limit;
+
+ /**
+ * Skipping of matches
+ */
+ private int skip;
+
/**
* Default constructor
*/
public SearchCriteria () {
}
+ @Override
+ public int getLimit () {
+ return this.limit;
+ }
+
+ @Override
+ public final void setLimit (final int limit) {
+ this.limit = limit;
+ }
+
+ @Override
+ public int getSkip () {
+ return this.skip;
+ }
+
+ @Override
+ public final void setSkip (final int skip) {
+ this.skip = skip;
+ }
+
@Override
public boolean matches (final Storeable storeable) {
// Trace message
* @author Roland Haeder
*/
public interface SearchableCritera extends Criteria {
-
/**
* Checks if the given instance of a Storeable class matches
*
* @return Whether the Storeable instance matches
*/
public boolean matches (final Storeable storeable);
+
+ /**
+ * Setter for limit of possible matches
+ *
+ * @param limit Limit of matches
+ */
+ public void setLimit (final int limit);
+
+ /**
+ * Getter for limit of possible matches
+ *
+ * @return Limit of matches
+ */
+ public int getLimit ();
+
+ /**
+ * Setter for skipping of possible matches
+ *
+ * @param skip Skipping of matches
+ */
+ public void setSkip (final int skip);
+
+ /**
+ * Getter for skipping of possible matches
+ *
+ * @return Skipping of matches
+ */
+ public int getSkip ();
}
}
}
+ // Is limit set?
+ if (critera.getLimit() > 0) {
+ // Is skip set?
+ if (critera.getSkip() > 0) {
+ // Limit with skip
+ query.append(String.format(" LIMIT %d,%d", critera.getSkip(), critera.getLimit()));
+ } else {
+ // Only limit
+ query.append(String.format(" LIMIT %d", critera.getLimit()));
+ }
+ }
+
// Full statement is complete here, better log it
this.getLogger().debug(MessageFormat.format("query={0} is complete.", query));