@Override default EntityTypeDescriptor getEntityTypeByName(String entityName) { return entity( entityName ); } }
public Root from(Class<T> entityClass) { EntityType<T> entityType = criteriaBuilder.getEntityManagerFactory() .getMetamodel() .entity( entityClass ); if ( entityType == null ) { throw new IllegalArgumentException( entityClass + " is not an entity" ); } return from( entityType ); }
public <X> Root<X> from(Class<X> entityClass) { EntityType<X> entityType = criteriaBuilder.getEntityManagerFactory() .getMetamodel() .entity( entityClass ); if ( entityType == null ) { throw new IllegalArgumentException( entityClass + " is not an entity" ); } return from( entityType ); }
@Override public boolean appliesTo(Class entityType) { return appliesTo( sessionFactory().getMetamodel().entity( entityType ) ); } }
@Override public boolean appliesTo(String entityName) { return appliesTo( sessionFactory().getMetamodel().entity( entityName ) ); }
public TreatedRoot(RootImpl<? super T> original, Class<T> treatAsType) { super( original.criteriaBuilder(), original.criteriaBuilder().getEntityManagerFactory().getMetamodel().entity( treatAsType ) ); this.original = original; this.treatAsType = treatAsType; }
@Override public <T> RootGraphImplementor<T> createEntityGraph(Class<T> rootType) { checkOpen(); return new RootGraphImpl<T>( null, getMetamodel().entity( rootType ), getEntityManagerFactory() ); }
@SuppressWarnings("unchecked") public static <T, S extends T> ManagedTypeDescriptor<S> resolveSubType( ManagedTypeDescriptor<T> baseType, String subTypeName, SessionFactoryImplementor sessionFactory) { final MetamodelImplementor metamodel = sessionFactory.getMetamodel(); if ( baseType instanceof EmbeddedTypeDescriptor<?> ) { // todo : at least validate the string is a valid sub-type of the embeddable class? return (ManagedTypeDescriptor) baseType; } final String importedClassName = metamodel.getImportedClassName( subTypeName ); if ( importedClassName != null ) { // first, try to find it by name directly.. ManagedTypeDescriptor<S> subManagedType = metamodel.entity( importedClassName ); if ( subManagedType != null ) { return subManagedType; } // it could still be a mapped-superclass try { final Class<S> subTypeClass = sessionFactory.getServiceRegistry() .getService( ClassLoaderService.class ) .classForName( importedClassName ); return metamodel.managedType( subTypeClass ); } catch (Exception ignore) { } } throw new IllegalArgumentException( "Unknown sub-type name (" + baseType.getName() + ") : " + subTypeName ); }
@Override public boolean appliesTo(Class entityType) { return appliesTo( sessionFactory().getMetamodel().entity( entityType ) ); } }
@Override public boolean appliesTo(String entityName) { return appliesTo( sessionFactory().getMetamodel().entity( entityName ) ); }
@Override @SuppressWarnings("unchecked") public <T> RootGraphImplementor<T> createEntityGraph(Class<T> rootType) { checkOpen(); return new RootGraphImpl<T>( null, getMetamodel().entity( rootType ), getEntityManagerFactory() ); }
/** * 初始化 */ public SessionFactorys() { // 实例化表列表 entity_factorys = Maps.newMap(); factorys = Lists.newList(); // 初始化SessionFactory initSessionFactory(); // 如果只有一个SessionFactory if (factorys.size() == 1) factory = factorys.get(0); // 循环获得表名 for (Class<?> e : ClassUtil.getAnnotationClass(CommonParams.getPackages("entity"), Entity.class)) // 循环获得SessionFactory for (SessionFactory sessionFactory : factorys) try { if (((SessionFactoryImplementor) sessionFactory).getMetamodel().entity(e) != null) { entity_factorys.put(e, sessionFactory); break; } } catch (Exception ex) {} }
public BatchIndexingWorkspace(SessionFactoryImplementor sessionFactory, HibernateOrmMapping mapping, Class<?> type, int objectLoadingThreads, CacheMode cacheMode, int objectLoadingBatchSize, CountDownLatch endAllSignal, MassIndexingMonitor monitor, long objectsLimit, int idFetchSize, Integer transactionTimeout, String tenantId) { this.indexedType = type; this.idFetchSize = idFetchSize; this.transactionTimeout = transactionTimeout; this.tenantId = tenantId; this.mapping = mapping; this.idNameOfIndexedType = sessionFactory.getMetamodel().entity( indexedType ).getId( Object.class ).getName(); this.sessionFactory = sessionFactory; //thread pool sizing: this.documentBuilderThreads = objectLoadingThreads; //loading options: this.cacheMode = cacheMode; this.objectLoadingBatchSize = objectLoadingBatchSize; //pipelining queues: this.primaryKeyStream = new ProducerConsumerQueue<List<Serializable>>( 1 ); //end signal shared with other instances: this.endAllSignal = endAllSignal; this.producerEndSignal = new CountDownLatch( documentBuilderThreads ); this.monitor = monitor; this.objectsLimit = objectsLimit; }
@SuppressWarnings("unchecked") public static <T, S extends T> ManagedTypeDescriptor<S> resolveSubType( ManagedTypeDescriptor<T> baseType, String subTypeName, SessionFactoryImplementor sessionFactory) { final MetamodelImplementor metamodel = sessionFactory.getMetamodel(); if ( baseType instanceof EmbeddedTypeDescriptor<?> ) { // todo : at least validate the string is a valid sub-type of the embeddable class? return (ManagedTypeDescriptor) baseType; } final String importedClassName = metamodel.getImportedName( subTypeName ); if ( importedClassName != null ) { // first, try to find it by name directly.. ManagedTypeDescriptor<S> subManagedType = metamodel.entity( importedClassName ); if ( subManagedType != null ) { return subManagedType; } // it could still be a mapped-superclass try { final Class<S> subTypeClass = sessionFactory.getServiceRegistry() .getService( ClassLoaderService.class ) .classForName( importedClassName ); return metamodel.managedType( subTypeClass ); } catch (Exception ignore) { } } throw new IllegalArgumentException( "Unknown sub-type name (" + baseType.getDomainTypeName() + ") : " + subTypeName ); }
/** * Attempt to initialize the proxy without loading anything from the database. * * This will only have any effect if the proxy is still attached to a session, * and the entity being proxied has been loaded and added to the persistence context * of that session since the proxy was created. */ public final void initializeWithoutLoadIfPossible() { if ( !initialized && session != null && session.isOpen() ) { final EntityKey key = session.generateEntityKey( getIdentifier(), session.getFactory().getMetamodel().entity( getEntityName() ) ); final Object entity = session.getPersistenceContext().getEntity( key ); if ( entity != null ) { setImplementation( entity ); } } }