private static void handleJoinedSubclass(PersistentClass model, Mappings mappings, Element subnode, java.util.Map inheritedMetas) throws MappingException { JoinedSubclass subclass = new JoinedSubclass( model ); bindJoinedSubclass( subnode, subclass, mappings, inheritedMetas ); model.addSubclass( subclass ); mappings.addClass( subclass ); }
private static void bindImport(Element importNode, Mappings mappings) { String className = getClassName( importNode.attribute( "class" ), mappings ); Attribute renameNode = importNode.attribute( "rename" ); String rename = ( renameNode == null ) ? StringHelper.unqualify( className ) : renameNode.getValue(); log.debug( "Import: " + rename + " -> " + className ); mappings.addImport( className, rename ); }
Mappings mappings, String subselect) { schema = BinderHelper.isEmptyAnnotationValue( schema ) ? mappings.getSchemaName() : schema; catalog = BinderHelper.isEmptyAnnotationValue( catalog ) ? mappings.getCatalogName() : catalog; String realTableName = mappings.getObjectNameNormalizer().normalizeDatabaseIdentifier( nameSource.getExplicitName(), namingStrategyHelper table = mappings.addDenormalizedTable( schema, catalog, table = mappings.addTable( schema, catalog, mappings.addUniqueConstraintHolders( table, uniqueConstraints ); mappings.addTableBinding( schema, catalog, logicalName, realTableName, denormalizedSuperTable );
protected String getJoinedSubClassTableName( HibernatePersistentEntity sub, PersistentClass model, Table denormalizedSuperTable, Mappings mappings, String sessionFactoryBeanName) { String logicalTableName = unqualify(model.getEntityName()); String physicalTableName = getTableName(sub, sessionFactoryBeanName); mappings.addTableBinding(mappings.getSchemaName(), mappings.getCatalogName(), logicalTableName, physicalTableName, denormalizedSuperTable); return physicalTableName; }
void addUniqueKey(String uniqueKeyName, boolean inSecondPass) { IndexOrUniqueKeySecondPass secondPass = new IndexOrUniqueKeySecondPass( uniqueKeyName, this, mappings, true ); if ( inSecondPass ) { secondPass.doSecondPass( mappings.getClasses() ); } else { mappings.addSecondPass( secondPass ); } }
private void manageIdentityGenerator(Mappings mappings, Table tab, SimpleValue id) { id.setIdentifierGeneratorStrategy(PortofinoIdentityGenerator.class.getName()); //"identity"); Properties params = new Properties(); params.put(PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer()); if (mappings.getSchemaName() != null) { params.setProperty( PersistentIdentifierGenerator.SCHEMA, mappings.getObjectNameNormalizer().normalizeIdentifierQuoting(mappings.getSchemaName())); } if (mappings.getCatalogName() != null) { params.setProperty( PersistentIdentifierGenerator.CATALOG, mappings.getObjectNameNormalizer().normalizeIdentifierQuoting(mappings.getCatalogName())); } id.setIdentifierGeneratorProperties(params); id.setNullValue(null); }
private static void bindCollectionTable(GrailsDomainClassProperty property, Mappings mappings, Collection collection, Table ownerTable, String sessionFactoryBeanName) { String prefix = ownerTable.getSchema(); PropertyConfig config = getPropertyConfig(property); JoinTable jt = config != null ? config.getJoinTable() : null; NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); String tableName = (prefix == null ? "" : prefix + '.') + (jt != null && jt.getName() != null ? jt.getName() : namingStrategy.tableName(calculateTableForMany(property, sessionFactoryBeanName))); String schemaName = mappings.getSchemaName(); String catalogName = mappings.getCatalogName(); if(jt != null) { if(jt.getSchema() != null) { schemaName = jt.getSchema(); } if(jt.getCatalog() != null) { catalogName = jt.getCatalog(); } } collection.setCollectionTable(mappings.addTable( schemaName, catalogName, tableName, null, false)); }
Table denormalizedSuperTable, Mappings mappings) { schema = BinderHelper.isEmptyAnnotationValue( schema ) ? mappings.getSchemaName() : schema; catalog = BinderHelper.isEmptyAnnotationValue( catalog ) ? mappings.getCatalogName() : catalog; Table table; if ( denormalizedSuperTable != null ) { table = mappings.addDenormalizedTable( schema, catalog, table = mappings.addTable( schema, catalog, mappings.addUniqueConstraints( table, uniqueConstraints ); mappings.addTableBinding( schema, catalog, logicalName, realTableName, denormalizedSuperTable );
public static void bindUnionSubclass(Element node, UnionSubclass unionSubclass, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindClass( node, unionSubclass, mappings, inheritedMetas ); inheritedMetas = getMetas( node, inheritedMetas, true ); // get meta's from <subclass> Attribute schemaNode = node.attribute( "schema" ); String schema = schemaNode == null ? mappings.getSchemaName() : schemaNode.getValue(); Attribute catalogNode = node.attribute( "catalog" ); String catalog = catalogNode == null ? mappings.getCatalogName() : catalogNode.getValue(); Table denormalizedSuperTable = unionSubclass.getSuperclass().getTable(); Table mytable = mappings.addDenormalizedTable( schema, catalog, getClassTableName(unionSubclass, node, schema, catalog, denormalizedSuperTable, mappings ), unionSubclass.isAbstract() != null && unionSubclass.isAbstract().booleanValue(), getSubselect( node ), denormalizedSuperTable ); unionSubclass.setTable( mytable ); if ( LOG.isDebugEnabled() ) { LOG.debugf( "Mapping union-subclass: %s -> %s", unionSubclass.getEntityName(), unionSubclass.getTable().getName() ); } createClassProperties( node, unionSubclass, mappings, inheritedMetas ); }
/** * Binds the specified persistant class to the runtime model based on the * properties defined in the domain class * * @param domainClass The Grails domain class * @param persistentClass The persistant class * @param mappings Existing mappings */ private static void bindClass(GrailsDomainClass domainClass, PersistentClass persistentClass, Mappings mappings) { // set lazy loading for now persistentClass.setLazy(true); persistentClass.setEntityName(domainClass.getFullName()); persistentClass.setProxyInterfaceName(domainClass.getFullName()); persistentClass.setClassName(domainClass.getFullName()); // set dynamic insert to false persistentClass.setDynamicInsert(false); // set dynamic update to false persistentClass.setDynamicUpdate(false); // set select before update to false persistentClass.setSelectBeforeUpdate(false); // add import to mappings if (mappings.isAutoImport() && persistentClass.getEntityName().indexOf('.') > 0) { mappings.addImport(persistentClass.getEntityName(), StringHelper.unqualify(persistentClass.getEntityName())); } }
mappings.addToExtendsQueue( className, doc ); mappings.addTypeDef( typeName, typeClass, parameters ); RootClass rootclass = new RootClass(); bindRootClass( n, rootclass, mappings, inheritedMetas ); mappings.addClass( rootclass ); : renameNode.getValue(); log.debug( "Import: " + rename + " -> " + className ); mappings.addImport( className, rename );
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; }
property.setPropertyAccessorName( mappings.getDefaultAccess() ); property.setCascade( cascadeNode == null ? mappings.getDefaultCascade() : cascadeNode .getValue() );
persistentClass, mappings ); mappings.addCollection( collection ); value = collection;
private Mappings classMapping(Database database, Mappings mappings) { for (Schema schema : database.getSchemas()) { for (com.manydesigns.portofino.model.database.Table aTable : schema.getTables()) { logger.debug("Class - {}", aTable.getQualifiedName()); com.manydesigns.portofino.model.database.PrimaryKey primaryKey = aTable.getPrimaryKey(); if (primaryKey == null) { logger.debug("Skipping table without primary key: {}", aTable.getQualifiedName()); continue; } if (!primaryKey.isValid()) { logger.debug("Skipping table with invalid primary key: {}", aTable.getQualifiedName()); continue; } RootClass clazz = createTableMapping(mappings, aTable); if(clazz != null) { mappings.addClass(clazz); mappings.addImport(clazz.getEntityName(), clazz.getEntityName()); } } } return mappings; }
mappings.addMappedBy( getCollectionType().getName(), mappedBy, propertyName ); mappings.addSecondPass( sp, !isMappedBy ); mappings.addSecondPass( sp, !isMappedBy ); mappings.addCollection( collection );
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 ); } }
Table tab = mappings.addTable(quoteIdentifier(aTable.getSchemaName()), null, quoteIdentifier(aTable.getTableName()), null, false); mappings.addTableBinding(aTable.getSchemaName(), null, aTable.getTableName(), aTable.getTableName(), null);
if ( mappings.getSchemaName() != null ) { params.setProperty( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() ); if ( mappings.getCatalogName() != null ) { params.setProperty( PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName() );
private static String getClassTableName( PersistentClass model, Element node, String schema, String catalog, Table denormalizedSuperTable, Mappings mappings ) { Attribute tableNameNode = node.attribute( "table" ); String logicalTableName; String physicalTableName; if ( tableNameNode == null ) { logicalTableName = StringHelper.unqualify( model.getEntityName() ); physicalTableName = mappings.getNamingStrategy().classToTableName( model.getEntityName() ); } else { logicalTableName = tableNameNode.getValue(); physicalTableName = mappings.getNamingStrategy().tableName( logicalTableName ); } mappings.addTableBinding( schema, catalog, logicalTableName, physicalTableName, denormalizedSuperTable ); return physicalTableName; }