private static PersistentClass getSuperclass(Mappings mappings, Element subnode) throws MappingException { String extendsName = subnode.attributeValue( "extends" ); PersistentClass superModel = mappings.getClass( extendsName ); if ( superModel == null ) { String qualifiedExtendsName = getClassName( extendsName, mappings ); superModel = mappings.getClass( qualifiedExtendsName ); } if ( superModel == null ) { throw new MappingException( "Cannot extend unmapped class " + extendsName ); } return superModel; }
private static PersistentClass getSuperclass(Mappings mappings, Element subnode) throws MappingException { String extendsName = subnode.attributeValue( "extends" ); PersistentClass superModel = mappings.getClass( extendsName ); if ( superModel == null ) { String qualifiedExtendsName = getClassName( extendsName, mappings ); superModel = mappings.getClass( qualifiedExtendsName ); } if ( superModel == null ) { throw new MappingException( "Cannot extend unmapped class " + extendsName ); } return superModel; }
private static PersistentClass getSuperclass(Mappings mappings, Element subnode) throws MappingException { String superClass = getClassName( subnode.attributeValue( "extends" ), mappings ); PersistentClass superModel = mappings.getClass( superClass ); if ( superModel == null ) { throw new MappingException( "Cannot extend unmapped class " + superClass ); } return superModel; }
@Override public boolean isInPrimaryKey() { if ( entityClassName == null ) return false; final PersistentClass persistentClass = mappings.getClass( entityClassName ); Property property = persistentClass.getIdentifierProperty(); if ( path == null ) { return false; } else if ( property != null) { //try explicit identifier property return path.startsWith( property.getName() + "." ); } else { //try the embedded property //embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor if ( path.startsWith( "id." ) ) { KeyValue valueIdentifier = persistentClass.getIdentifier(); String localPath = path.substring( 3 ); if ( valueIdentifier instanceof Component ) { Iterator it = ( (Component) valueIdentifier ).getPropertyIterator(); while ( it.hasNext() ) { Property idProperty = (Property) it.next(); if ( localPath.startsWith( idProperty.getName() ) ) return true; } } } } return false; }
@Override public boolean isInPrimaryKey() { if ( entityClassName == null ) return false; final PersistentClass persistentClass = mappings.getClass( entityClassName ); Property property = persistentClass.getIdentifierProperty(); if ( path == null ) { return false; } else if ( property != null) { //try explicit identifier property return path.startsWith( property.getName() + "." ); } else { //try the embedded property //embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor if ( path.startsWith( "id." ) ) { KeyValue valueIdentifier = persistentClass.getIdentifier(); String localPath = path.substring( 3 ); if ( valueIdentifier instanceof Component ) { Iterator it = ( (Component) valueIdentifier ).getPropertyIterator(); while ( it.hasNext() ) { Property idProperty = (Property) it.next(); if ( localPath.startsWith( idProperty.getName() ) ) return true; } } } } return false; }
Element element = (Element) iterator.next(); String superClass = getClassName( element.attributeValue( "extends" ), mappings ); if ( mappings.getClass( superClass ) == null ) { extendz.add( superClass );
/** * Add all classes loaded in Naked Objects to the hibernate configuration */ public void configure(final Configuration cfg) { final Mappings mappings = cfg.createMappings(); for (Iterator<PersistentNakedClass> iter = persistentClasses.getPersistentClasses(); iter.hasNext();) { final PersistentNakedClass persistentClass = iter.next(); final String className = persistentClass.getName(); if (mappings.getClass(className) == null) { LOG.debug("binding persistent class " + className); final Document doc4j = createDocument(persistentClass); org.w3c.dom.Document docW3c = createW3cDoc(doc4j); cfg.addDocument(docW3c); writeMappingDoc(doc4j, className); } else { LOG.info("class [" + className + "] is already mapped, skipping.. "); } } }
private static NativeSQLQueryRootReturn bindReturn(Element returnElem, Mappings mappings, int elementCount) { String alias = returnElem.attributeValue( "alias" ); if( StringHelper.isEmpty( alias )) { alias = "alias_" + elementCount; // hack/workaround as sqlquery impl depend on having a key. } String entityName = HbmBinder.getEntityName(returnElem, mappings); if(entityName==null) { throw new MappingException( "<return alias='" + alias + "'> must specify either a class or entity-name"); } LockMode lockMode = getLockMode( returnElem.attributeValue( "lock-mode" ) ); PersistentClass pc = mappings.getClass( entityName ); java.util.Map propertyResults = bindPropertyResults(alias, returnElem, pc, mappings ); return new NativeSQLQueryRootReturn( alias, entityName, propertyResults, lockMode ); }
private static NativeSQLQueryRootReturn bindReturn(Element returnElem, Mappings mappings, int elementCount) { String alias = returnElem.attributeValue( "alias" ); if( StringHelper.isEmpty( alias )) { alias = "alias_" + elementCount; // hack/workaround as sqlquery impl depend on having a key. } String entityName = HbmBinder.getEntityName(returnElem, mappings); if(entityName==null) { throw new MappingException( "<return alias='" + alias + "'> must specify either a class or entity-name"); } LockMode lockMode = getLockMode( returnElem.attributeValue( "lock-mode" ) ); PersistentClass pc = mappings.getClass( entityName ); java.util.Map propertyResults = bindPropertyResults(alias, returnElem, pc, mappings ); return new NativeSQLQueryRootReturn( alias, entityName, propertyResults, lockMode ); }
public void doSecondPass(Map persistentClasses) throws MappingException { org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile( fetchProfileName, MetadataSource.ANNOTATIONS ); if ( MetadataSource.ANNOTATIONS != profile.getSource() ) { return; } PersistentClass clazz = mappings.getClass( fetch.entity().getName() ); // throws MappingException in case the property does not exist clazz.getProperty( fetch.association() ); profile.addFetch( fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase() ); } }
public void doSecondPass(Map persistentClasses) throws MappingException { org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile( fetchProfileName, MetadataSource.ANNOTATIONS ); if ( MetadataSource.ANNOTATIONS != profile.getSource() ) { return; } PersistentClass clazz = mappings.getClass( fetch.entity().getName() ); // throws MappingException in case the property does not exist clazz.getProperty( fetch.association() ); profile.addFetch( fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase() ); } }
private static PersistentClass getSuperEntity(XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, Mappings mappings, InheritanceState inheritanceState) { InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazzToProcess, inheritanceStatePerClass ); PersistentClass superEntity = superEntityState != null ? mappings.getClass( superEntityState.getClazz().getName() ) : null; if ( superEntity == null ) { //check if superclass is not a potential persistent class if ( inheritanceState.hasParents() ) { throw new AssertionFailure( "Subclass has to be binded after it's mother class: " + superEntityState.getClazz().getName() ); } } return superEntity; }
private void addMappedSuperClassInMetadata(PersistentClass persistentClass) { //add @MappedSuperclass in the metadata // classes from 0 to n-1 are @MappedSuperclass and should be linked org.hibernate.mapping.MappedSuperclass mappedSuperclass = null; final InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass ); PersistentClass superEntity = superEntityState != null ? mappings.getClass( superEntityState.getClazz().getName() ) : null; final int lastMappedSuperclass = classesToProcessForMappedSuperclass.size() - 1; for ( int index = 0; index < lastMappedSuperclass; index++ ) { org.hibernate.mapping.MappedSuperclass parentSuperclass = mappedSuperclass; final Class<?> type = mappings.getReflectionManager() .toClass( classesToProcessForMappedSuperclass.get( index ) ); //add MAppedSuperclass if not already there mappedSuperclass = mappings.getMappedSuperclass( type ); if ( mappedSuperclass == null ) { mappedSuperclass = new org.hibernate.mapping.MappedSuperclass( parentSuperclass, superEntity ); mappedSuperclass.setMappedClass( type ); mappings.addMappedSuperclass( type, mappedSuperclass ); } } if ( mappedSuperclass != null ) { persistentClass.setSuperMappedSuperclass( mappedSuperclass ); } }
private void addMappedSuperClassInMetadata(PersistentClass persistentClass) { //add @MappedSuperclass in the metadata // classes from 0 to n-1 are @MappedSuperclass and should be linked org.hibernate.mapping.MappedSuperclass mappedSuperclass = null; final InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass ); PersistentClass superEntity = superEntityState != null ? mappings.getClass( superEntityState.getClazz().getName() ) : null; final int lastMappedSuperclass = classesToProcessForMappedSuperclass.size() - 1; for ( int index = 0; index < lastMappedSuperclass; index++ ) { org.hibernate.mapping.MappedSuperclass parentSuperclass = mappedSuperclass; final Class<?> type = mappings.getReflectionManager() .toClass( classesToProcessForMappedSuperclass.get( index ) ); //add MAppedSuperclass if not already there mappedSuperclass = mappings.getMappedSuperclass( type ); if ( mappedSuperclass == null ) { mappedSuperclass = new org.hibernate.mapping.MappedSuperclass( parentSuperclass, superEntity ); mappedSuperclass.setMappedClass( type ); mappings.addMappedSuperclass( type, mappedSuperclass ); } } if ( mappedSuperclass != null ) { persistentClass.setSuperMappedSuperclass( mappedSuperclass ); } }
private static PersistentClass getSuperEntity(XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, Mappings mappings, InheritanceState inheritanceState) { InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazzToProcess, inheritanceStatePerClass ); PersistentClass superEntity = superEntityState != null ? mappings.getClass( superEntityState.getClazz().getName() ) : null; if ( superEntity == null ) { //check if superclass is not a potential persistent class if ( inheritanceState.hasParents() ) { throw new AssertionFailure( "Subclass has to be binded after it's mother class: " + superEntityState.getClazz().getName() ); } } return superEntity; }
PersistentClass referenced = mappings.getClass( entityName ); IndexBackref ib = new IndexBackref(); ib.setName( '_' + node.attributeValue( "name" ) + "IndexBackref" );
if (mappings.getClass(domainClass.getFullName()) != null) { LOG.info("[GrailsDomainBinder] Class [" + domainClass.getFullName() + "] is already mapped, skipping.. "); return;
PersistentClass referenced = mappings.getClass( entityName ); IndexBackref ib = new IndexBackref(); ib.setName( '_' + list.getOwnerEntityName() + "." + node.attributeValue( "name" ) + "IndexBackref" );
/** * Binds a unidirectional one-to-many creating a psuedo back reference property in the process. * * @param property * @param mappings * @param collection */ protected void bindUnidirectionalOneToMany(org.grails.datastore.mapping.model.types.OneToMany property, Mappings mappings, Collection collection) { Value v = collection.getElement(); v.createForeignKey(); String entityName; if (v instanceof ManyToOne) { ManyToOne manyToOne = (ManyToOne) v; entityName = manyToOne.getReferencedEntityName(); } else { entityName = ((OneToMany) v).getReferencedEntityName(); } collection.setInverse(false); PersistentClass referenced = mappings.getClass(entityName); Backref prop = new Backref(); PersistentEntity owner = property.getOwner(); prop.setEntityName(owner.getName()); prop.setName(UNDERSCORE + addUnderscore(owner.getJavaClass().getSimpleName(), property.getName()) + "Backref"); prop.setUpdateable(false); prop.setInsertable(true); prop.setCollectionRole(collection.getRole()); prop.setValue(collection.getKey()); prop.setOptional(true); referenced.addProperty(prop); }
/** * Binds a unidirectional one-to-many creating a psuedo back reference property in the process. * * @param property * @param mappings * @param collection */ private static void bindUnidirectionalOneToMany(GrailsDomainClassProperty property, Mappings mappings, Collection collection) { Value v = collection.getElement(); v.createForeignKey(); String entityName; if (v instanceof ManyToOne) { ManyToOne manyToOne = (ManyToOne) v; entityName = manyToOne.getReferencedEntityName(); } else { entityName = ((OneToMany) v).getReferencedEntityName(); } collection.setInverse(false); PersistentClass referenced = mappings.getClass(entityName); Backref prop = new Backref(); prop.setEntityName(property.getDomainClass().getFullName()); prop.setName(UNDERSCORE + addUnderscore(property.getDomainClass().getShortName(), property.getName()) + "Backref"); prop.setUpdateable(false); prop.setInsertable(true); prop.setCollectionRole(collection.getRole()); prop.setValue(collection.getKey()); prop.setOptional(true); referenced.addProperty(prop); }