List of usage examples for org.hibernate.mapping RootClass RootClass
RootClass
From source file:com.javaetmoi.core.persistence.hibernate.TestReflectionUtil.java
License:Apache License
@Before public void setUp() { Configuration configuration = new Configuration(); Mappings mappings = configuration.createMappings(); Component component = new Component(mappings, new RootClass()); Property p1 = new Property(); p1.setName("client"); SimpleValue p1val = new SimpleValue(mappings); p1val.setTypeName("java.lang.Integer"); p1.setValue(p1val); component.addProperty(p1);/* w w w . j a v a 2s. c om*/ Property p2 = new Property(); p2.setName("user"); SimpleValue p2val = new SimpleValue(mappings); p2val.setTypeName("java.lang.String"); p2.setValue(p2val); component.addProperty(p2); metadata = new ComponentMetamodel(component); }
From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java
License:Open Source License
protected RootClass createTableMapping(Mappings mappings, com.manydesigns.portofino.model.database.Table aTable) { Table tab = mappings.addTable(escapeName(aTable.getSchemaName()), null, escapeName(aTable.getTableName()), null, false);/*from w w w . ja v a 2 s. c o m*/ //tab.setName(escapeName(aTable.getTableName())); //tab.setSchema(escapeName(aTable.getSchemaName())); mappings.addTableBinding(aTable.getSchemaName(), null, aTable.getTableName(), aTable.getTableName(), null); RootClass clazz = new RootClass(); clazz.setEntityName(aTable.getActualEntityName()); clazz.setJpaEntityName(aTable.getActualEntityName()); if (aTable.getJavaClass() != null) { clazz.setClassName(aTable.getJavaClass()); clazz.setProxyInterfaceName(aTable.getJavaClass()); } clazz.setLazy(LAZY); clazz.setTable(tab); //clazz.setNodeName(aTable.getTableName()); List<com.manydesigns.portofino.model.database.Column> columnList = new ArrayList<com.manydesigns.portofino.model.database.Column>(); for (com.manydesigns.portofino.model.database.Column modelColumn : aTable.getColumns()) { int jdbcType = modelColumn.getJdbcType(); Class javaType = modelColumn.getActualJavaType(); //First param = null ==> doesn't really set anything, just check boolean hibernateTypeOk = setHibernateType(null, modelColumn, javaType, jdbcType); if (hibernateTypeOk) { columnList.add(modelColumn); } else { logger.error( "Cannot find Hibernate type for table: {}, column: {}, jdbc type: {}, type name: {}. Skipping column.", new Object[] { aTable.getQualifiedName(), modelColumn.getColumnName(), jdbcType, javaType != null ? javaType.getName() : null }); } } //Primary keys List<com.manydesigns.portofino.model.database.Column> columnPKList = aTable.getPrimaryKey().getColumns(); if (!columnList.containsAll(columnPKList)) { logger.error("Primary key refers to some invalid columns, skipping table {}", aTable.getQualifiedName()); return null; } if (columnPKList.size() > 1) { createPKComposite(mappings, aTable, aTable.getPrimaryKey().getPrimaryKeyName(), clazz, tab, columnPKList); } else { createPKSingle(mappings, aTable, aTable.getPrimaryKey().getPrimaryKeyName(), clazz, tab, columnPKList); } //Other columns columnList.removeAll(columnPKList); for (com.manydesigns.portofino.model.database.Column column : columnList) { Column col = createColumn(mappings, tab, column); if (col != null) { clazz.addProperty(createProperty(column, col.getValue())); } } return clazz; }
From source file:org.bonitasoft.engine.persistence.PlatformHibernatePersistenceServiceTest.java
License:Open Source License
@Before public void before() throws ConfigurationException { doReturn(mock(Filter.class)).when(session).enableFilter("tenantFilter"); final SessionFactory sessionFactory = mock(SessionFactory.class); doReturn(mock(Statistics.class)).when(sessionFactory).getStatistics(); doReturn(session).when(sessionFactory).getCurrentSession(); final Iterator<PersistentClass> classMappingsIterator = Arrays.asList((PersistentClass) new RootClass()) .iterator();/*from w w w. ja v a 2 s . co m*/ final Configuration configuration = mock(Configuration.class); doReturn(sessionFactory).when(configuration).buildSessionFactory(); doReturn(classMappingsIterator).when(configuration).getClassMappings(); doReturn(configuration).when(hbmConfigurationProvider).getConfiguration(); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a root class (one with no super classes) to the runtime meta model * based on the supplied Grails domain class * * @param domainClass The Grails domain class * @param mappings The Hibernate Mappings object * @param sessionFactoryBeanName the session factory bean name *//* w w w . j a v a 2 s. c o m*/ public void bindRoot(GrailsDomainClass domainClass, Mappings mappings, String sessionFactoryBeanName) { if (mappings.getClass(domainClass.getFullName()) != null) { LOG.info("[GrailsDomainBinder] Class [" + domainClass.getFullName() + "] is already mapped, skipping.. "); return; } RootClass root = new RootClass(); root.setAbstract(Modifier.isAbstract(domainClass.getClazz().getModifiers())); if (!domainClass.hasSubClasses()) { root.setPolymorphic(false); } bindClass(domainClass, root, mappings); Mapping m = getMapping(domainClass); bindRootPersistentClassCommonValues(domainClass, root, mappings, sessionFactoryBeanName); if (!domainClass.getSubClasses().isEmpty()) { boolean tablePerSubclass = m != null && !m.getTablePerHierarchy(); if (!tablePerSubclass) { // if the root class has children create a discriminator property bindDiscriminatorProperty(root.getTable(), root, mappings); } // bind the sub classes bindSubClasses(domainClass, root, mappings, sessionFactoryBeanName); } if (root.getEntityPersisterClass() == null) { root.setEntityPersisterClass(getGroovyAwareSingleTableEntityPersisterClass()); } mappings.addClass(root); }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
License:Apache License
/** * Binds a root class (one with no super classes) to the runtime meta model * based on the supplied Grails domain class * * @param domainClass The Grails domain class * @param mappings The Hibernate Mappings object * @param sessionFactoryBeanName the session factory bean name */// w ww .j av a2 s. c o m public static void bindRoot(GrailsDomainClass domainClass, Mappings mappings, String sessionFactoryBeanName) { if (mappings.getClass(domainClass.getFullName()) != null) { LOG.info("[GrailsDomainBinder] Class [" + domainClass.getFullName() + "] is already mapped, skipping.. "); return; } RootClass root = new RootClass(); root.setAbstract(Modifier.isAbstract(domainClass.getClazz().getModifiers())); if (!domainClass.hasSubClasses()) { root.setPolymorphic(false); } bindClass(domainClass, root, mappings); Mapping m = getMapping(domainClass); bindRootPersistentClassCommonValues(domainClass, root, mappings, sessionFactoryBeanName); if (!domainClass.getSubClasses().isEmpty()) { boolean tablePerSubclass = m != null && !m.getTablePerHierarchy(); if (!tablePerSubclass) { // if the root class has children create a discriminator property bindDiscriminatorProperty(root.getTable(), root, mappings); } // bind the sub classes bindSubClasses(domainClass, root, mappings, sessionFactoryBeanName); } if (root.getEntityPersisterClass() == null) { root.setEntityPersisterClass(GroovyAwareSingleTableEntityPersister.class); } mappings.addClass(root); }
From source file:org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder.java
License:Apache License
/** * Binds a root class (one with no super classes) to the runtime meta model * based on the supplied Grails domain class * * @param entity The Grails domain class * @param mappings The Hibernate Mappings object * @param sessionFactoryBeanName the session factory bean name */// w w w . ja v a 2 s . c om public void bindRoot(HibernatePersistentEntity entity, Mappings mappings, String sessionFactoryBeanName) { if (mappings.getClass(entity.getName()) != null) { LOG.info("[GrailsDomainBinder] Class [" + entity.getName() + "] is already mapped, skipping.. "); return; } RootClass root = new RootClass(); root.setAbstract(entity.isAbstract()); final MappingContext mappingContext = entity.getMappingContext(); final java.util.Collection<PersistentEntity> children = mappingContext.getDirectChildEntities(entity); if (children.isEmpty()) { root.setPolymorphic(false); } bindClass(entity, root, mappings); Mapping m = getMapping(entity); bindRootPersistentClassCommonValues(entity, root, mappings, sessionFactoryBeanName); if (!children.isEmpty()) { boolean tablePerSubclass = m != null && !m.getTablePerHierarchy(); if (!tablePerSubclass) { // if the root class has children create a discriminator property bindDiscriminatorProperty(root.getTable(), root, mappings); } // bind the sub classes bindSubClasses(entity, root, mappings, sessionFactoryBeanName); } if (root.getEntityPersisterClass() == null) { root.setEntityPersisterClass(getGroovyAwareSingleTableEntityPersisterClass()); } mappings.addClass(root); }