/** * Retrieve the count of objects using a list of keys and values to match. * * @param context The editing context to use * @param keysAndValues a list of keys and values to match, alternating "key", "value", "key", * "value"... * @return the count of objects that match the specified values */ public static int countOfObjectsMatchingValues( EOEditingContext context, Object... keysAndValues) { if (keysAndValues.length % 2 != 0) { throw new IllegalArgumentException( "There should a value " + "corresponding to every key that was passed. Args = " + java.util.Arrays.toString(keysAndValues)); } NSMutableDictionary<String, Object> valueDictionary = new NSMutableDictionary<String, Object>(); for (int i = 0; i < keysAndValues.length; i += 2) { Object key = keysAndValues[i]; Object value = keysAndValues[i + 1]; if (key == null) { throw new IllegalArgumentException( "Found null where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } else if (!(key instanceof String)) { throw new IllegalArgumentException( "Found a " + key.getClass().getName() + " [" + key + "]" + " where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } valueDictionary.setObjectForKey(value, (String) key); } return countOfObjectsMatchingValues(context, valueDictionary); }
/** * Retrieve objects according to the <code>subscriptionsForMessageTypeAndUser</code> fetch * specification. * * @param context The editing context to use * @param messageTypeBinding fetch spec parameter * @param userBinding fetch spec parameter * @return an NSArray of the entities retrieved */ public static NSArray<UserMessageSubscription> subscriptionsForMessageTypeAndUser( EOEditingContext context, String messageTypeBinding, org.webcat.core.User userBinding) { EOFetchSpecification spec = WCFetchSpecification.fetchSpecificationNamed( "subscriptionsForMessageTypeAndUser", "UserMessageSubscription"); NSMutableDictionary<String, Object> bindings = new NSMutableDictionary<String, Object>(); if (messageTypeBinding != null) { bindings.setObjectForKey(messageTypeBinding, "messageType"); } if (userBinding != null) { bindings.setObjectForKey(userBinding, "user"); } spec = spec.fetchSpecificationWithQualifierBindings(bindings); NSArray<UserMessageSubscription> objects = objectsWithFetchSpecification(context, spec); if (log.isDebugEnabled()) { log.debug( "subscriptionsForMessageTypeAndUser(ec" + ", " + messageTypeBinding + ", " + userBinding + "): " + objects); } return objects; }
public static NSArray<edu.umich.marketplace.eof.Category> fetchSubCategories( EOEditingContext editingContext, edu.umich.marketplace.eof.Category parentBinding) { EOFetchSpecification fetchSpec = EOFetchSpecification.fetchSpecificationNamed("subCategories", "Category"); NSMutableDictionary<String, Object> bindings = new NSMutableDictionary<String, Object>(); bindings.takeValueForKey(parentBinding, "parent"); fetchSpec = fetchSpec.fetchSpecificationWithQualifierBindings(bindings); return (NSArray<edu.umich.marketplace.eof.Category>) editingContext.objectsWithFetchSpecification(fetchSpec); }
public static NSArray<org.pachyderm.foundation.eof.PDBPresentation> fetchPresentationNamesAndIdentities(EOEditingContext editingContext, String authorBinding) { EOFetchSpecification fetchSpec = EOFetchSpecification.fetchSpecificationNamed( "presentationNamesAndIdentities", _PDBPresentation.ENTITY_NAME); NSMutableDictionary<String, Object> bindings = new NSMutableDictionary<String, Object>(); bindings.takeValueForKey(authorBinding, "author"); fetchSpec = fetchSpec.fetchSpecificationWithQualifierBindings(bindings); return (NSArray<org.pachyderm.foundation.eof.PDBPresentation>) editingContext.objectsWithFetchSpecification(fetchSpec); }
// [PJYF Nov 5 2004] // This is major Hack to generate a diffenrent bind dictionary for update and insert form the // one for select and delete public String sqlStringForForInsertOrUpdateValue(Object value, String keyPath) { EOAttribute attribute = this.entity()._attributeForPath(keyPath); if (value != NSKeyValueCoding.NullValue && (useBindVariables() && this.shouldUseBindVariableForAttribute(attribute) || this.mustUseBindVariableForAttribute(attribute))) { NSMutableDictionary bindVariableDictionary = this.bindVariableDictionaryForAttribute(attribute, value); this.addBindVariableDictionary(bindVariableDictionary); return (String) bindVariableDictionary.objectForKey(BindVariablePlaceHolderKey); } else { return this.formatValueForAttribute(value, attribute); } }
// High level all for top dictionary public NSMutableDictionary thePlotData() { NSMutableDictionary myPlot = new NSMutableDictionary(); NSMutableArray subPlotDict = new NSMutableArray(); Enumeration enumer = plots.objectEnumerator(); while (enumer.hasMoreElements()) { SubPlot currSubPlot = (SubPlot) enumer.nextElement(); subPlotDict.addObject(currSubPlot.toDictionary()); } // Title = "Defect Trends"; if (title != null) { myPlot.setObjectForKey(title, "Title"); } myPlot.setObjectForKey(subPlotDict, "Plots"); return (myPlot); }
public NSArray primaryKeyConstraintStatementsForEntityGroup(NSArray entityGroup) { if (entityGroup == null) return NSArray.EmptyArray; NSMutableDictionary columnNameDictionary = new NSMutableDictionary(); NSMutableArray primaryKeyConstraintExpressions = new NSMutableArray(); for (Enumeration enumerator = entityGroup.objectEnumerator(); enumerator.hasMoreElements(); ) { EOEntity entity = (EOEntity) enumerator.nextElement(); String tableName = entity.externalName(); NSArray primaryKeyAttributes = entity.primaryKeyAttributes(); boolean singlePrimaryKey = primaryKeyAttributes.count() == 1; if ((tableName != null) && (!"".equals(tableName)) && (primaryKeyAttributes.count() > 0)) { NSArray expressions = super.primaryKeyConstraintStatementsForEntityGroup(entityGroup); if ((expressions != null) && (expressions.count() > 0)) primaryKeyConstraintExpressions.addObjectsFromArray(expressions); for (Enumeration attributeEnumerator = primaryKeyAttributes.objectEnumerator(); attributeEnumerator.hasMoreElements(); ) { String columnName = ((EOAttribute) attributeEnumerator.nextElement()).columnName(); columnNameDictionary.setObjectForKey( columnName, entity.externalName() + "." + columnName); EOSQLExpression expression = this._expressionForString( "create " + (singlePrimaryKey ? "unique" : "") + " index " + entity.externalName() + " " + columnName); if (expression != null) primaryKeyConstraintExpressions.addObject(expression); } } } for (Enumeration enumerator = entityGroup.objectEnumerator(); enumerator.hasMoreElements(); ) { EOEntity entity = (EOEntity) enumerator.nextElement(); String tableName = entity.externalName(); if ((tableName != null) && (!"".equals(tableName))) { for (Enumeration relationshipEnumerator = entity.relationships().objectEnumerator(); relationshipEnumerator.hasMoreElements(); ) { EORelationship relationship = (EORelationship) relationshipEnumerator.nextElement(); if (!relationship.isFlattened()) { NSArray destinationAttributes = relationship.destinationAttributes(); // First exclude all the destination entity primary keys for (Enumeration attributeEnumerator = relationship.destinationEntity().primaryKeyAttributes().objectEnumerator(); attributeEnumerator.hasMoreElements(); ) { EOAttribute attribute = (EOAttribute) attributeEnumerator.nextElement(); columnNameDictionary.setObjectForKey( attribute.columnName(), relationship.destinationEntity().externalName() + "." + attribute.columnName()); } // Then deal with our end of things for (Enumeration attributeEnumerator = relationship.sourceAttributes().objectEnumerator(); attributeEnumerator.hasMoreElements(); ) { EOAttribute attribute = (EOAttribute) attributeEnumerator.nextElement(); if ((!this.isSinglePrimaryKeyAttribute(attribute)) && (columnNameDictionary.objectForKey(tableName + "." + attribute.columnName()) != null)) { columnNameDictionary.setObjectForKey( attribute.columnName(), tableName + "." + attribute.columnName()); EOSQLExpression expression = this._expressionForString( "create index " + tableName + " " + attribute.columnName()); if (expression != null) primaryKeyConstraintExpressions.addObject(expression); } } // Then deal with the other side if (entity.model() == relationship.destinationEntity().model()) { for (Enumeration attributeEnumerator = relationship.destinationAttributes().objectEnumerator(); attributeEnumerator.hasMoreElements(); ) { EOAttribute attribute = (EOAttribute) attributeEnumerator.nextElement(); String destinationTableName = relationship.destinationEntity().externalName(); if ((destinationTableName != null) && (!"".equals(destinationTableName))) { if ((!this.isSinglePrimaryKeyAttribute(attribute)) && (columnNameDictionary.objectForKey( destinationTableName + "." + attribute.columnName()) != null)) { columnNameDictionary.setObjectForKey( attribute.columnName(), destinationTableName + "." + attribute.columnName()); EOSQLExpression expression = this._expressionForString( "create index " + destinationTableName + " " + attribute.columnName()); if (expression != null) primaryKeyConstraintExpressions.addObject(expression); } if ((!relationship.isCompound()) && (relationship.sourceAttributes().count() == 1) && (relationship.destinationAttributes().count() == 1)) { String semantics; switch (relationship.joinSemantic()) { case EORelationship.FullOuterJoin: // '\001' case EORelationship.LeftOuterJoin: // '\002' case EORelationship.RightOuterJoin: // '\003' semantics = "*"; break; default: semantics = "="; break; } String sourceColumn = ((EOAttribute) relationship.sourceAttributes().objectAtIndex(0)) .columnName(); String destinationColumn = ((EOAttribute) relationship.destinationAttributes().objectAtIndex(0)) .columnName(); EOSQLExpression expression = this._expressionForString( "delete from _SYS_RELATIONSHIP where relationshipName = '" + relationship.name() + "' and source_table = '" + tableName + "' "); if (expression != null) primaryKeyConstraintExpressions.addObject(expression); expression = this._expressionForString( "insert into _SYS_RELATIONSHIP (relationshipName, source_table, source_column, dest_table, dest_column, operator, one_to_many) values ('" + relationship.name() + "','" + tableName + "','" + sourceColumn + "','" + destinationTableName + "','" + destinationColumn + "','" + semantics + "'," + (relationship.isToMany() ? 1 : 0) + ")"); if (expression != null) primaryKeyConstraintExpressions.addObject(expression); } } } } } } } } return primaryKeyConstraintExpressions.immutableClone(); }