List of usage examples for org.apache.commons.collections Predicate Predicate
Predicate
From source file:org.apache.cayenne.wocompat.EOModelProcessor.java
public EOModelProcessor() { prototypeChecker = new Predicate() { @Override//from w w w . ja v a 2 s .c o m public boolean evaluate(Object object) { if (object == null) { return false; } String entityName = object.toString(); return entityName.startsWith("EO") && entityName.endsWith("Prototypes"); } }; }
From source file:org.apache.cayenne.xml.XMLUtil.java
/** * Returns the first element among the direct children that has a matching name. *///from ww w. java2s .c om static Element getChild(Node node, final String name) { Predicate p = new Predicate() { public boolean evaluate(Object object) { if (object instanceof Element) { Element e = (Element) object; return name.equals(e.getNodeName()); } return false; } }; return (Element) firstMatch(node.getChildNodes(), p); }
From source file:org.apache.cayenne.xml.XMLUtil.java
/** * Returns all elements among the direct children that have a matching name. *//* w ww . j av a2 s . co m*/ static List<Element> getChildren(Node node, final String name) { Predicate p = new Predicate() { public boolean evaluate(Object object) { if (object instanceof Element) { Element e = (Element) object; return name.equals(e.getNodeName()); } return false; } }; return (List<Element>) CollectionUtils.select(getChildren(node), p); }
From source file:org.apache.ddlutils.model.Table.java
/** * Gets a list of non-unique indices on this table. * //from w w w . ja v a 2s .co m * @return The unique indices */ public Index[] getNonUniqueIndices() { Collection nonUniqueIndices = CollectionUtils.select(_indices, new Predicate() { public boolean evaluate(Object input) { return !((Index) input).isUnique(); } }); return (Index[]) nonUniqueIndices.toArray(new Index[nonUniqueIndices.size()]); }
From source file:org.apache.ddlutils.model.Table.java
/** * Gets a list of unique indices on this table. * /*from w ww .j a va 2 s . c om*/ * @return The unique indices */ public Index[] getUniqueIndices() { Collection uniqueIndices = CollectionUtils.select(_indices, new Predicate() { public boolean evaluate(Object input) { return ((Index) input).isUnique(); } }); return (Index[]) uniqueIndices.toArray(new Index[uniqueIndices.size()]); }
From source file:org.apache.ddlutils.model.Table.java
/** * Returns the primary key columns of this table. * //from www . jav a2 s .c o m * @return The primary key columns */ public Column[] getPrimaryKeyColumns() { Collection pkColumns = CollectionUtils.select(_columns, new Predicate() { public boolean evaluate(Object input) { return ((Column) input).isPrimaryKey(); } }); return (Column[]) pkColumns.toArray(new Column[pkColumns.size()]); }
From source file:org.apache.ddlutils.model.Table.java
/** * Returns the auto increment columns in this table. If none are found, * then an empty array will be returned. * /* w w w . ja va2s .c o m*/ * @return The auto increment columns */ public Column[] getAutoIncrementColumns() { Collection autoIncrColumns = CollectionUtils.select(_columns, new Predicate() { public boolean evaluate(Object input) { return ((Column) input).isAutoIncrement(); } }); return (Column[]) autoIncrColumns.toArray(new Column[autoIncrColumns.size()]); }
From source file:org.apache.ddlutils.model.Table.java
/** * Returns the required (not-nullable) columns in this table. If none are found, * then an empty array will be returned. * /*www . ja v a 2s .com*/ * @return The required columns */ public Column[] getRequiredColumns() { Collection requiredColumns = CollectionUtils.select(_columns, new Predicate() { public boolean evaluate(Object input) { return ((Column) input).isRequired(); } }); return (Column[]) requiredColumns.toArray(new Column[requiredColumns.size()]); }
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * Returns all properties where the column is not non-autoincrement and for which the bean * either has a value or the column hasn't got a default value, for the given dyna class. * // ww w . j a v a 2s .co m * @param model The database model * @param dynaClass The dyna class * @param bean The bean * @return The properties */ private SqlDynaProperty[] getPropertiesForInsertion(Database model, SqlDynaClass dynaClass, final DynaBean bean) { SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties(); Collection result = CollectionUtils.select(Arrays.asList(properties), new Predicate() { public boolean evaluate(Object input) { SqlDynaProperty prop = (SqlDynaProperty) input; if (bean.get(prop.getName()) != null) { // we ignore properties for which a value is present in the bean // only if they are identity and identity override is off or // the platform does not allow the override of the auto-increment // specification return !prop.getColumn().isAutoIncrement() || (isIdentityOverrideOn() && getPlatformInfo().isIdentityOverrideAllowed()); } else { // we also return properties without a value in the bean // if they ain't auto-increment and don't have a default value // in this case, a NULL is inserted return !prop.getColumn().isAutoIncrement() && (prop.getColumn().getDefaultValue() == null); } } }); return (SqlDynaProperty[]) result.toArray(new SqlDynaProperty[result.size()]); }
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * Returns all identity properties whose value were defined by the database and which * now need to be read back from the DB. * // www . ja v a 2 s .c om * @param model The database model * @param dynaClass The dyna class * @param bean The bean * @return The columns */ private Column[] getRelevantIdentityColumns(Database model, SqlDynaClass dynaClass, final DynaBean bean) { SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties(); Collection relevantProperties = CollectionUtils.select(Arrays.asList(properties), new Predicate() { public boolean evaluate(Object input) { SqlDynaProperty prop = (SqlDynaProperty) input; // we only want those identity columns that were really specified by the DB // if the platform allows specification of values for identity columns // in INSERT/UPDATE statements, then we need to filter the corresponding // columns out return prop.getColumn().isAutoIncrement() && (!isIdentityOverrideOn() || !getPlatformInfo().isIdentityOverrideAllowed() || (bean.get(prop.getName()) == null)); } }); Column[] columns = new Column[relevantProperties.size()]; int idx = 0; for (Iterator propIt = relevantProperties.iterator(); propIt.hasNext(); idx++) { columns[idx] = ((SqlDynaProperty) propIt.next()).getColumn(); } return columns; }