void createPrimaryKey() { if ( !isOneToMany() ) { PrimaryKey pk = new PrimaryKey( getCollectionTable() ); pk.addColumns( getKey().getColumnIterator() ); Iterator iter = getIndex().getColumnIterator(); while ( iter.hasNext() ) { if ( ( (Selectable) iter.next() ).isFormula() ) { pk.addColumns( getElement().getColumnIterator() ); pk.addColumns( getIndex().getColumnIterator() ); getCollectionTable().setPrimaryKey(pk);
public void createAllKeys() throws MappingException { super.createAllKeys(); if ( !isInverse() ) { getIndex().createForeignKey(); } }
private void createIndexBackRef( MappingDocument mappingDocument, IndexedPluralAttributeSource pluralAttributeSource, IndexedCollection collectionBinding) { if ( collectionBinding.isOneToMany() && !collectionBinding.getKey().isNullable() && !collectionBinding.isInverse() ) { final String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName(); final PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref(); ib.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( collectionBinding.getRole() ); ib.setEntityName( collectionBinding.getOwner().getEntityName() ); ib.setValue( collectionBinding.getIndex() ); referenced.addProperty( ib ); } }
public void validate(Mapping mapping) throws MappingException { super.validate( mapping ); assert getElement() != null : "IndexedCollection index not bound : " + getRole(); if ( !getIndex().isValid(mapping) ) { throw new MappingException( "collection index mapping has wrong number of columns: " + getRole() + " type: " + getIndex().getType().getName() ); } }
/** * Returns whether we believe the map element should be included as part of the middle table's primary key. * * @return {@code true} if the element should be included as part of the key, otherwise {@code false}. */ private boolean isMapElementInPrimaryKey() { if ( propertyValue instanceof IndexedCollection ) { final Value index = ( (IndexedCollection) propertyValue ).getIndex(); return !index.getType().isEntityType(); } return true; } }
indexType = indexedCollection.getIndex().getType(); int indexSpan = indexedCollection.getIndex().getColumnSpan(); iter = indexedCollection.getIndex().getColumnIterator(); indexColumnNames = new String[indexSpan]; indexFormulaTemplates = new String[indexSpan]; baseIndex = indexedCollection.isList() ? ( (List) indexedCollection ).getBaseIndex() : 0; indexNodeName = indexedCollection.getIndexNodeName();
public void validate(Mapping mapping) throws MappingException { super.validate(mapping); if ( !getIndex().isValid(mapping) ) { throw new MappingException( "collection index mapping has wrong number of columns: " + getRole() + " type: " + getIndex().getType().getName() ); } if ( indexNodeName!=null && !indexNodeName.startsWith("@") ) { throw new MappingException("index node must be an attribute: " + indexNodeName ); } }
indexType = indexedCollection.getIndex().getType(); int indexSpan = indexedCollection.getIndex().getColumnSpan(); boolean[] indexColumnInsertability = indexedCollection.getIndex().getColumnInsertability(); boolean[] indexColumnUpdatability = indexedCollection.getIndex().getColumnUpdateability(); iter = indexedCollection.getIndex().getColumnIterator(); indexColumnNames = new String[indexSpan]; indexFormulaTemplates = new String[indexSpan]; baseIndex = indexedCollection.isList() ? ( (List) indexedCollection ).getBaseIndex() : 0;
void createPrimaryKey() { if ( !isOneToMany() ) { final MappedPrimaryKey pk = new PrimaryKey( getMappedTable() ); pk.addColumns( getKey().getMappedColumns() ); // index should be last column listed boolean isFormula = false; for( MappedColumn selectable : (List<MappedColumn>) getIndex().getMappedColumns() ){ if(selectable.isFormula()){ isFormula = true; } } if (isFormula) { //if it is a formula index, use the element columns in the PK pk.addColumns( getElement().getMappedColumns() ); } else { pk.addColumns( getIndex().getMappedColumns() ); } getMappedTable().setPrimaryKey(pk); } else { // don't create a unique key, 'cos some // databases don't like a UK on nullable // columns /*ArrayList list = new ArrayList(); list.addAll( getKey().getConstraintColumns() ); list.addAll( getIndex().getConstraintColumns() ); getCollectionTable().createUniqueKey(list);*/ } }
private Class determineKeyClass(XClass keyXClass) { if ( keyXClass != null ) { try { return getContext().getBootstrapContext().getReflectionManager().toClass( keyXClass ); } catch (Exception e) { log.debugf( "Unable to resolve XClass [%s] to Class for collection key [%s]", keyXClass.getName(), collection.getRole() ); } } final IndexedCollection indexedCollection = (IndexedCollection) collection; if ( indexedCollection.getIndex() != null ) { if ( indexedCollection.getIndex().getType() != null ) { return indexedCollection.getIndex().getType().getReturnedClass(); } } // currently this is called from paths where the element type really should be known, // so log the fact that we could not resolve the collection element info log.debugf( "Unable to resolve key information for collection [%s]", collection.getRole() ); return null; } }
if (hasIndex) { IndexedCollection indexedCollection = (IndexedCollection) collection; indexType = indexedCollection.getIndex().getType(); int indexSpan = indexedCollection.getIndex().getColumnSpan(); iter = indexedCollection.getIndex().getColumnIterator(); indexColumnNames = new String[indexSpan]; indexFormulaTemplates = new String[indexSpan]; baseIndex = indexedCollection.isList() ? ( (List) indexedCollection ).getBaseIndex() : 0; indexNodeName = indexedCollection.getIndexNodeName();
public void validate(Mapping mapping) throws MappingException { super.validate(mapping); if ( !getIndex().isValid(mapping) ) { throw new MappingException( "collection index mapping has wrong number of columns: " + getRole() + " type: " + getIndex().getType().getName() ); } if ( indexNodeName!=null && !indexNodeName.startsWith("@") ) { throw new MappingException("index node must be an attribute: " + indexNodeName ); } }
public String getGenericCollectionDeclaration(Collection collection, boolean preferRawTypeNames, ImportContext importContext) { Value element = collection.getElement(); String elementType = importContext.importType(getJavaTypeName(element, preferRawTypeNames)); String genericDecl = elementType; if(collection.isIndexed()) { IndexedCollection idxCol = (IndexedCollection) collection; if(!idxCol.isList()) { Value idxElement = idxCol.getIndex(); String indexType = importContext.importType(getJavaTypeName(idxElement, preferRawTypeNames)); genericDecl = indexType + "," + elementType; } } String decl = "<" + genericDecl + ">"; return decl; }
void createPrimaryKey() { if ( !isOneToMany() ) { PrimaryKey pk = new PrimaryKey(); pk.addColumns( getKey().getColumnIterator() ); // index should be last column listed boolean isFormula = false; Iterator iter = getIndex().getColumnIterator(); while ( iter.hasNext() ) { if ( ( (Selectable) iter.next() ).isFormula() ) isFormula=true; } if (isFormula) { //if it is a formula index, use the element columns in the PK pk.addColumns( getElement().getColumnIterator() ); } else { pk.addColumns( getIndex().getColumnIterator() ); } getCollectionTable().setPrimaryKey(pk); } else { // don't create a unique key, 'cos some // databases don't like a UK on nullable // columns /*ArrayList list = new ArrayList(); list.addAll( getKey().getConstraintColumns() ); list.addAll( getIndex().getConstraintColumns() ); getCollectionTable().createUniqueKey(list);*/ } }
private void createIndexBackRef( MappingDocument mappingDocument, IndexedPluralAttributeSource pluralAttributeSource, IndexedCollection collectionBinding) { if ( collectionBinding.isOneToMany() && !collectionBinding.getKey().isNullable() && !collectionBinding.isInverse() ) { final String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName(); final PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref( metadataBuildingContext ); ib.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( collectionBinding.getRole() ); ib.setEntityName( collectionBinding.getOwner().getEntityName() ); ib.setValue( collectionBinding.getIndex() ); referenced.addProperty( ib ); } }
private void checkColumnDuplication() throws MappingException { HashSet cols = new HashSet(); checkColumnDuplication( cols, getKey() ); if ( isIndexed() ) { checkColumnDuplication( cols, ( (IndexedCollection) this ).getIndex() ); } if ( isIdentified() ) { checkColumnDuplication( cols, ( (IdentifierCollection) this ).getIdentifier() ); } if ( !isOneToMany() ) { checkColumnDuplication( cols, getElement() ); } }
indexType = indexedCollection.getIndex().getType(); int indexSpan = indexedCollection.getIndex().getColumnSpan(); iter = indexedCollection.getIndex().getColumnIterator(); indexColumnNames = new String[indexSpan]; indexFormulaTemplates = new String[indexSpan]; baseIndex = indexedCollection.isList() ? ( (List) indexedCollection ).getBaseIndex() : 0; indexNodeName = indexedCollection.getIndexNodeName();
public void validate(Mapping mapping) throws MappingException { super.validate(mapping); if ( !getIndex().isValid(mapping) ) { throw new MappingException( "collection index mapping has wrong number of columns: " + getRole() + " type: " + getIndex().getType().getName() ); } if ( indexNodeName!=null && !indexNodeName.startsWith("@") ) { throw new MappingException("index node must be an attribute: " + indexNodeName ); } }
public String getGenericCollectionDeclaration(Collection collection, boolean preferRawTypeNames, ImportContext importContext) { Value element = collection.getElement(); String elementType = importContext.importType(getJavaTypeName(element, preferRawTypeNames)); String genericDecl = elementType; if(collection.isIndexed()) { IndexedCollection idxCol = (IndexedCollection) collection; if(!idxCol.isList()) { Value idxElement = idxCol.getIndex(); String indexType = importContext.importType(getJavaTypeName(idxElement, preferRawTypeNames)); genericDecl = indexType + "," + elementType; } } String decl = "<" + genericDecl + ">"; return decl; }
public void createAllKeys() throws MappingException { super.createAllKeys(); if ( !isInverse() ) { getIndex().createForeignKey(); } }