List of usage examples for org.hibernate.boot.spi InFlightMetadataCollector addTable
Table addTable(String schema, String catalog, String name, String subselect, boolean isAbstract);
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
protected void bindCollectionTable(ToMany property, InFlightMetadataCollector mappings, Collection collection, Table ownerTable, String sessionFactoryBeanName) { String owningTableSchema = ownerTable.getSchema(); PropertyConfig config = getPropertyConfig(property); JoinTable jt = config != null ? config.getJoinTable() : null; NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); String tableName = (jt != null && jt.getName() != null ? jt.getName() : namingStrategy.tableName(calculateTableForMany(property, sessionFactoryBeanName))); String schemaName = getSchemaName(mappings); String catalogName = getCatalogName(mappings); if (jt != null) { if (jt.getSchema() != null) { schemaName = jt.getSchema(); }//from w w w . j a v a2 s . c om if (jt.getCatalog() != null) { catalogName = jt.getCatalog(); } } if (schemaName == null && owningTableSchema != null) { schemaName = owningTableSchema; } collection.setCollectionTable(mappings.addTable(schemaName, catalogName, tableName, null, false)); }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * Binds a joined sub-class mapping using table-per-subclass * * @param sub The Grails sub class * @param joinedSubclass The Hibernate Subclass object * @param mappings The mappings Object * @param gormMapping The GORM mapping object * @param sessionFactoryBeanName the session factory bean name *///from w w w . j a va2s . c o m protected void bindJoinedSubClass(HibernatePersistentEntity sub, JoinedSubclass joinedSubclass, InFlightMetadataCollector mappings, Mapping gormMapping, String sessionFactoryBeanName) { bindClass(sub, joinedSubclass, mappings); String schemaName = getSchemaName(mappings); String catalogName = getCatalogName(mappings); Table mytable = mappings.addTable(schemaName, catalogName, getJoinedSubClassTableName(sub, joinedSubclass, null, mappings, sessionFactoryBeanName), null, false); joinedSubclass.setTable(mytable); LOG.info("Mapping joined-subclass: " + joinedSubclass.getEntityName() + " -> " + joinedSubclass.getTable().getName()); SimpleValue key = new DependantValue(mappings, mytable, joinedSubclass.getIdentifier()); joinedSubclass.setKey(key); final PersistentProperty identifier = sub.getIdentity(); String columnName = getColumnNameForPropertyAndPath(identifier, EMPTY_PATH, null, sessionFactoryBeanName); bindSimpleValue(identifier.getType().getName(), key, false, columnName, mappings); joinedSubclass.createPrimaryKey(); // properties createClassProperties(sub, joinedSubclass, mappings, sessionFactoryBeanName); }
From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
protected void bindRootPersistentClassCommonValues(HibernatePersistentEntity domainClass, RootClass root, InFlightMetadataCollector mappings, String sessionFactoryBeanName) { // get the schema and catalog names from the configuration Mapping m = getMapping(domainClass.getJavaClass()); String schema = getSchemaName(mappings); String catalog = getCatalogName(mappings); if (m != null) { configureDerivedProperties(domainClass, m); CacheConfig cc = m.getCache();// w w w.ja va2 s.c o m if (cc != null && cc.getEnabled()) { root.setCacheConcurrencyStrategy(cc.getUsage()); if ("read-only".equals(cc.getUsage())) { root.setMutable(false); } root.setLazyPropertiesCacheable(!"non-lazy".equals(cc.getInclude())); } Integer bs = m.getBatchSize(); if (bs != null) { root.setBatchSize(bs); } if (m.getDynamicUpdate()) { root.setDynamicUpdate(true); } if (m.getDynamicInsert()) { root.setDynamicInsert(true); } } final boolean hasTableDefinition = m != null && m.getTable() != null; if (hasTableDefinition && m.getTable().getSchema() != null) { schema = m.getTable().getSchema(); } if (hasTableDefinition && m.getTable().getCatalog() != null) { catalog = m.getTable().getCatalog(); } final boolean isAbstract = m != null && !m.getTablePerHierarchy() && m.isTablePerConcreteClass() && root.isAbstract(); // create the table Table table = mappings.addTable(schema, catalog, getTableName(domainClass, sessionFactoryBeanName), null, isAbstract); root.setTable(table); if (LOG.isDebugEnabled()) { LOG.debug("[GrailsDomainBinder] Mapping Grails domain class: " + domainClass.getName() + " -> " + root.getTable().getName()); } bindIdentity(domainClass, root, mappings, m, sessionFactoryBeanName); if (m == null) { bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName); } else { if (m.getVersioned()) { bindVersion(domainClass.getVersion(), root, mappings, sessionFactoryBeanName); } } root.createPrimaryKey(); createClassProperties(domainClass, root, mappings, sessionFactoryBeanName); }