List of usage examples for org.hibernate.mapping PersistentClass getTable
public abstract Table getTable();
From source file:com.blazebit.persistence.integration.hibernate.Hibernate43Integrator.java
License:Apache License
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { Class<?> valuesEntity;/*ww w. ja v a 2 s. c o m*/ boolean registerValuesEntity = true; try { valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"); } catch (ClassNotFoundException e) { throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e); } Iterator<PersistentClass> iter = configuration.getClassMappings(); while (iter.hasNext()) { PersistentClass clazz = iter.next(); Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } } if (registerValuesEntity) { // Register values entity if wasn't found configuration.addAnnotatedClass(valuesEntity); configuration.buildMappings(); PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } serviceRegistry.locateServiceBinding(PersisterClassResolver.class) .setService(new CustomPersisterClassResolver()); serviceRegistry.locateServiceBinding(Database.class) .setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping())); }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate4Integrator.java
License:Apache License
@Override public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { Class<?> valuesEntity;/*from w w w .j a v a 2s . c o m*/ boolean registerValuesEntity = true; try { valuesEntity = Class.forName("com.blazebit.persistence.impl.function.entity.ValuesEntity"); } catch (ClassNotFoundException e) { throw new RuntimeException("Are you missing blaze-persistence-core-impl on the classpath?", e); } Iterator<PersistentClass> iter = configuration.getClassMappings(); while (iter.hasNext()) { PersistentClass clazz = iter.next(); Class<?> entityClass = clazz.getMappedClass(); if (valuesEntity.equals(entityClass)) { registerValuesEntity = false; } if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } } if (registerValuesEntity) { // Register values entity if wasn't found configuration.addAnnotatedClass(valuesEntity); configuration.buildMappings(); PersistentClass clazz = configuration.getClassMapping(valuesEntity.getName()); clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); } serviceRegistry.locateServiceBinding(PersisterClassResolver.class) .setService(new CustomPersisterClassResolver()); serviceRegistry.locateServiceBinding(Database.class) .setService(new SimpleDatabase(configuration.getTableMappings(), sessionFactory.getDialect(), new SimpleTableNameFormatter(), configuration.buildMapping())); }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate52Integrator.java
License:Apache License
@Override public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { // TODO: remember metadata for exact column types for (PersistentClass clazz : metadata.getEntityBindings()) { Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); }/*ww w . jav a2 s . co m*/ } serviceRegistry.locateServiceBinding(PersisterClassResolver.class) .setService(new CustomPersisterClassResolver()); TableNameFormatter formatter = new NativeTableNameFormatter( sessionFactory.getJdbcServices().getJdbcEnvironment().getQualifiedObjectNameFormatter()); serviceRegistry.locateServiceBinding(Database.class) .setService(new SimpleDatabase(getTableIterator(metadata.getDatabase().getNamespaces()), sessionFactory.getDialect(), formatter, metadata)); }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate5Integrator.java
License:Apache License
@Override public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { for (PersistentClass clazz : metadata.getEntityBindings()) { Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); }// ww w . j a v a2s . co m } serviceRegistry.locateServiceBinding(PersisterClassResolver.class) .setService(new CustomPersisterClassResolver()); TableNameFormatter formatter = new NativeTableNameFormatter( sessionFactory.getJdbcServices().getJdbcEnvironment().getQualifiedObjectNameFormatter()); serviceRegistry.locateServiceBinding(Database.class) .setService(new SimpleDatabase(getTableIterator(metadata.getDatabase().getNamespaces()), sessionFactory.getDialect(), formatter, metadata)); }
From source file:com.blazebit.persistence.integration.hibernate.Hibernate60Integrator.java
License:Apache License
@Override public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { for (PersistentClass clazz : metadata.getEntityBindings()) { Class<?> entityClass = clazz.getMappedClass(); if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) { clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName()); }/* ww w . ja v a2s. c om*/ } serviceRegistry.locateServiceBinding(PersisterClassResolver.class) .setService(new CustomPersisterClassResolver()); TableNameFormatter formatter = new NativeTableNameFormatter( sessionFactory.getJdbcServices().getJdbcEnvironment().getQualifiedObjectNameFormatter()); serviceRegistry.locateServiceBinding(Database.class) .setService(new SimpleDatabase(getTableIterator(metadata.getDatabase().getNamespaces()), sessionFactory.getJdbcServices().getDialect(), formatter, metadata)); }
From source file:com.clueride.rest.MemberWebService.java
License:Apache License
private void dumpEntities() { Metadata metadata = MetadataExtractorIntegrator.INSTANCE.getMetadata(); for (PersistentClass persistentClass : metadata.getEntityBindings()) { Table table = persistentClass.getTable(); LOGGER.info(String.format("Entity: {} is mapped to table: {}", persistentClass.getClassName(), table.getName()));/*from w w w. j a v a 2 s .com*/ for (Iterator propertyIterator = persistentClass.getPropertyIterator(); propertyIterator.hasNext();) { Property property = (Property) propertyIterator.next(); for (Iterator columnIterator = property.getColumnIterator(); columnIterator.hasNext();) { Column column = (Column) columnIterator.next(); LOGGER.info(String.format("Property: {} is mapped on table column: {} of type: {}", property.getName(), column.getName(), column.getSqlType())); } } } }
From source file:com.fiveamsolutions.nci.commons.audit.AuditLogInterceptor.java
License:Open Source License
/** * Retrieves the table name and the column name for the given class and property. * * @param className//from w ww . jav a2 s . c om * @param fieldName * @return Map */ private synchronized Map<String, String> getColumnTableName(String className, String fieldName) { String hashkey = className + ";" + fieldName; Map<String, String> retMap = COLUMN_CACHE.get(hashkey); if (retMap != null) { return retMap; } retMap = new HashMap<String, String>(); COLUMN_CACHE.put(hashkey, retMap); PersistentClass pc = getHibernateHelper().getConfiguration().getClassMapping(className); // get the table and column information Table table = pc.getTable(); String tableName = table.getName(); String columnName = getColumnName(pc, fieldName); if (columnName == null) { columnName = fieldName; } retMap.put(TABLE_NAME, tableName); retMap.put(COLUMN_NAME, columnName); return retMap; }
From source file:com.github.shyiko.rook.target.hibernate4.cache.PrimaryKey.java
License:Apache License
public PrimaryKey(PersistentClass persistentClass, Map<String, Integer> columnIndexByNameMap) { this(persistentClass.getKey(), persistentClass.getTable(), columnIndexByNameMap); final Type type = persistentClass.getIdentifier().getType(); if (type instanceof EmbeddedComponentType) { entityClass = type.getReturnedClass(); } else {/*from w w w.j av a 2s . c om*/ entityClass = persistentClass.getMappedClass(); } }
From source file:com.github.shyiko.rook.target.hibernate4.cache.SynchronizationContext.java
License:Apache License
private void loadClassMappings(Configuration configuration) throws SQLException { for (Iterator<PersistentClass> iterator = configuration.getClassMappings(); iterator.hasNext();) { PersistentClass persistentClass = iterator.next(); String entityName = persistentClass.getEntityName(); boolean isCacheable = ((SessionFactoryImplementor) sessionFactory).getEntityPersister(entityName) .hasCache();/*from ww w .ja v a2 s.co m*/ if (isCacheable) { Table table = persistentClass.getTable(); PrimaryKey primaryKey = new PrimaryKey(persistentClass, getColumnIndexByNameMap(table)); evictionTargetsOf(table).add(new EvictionTarget(entityName, primaryKey, false)); } } }
From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.PrimaryKey.java
License:Apache License
public PrimaryKey(PersistentClass persistentClass) { this.entityClass = persistentClass.getMappedClass(); KeyValue keyValue = persistentClass.getKey(); Table table = persistentClass.getTable(); Map<String, Integer> columnIndexByNameMap = getColumnIndexByNameMap(table); KeyColumn[] positionWithinRow = new KeyColumn[keyValue.getColumnSpan()]; int index = 0; if (keyValue instanceof Component) { Iterator propertyIterator = ((Component) keyValue).getPropertyIterator(); while (propertyIterator.hasNext()) { Property property = (Property) propertyIterator.next(); String columnName = ((Column) property.getColumnIterator().next()).getName(); positionWithinRow[index++] = new KeyColumn(property.getName(), columnIndexByNameMap.get(columnName)); }//from w w w . j a v a2 s . c o m } else { Iterator columnIterator = keyValue.getColumnIterator(); while (columnIterator.hasNext()) { String columnName = ((Column) columnIterator.next()).getName(); positionWithinRow[index++] = new KeyColumn(columnName, columnIndexByNameMap.get(columnName)); } } if (positionWithinRow.length == 0) { throw new IllegalStateException("Unable to determine PK for " + table.getName()); } Property identifierProperty = persistentClass.getIdentifierProperty(); this.getter = identifierProperty.getGetter(this.entityClass); this.positionWithinRow = positionWithinRow; }