List of usage examples for org.hibernate.mapping PersistentClass getMappedClass
public Class getMappedClass() throws MappingException
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;//from w w w . j av a 2 s . co 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 ww.j av a2s .c om*/ 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()); }// w w w. ja va 2s . c o 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()); }//from w ww . j ava 2 s . 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.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()); }//from w ww.j a v a 2s .com } 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.db4o.drs.hibernate.impl.HibernateReplicationProvider.java
License:Open Source License
public final ObjectSet objectsChangedSinceLastReplication() { ensureReplicationActive();/* w w w. j a v a2 s . c o m*/ getSession().flush(); Set<PersistentClass> mappedClasses = new HashSet<PersistentClass>(); Iterator classMappings = getConfiguration().getClassMappings(); while (classMappings.hasNext()) { PersistentClass persistentClass = (PersistentClass) classMappings.next(); Class claxx = persistentClass.getMappedClass(); if (Util.isAssignableFromInternalObject(claxx)) continue; mappedClasses.add(persistentClass); } Set out = new HashSet(); for (PersistentClass persistentClass : mappedClasses) out.addAll(getChangedObjectsSinceLastReplication(persistentClass)); return new ObjectSetCollectionFacade(out); }
From source file:com.github.gekoh.yagen.hibernate.PatchGlue.java
License:Apache License
public static void addClass(PersistentClass clazz) { if (profile != null) { profile.addPersistenceClass(clazz.getMappedClass()); }/*from w w w .j av a 2 s .c o m*/ }
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 ww . j a va 2s .c o m*/ entityClass = persistentClass.getMappedClass(); } }
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)); }//ww w . j av 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; }
From source file:com.github.shyiko.rook.target.hibernate4.fulltextindex.SynchronizationContext.java
License:Apache License
@SuppressWarnings("unchecked") private void loadIndexingDirectives(Configuration configuration) { Map<String, IndexingDirective> directivesByEntityNameMap = new HashMap<String, IndexingDirective>(); Collection<Property> allContainedInProperties = new ArrayList<Property>(); for (Iterator<PersistentClass> classIterator = configuration.getClassMappings(); classIterator.hasNext();) { PersistentClass persistentClass = classIterator.next(); boolean suppressSelfIndexing = true; Class mappedClass = persistentClass.getMappedClass(); Indexed indexed = (Indexed) mappedClass.getAnnotation(Indexed.class); EntityIndexingInterceptor indexingInterceptor = null; if (indexed != null) { suppressSelfIndexing = false; Class<? extends EntityIndexingInterceptor> interceptorClass = indexed.interceptor(); if (interceptorClass != DefaultEntityInterceptor.class) { try { indexingInterceptor = interceptorClass.newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + interceptorClass, e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + interceptorClass, e); }// ww w .j a va 2 s. co m } } Collection<Property> containedInProperties = extractAnnotatedProperties(persistentClass, ContainedIn.class); if (suppressSelfIndexing && containedInProperties.isEmpty()) { continue; } allContainedInProperties.addAll(containedInProperties); PrimaryKey primaryKey = new PrimaryKey(persistentClass); Collection<Reference> containers = new ArrayList<Reference>(); for (Property property : containedInProperties) { containers.add(new Reference(property.getGetter(mappedClass))); } IndexingDirective indexingDirective = new IndexingDirective(primaryKey, suppressSelfIndexing, indexingInterceptor, containers); Table table = persistentClass.getTable(); directivesByTable.put(schema + "." + table.getName().toLowerCase(), indexingDirective); directivesByEntityClass.put(mappedClass, indexingDirective); directivesByEntityNameMap.put(persistentClass.getEntityName(), indexingDirective); } loadIndexingDirectivesForJoinTables(allContainedInProperties, directivesByEntityNameMap); }