@Override protected String normalizeCompositePathForLogging(String attributeName) { return collection.getRole() + '.' + attributeName; }
@Override public String toString() { return super.toString() + "(" + collection.getRole() + ")"; }
@Override public String toString() { return getClass().getName() + '(' + getRole() + ')'; }
public CollectionDataCachingConfigImpl( Collection collectionDescriptor, AccessType accessType) { super( accessType ); this.collectionDescriptor = collectionDescriptor; this.navigableRole = new NavigableRole( collectionDescriptor.getRole() ); }
@Override public void addCollectionBinding(Collection collection) throws DuplicateMappingException { final String collectionRole = collection.getRole(); if ( collectionBindingMap.containsKey( collectionRole ) ) { throw new DuplicateMappingException( DuplicateMappingException.Type.COLLECTION, collectionRole ); } collectionBindingMap.put( collectionRole, collection ); }
private void checkColumnDuplication(java.util.Set distinctColumns, Value value) throws MappingException { final boolean[] insertability = value.getColumnInsertability(); final boolean[] updatability = value.getColumnUpdateability(); final Iterator<Selectable> iterator = value.getColumnIterator(); int i = 0; while ( iterator.hasNext() ) { Selectable s = iterator.next(); // exclude formulas and coluns that are not insertable or updatable // since these values can be be repeated (HHH-5393) if ( !s.isFormula() && ( insertability[i] || updatability[i] ) ) { Column col = (Column) s; if ( !distinctColumns.add( col.getName() ) ) { throw new MappingException( "Repeated column in mapping for collection: " + getRole() + " column: " + col.getName() ); } } i++; } }
public void validate(Mapping mapping) throws MappingException { assert getKey() != null : "Collection key not bound : " + getRole(); assert getElement() != null : "Collection element not bound : " + getRole(); if ( !getKey().isValid( mapping ) ) { throw new MappingException( "collection foreign key mapping has wrong number of columns: " + getRole() + " type: " + getKey().getType().getName() ); } if ( !getElement().isValid( mapping ) ) { throw new MappingException( "collection element mapping has wrong number of columns: " + getRole() + " type: " + getElement().getType().getName() ); } checkColumnDuplication(); }
private static void checkFilterConditions(Collection collValue) { //for now it can't happen, but sometime soon... if ( ( collValue.getFilters().size() != 0 || StringHelper.isNotEmpty( collValue.getWhere() ) ) && collValue.getFetchMode() == FetchMode.JOIN && !( collValue.getElement() instanceof SimpleValue ) && //SimpleValue (CollectionOfElements) are always SELECT but it does not matter collValue.getElement().getFetchMode() != FetchMode.JOIN ) { throw new MappingException( "@ManyToMany or @CollectionOfElements defining filter or where without join fetching " + "not valid within collection using join fetching[" + collValue.getRole() + "]" ); } }
public Comparator getComparator() { if ( comparator == null && comparatorClassName != null ) { try { final ClassLoaderService classLoaderService = getMetadata().getMetadataBuildingOptions() .getServiceRegistry() .getService( ClassLoaderService.class ); setComparator( (Comparator) classLoaderService.classForName( comparatorClassName ).newInstance() ); } catch (Exception e) { throw new MappingException( "Could not instantiate comparator class [" + comparatorClassName + "] for collection " + getRole() ); } } return comparator; }
|| info.getAttributeName().startsWith( "value" ) ); if ( !specCompliant ) { log.nonCompliantMapConversion( collection.getRole() ); "@Convert placed on Map attribute [" + collection.getRole() + "] must define attributeName of 'key' or 'value'" ); "@Convert placed on Map attribute [" + collection.getRole() + "] must define attributeName of 'key' or 'value'" ); "Could not determine how to apply @Convert(attributeName='%s') to collection [%s]", info.getAttributeName(), collection.getRole()
@Test public void testCollectionPersisterSpecified() throws Exception { //tests the persister specified by the @Persister annotation on a collection Collection collection = metadata().getCollectionBinding( Deck.class.getName() + ".cards" ); assertEquals( "Incorrect Persister class for collection " + collection.getRole(), CollectionPersister.class, collection.getCollectionPersisterClass() ); }
private Class determineElementClass(XClass elementXClass) { if ( elementXClass != null ) { try { return getContext().getBootstrapContext().getReflectionManager().toClass( elementXClass ); } catch (Exception e) { log.debugf( "Unable to resolve XClass [%s] to Class for collection elements [%s]", elementXClass.getName(), collection.getRole() ); } } if ( collection.getElement() != null ) { if ( collection.getElement().getType() != null ) { return collection.getElement().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 element information for collection [%s]", collection.getRole() ); return null; }
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; } }
public ConverterDescriptor mapKeyAttributeConverterDescriptor(XProperty mapXProperty, XClass keyXClass) { AttributeConversionInfo info = locateAttributeConversionInfo( "key" ); if ( info != null ) { if ( info.isConversionDisabled() ) { return null; } else { try { return makeAttributeConverterDescriptor( info ); } catch (Exception e) { throw buildExceptionFromInstantiationError( info, e ); } } } log.debugf( "Attempting to locate auto-apply AttributeConverter for collection key [%s]", collection.getRole() ); // todo : do we need to pass along `XClass keyXClass`? return getContext().getMetadataCollector() .getAttributeConverterAutoApplyHandler() .findAutoApplyConverterForMapKey( mapXProperty, getContext() ); }
public ConverterDescriptor resolveElementAttributeConverterDescriptor(XProperty collectionXProperty, XClass elementXClass) { AttributeConversionInfo info = locateAttributeConversionInfo( "element" ); if ( info != null ) { if ( info.isConversionDisabled() ) { return null; } else { try { return makeAttributeConverterDescriptor( info ); } catch (Exception e) { throw buildExceptionFromInstantiationError( info, e ); } } } log.debugf( "Attempting to locate auto-apply AttributeConverter for collection element [%s]", collection.getRole() ); // todo : do we need to pass along `XClass elementXClass`? return getContext().getMetadataCollector() .getAttributeConverterAutoApplyHandler() .findAutoApplyConverterForCollectionElement( collectionXProperty, getContext() ); }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { final boolean debugEnabled = LOG.isDebugEnabled(); if ( debugEnabled ) { LOG.debugf( "Second pass for collection: %s", collection.getRole() ); } secondPass( persistentClasses, localInheritedMetas ); // using local since the inheritedMetas at this point is not the correct map since it is always the empty map collection.createAllKeys(); if ( debugEnabled ) { String msg = "Mapped collection key: " + columns( collection.getKey() ); if ( collection.isIndexed() ) msg += ", index: " + columns( ( (IndexedCollection) collection ).getIndex() ); if ( collection.isOneToMany() ) { msg += ", one-to-many: " + ( (OneToMany) collection.getElement() ).getReferencedEntityName(); } else { msg += ", element: " + columns( collection.getElement() ); } LOG.debug( msg ); } }
jpaOrderBy.value(), associatedClass, collection.getRole() ); if ( StringHelper.isNotEmpty( orderByFragment ) ) { LOG.debugf( "Mapping collection: %s -> %s", collection.getRole(), collection.getCollectionTable().getName() ); prop.setUpdateable( false ); prop.setSelectable( false ); prop.setCollectionRole( collection.getRole() ); prop.setEntityName( collection.getOwner().getEntityName() ); prop.setValue( collection.getKey() );
protected void createBackReferences() { if ( collectionBinding.isOneToMany() && !collectionBinding.isInverse() && !collectionBinding.getKey().isNullable() ) { // for non-inverse one-to-many, with a not-null fk, add a backref! String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName ); Backref prop = new Backref(); prop.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "Backref" ); prop.setUpdateable( false ); prop.setSelectable( false ); prop.setCollectionRole( collectionBinding.getRole() ); prop.setEntityName( collectionBinding.getOwner().getEntityName() ); prop.setValue( collectionBinding.getKey() ); referenced.addProperty( prop ); log.debugf( "Added virtual backref property [%s] : %s", prop.getName(), pluralAttributeSource.getAttributeRole().getFullPath() ); } }
log.debugf( "Mapping collection: %s -> %s", collectionBinding.getRole(), collectionBinding.getCollectionTable().getName() );