@SuppressWarnings("unchecked") @Override public U get(int index) { int size = array.count(); if (index < 0 || index >= size) { throw new IndexOutOfBoundsException("index = " + index + ", size = " + size); } return (U) array.objectAtIndex(index); }
/* * [PJYF Oct 19 2004] * This is a bad hack to get WO to create indes for external keys. * We use the primary key constrain generation to create our indexes. * But we need to be carefull not to overwrite previous constrains * */ protected boolean isSinglePrimaryKeyAttribute(EOAttribute attribute) { if (attribute == null) return false; EOEntity entity = (EOEntity) attribute.entity(); if ((entity == null) || entity.isAbstractEntity() || (entity.externalName() == null)) return false; NSArray primaryKeyAttributes = entity.primaryKeyAttributes(); if (primaryKeyAttributes.count() != 1) return false; return attribute.name().equals(((EOAttribute) primaryKeyAttributes.lastObject()).name()); }
public String _alterPhraseDeletingColumnsWithNames( NSArray columnNames, NSArray entityGroup, EOSchemaGenerationOptions options) { StringBuffer phrase = new StringBuffer(); int j = columnNames.count(); for (int i = 0; i < j; i++) { phrase.append( "" + (i == 0 ? "" : this._alterPhraseJoinString()) + "remove column " + columnNames.objectAtIndex(i)); } return phrase.toString(); }
public static Group fetchGroup(EOEditingContext editingContext, EOQualifier qualifier) { NSArray<Group> eoObjects = _Group.fetchGroups(editingContext, qualifier, null); Group eoObject; int count = eoObjects.count(); if (count == 0) { eoObject = null; } else if (count == 1) { eoObject = (Group) eoObjects.objectAtIndex(0); } else { throw new IllegalStateException( "There was more than one Group that matched the qualifier '" + qualifier + "'."); } return eoObject; }
public static Employee fetchEmployee(EOEditingContext editingContext, EOQualifier qualifier) { NSArray<Employee> eoObjects = _Employee.fetchEmployees(editingContext, qualifier, null); Employee eoObject; int count = eoObjects.count(); if (count == 0) { eoObject = null; } else if (count == 1) { eoObject = (Employee) eoObjects.objectAtIndex(0); } else { throw new IllegalStateException( "There was more than one Employee that matched the qualifier '" + qualifier + "'."); } return eoObject; }
public static Category fetchCategory(EOEditingContext editingContext, EOQualifier qualifier) { NSArray<Category> eoObjects = _Category.fetchCategories(editingContext, qualifier, null); Category eoObject; int count = eoObjects.count(); if (count == 0) { eoObject = null; } else if (count == 1) { eoObject = (Category) eoObjects.objectAtIndex(0); } else { throw new IllegalStateException( "There was more than one Category that matched the qualifier '" + qualifier + "'."); } return eoObject; }
public static MovieRole fetchMovieRole(EOEditingContext editingContext, EOQualifier qualifier) { NSArray<MovieRole> eoObjects = _MovieRole.fetchMovieRoles(editingContext, qualifier, null); MovieRole eoObject; int count = eoObjects.count(); if (count == 0) { eoObject = null; } else if (count == 1) { eoObject = (MovieRole) eoObjects.objectAtIndex(0); } else { throw new IllegalStateException( "There was more than one MovieRole that matched the qualifier '" + qualifier + "'."); } return eoObject; }
public static PDBPresentation fetchPDBPresentation( EOEditingContext editingContext, EOQualifier qualifier) { NSArray<PDBPresentation> eoObjects = _PDBPresentation.fetchPDBPresentations(editingContext, qualifier, null); PDBPresentation eoObject; int count = eoObjects.count(); if (count == 0) { eoObject = null; } else if (count == 1) { eoObject = eoObjects.objectAtIndex(0); } else { throw new IllegalStateException( "There was more than one PDBPresentation that matched the qualifier '" + qualifier + "'."); } return eoObject; }
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(); }
@Override public int size() { return array.count(); }
@Callback @BindSelector("count") public static int count(NSArray __self__, Selector __cmd__) { return __self__.count(); }