本文整理了Java中org.hibernate.engine.spi.SessionFactoryImplementor.getCollectionPersister()
方法的一些代码示例,展示了SessionFactoryImplementor.getCollectionPersister()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SessionFactoryImplementor.getCollectionPersister()
方法的具体详情如下:
包路径:org.hibernate.engine.spi.SessionFactoryImplementor
类名称:SessionFactoryImplementor
方法名:getCollectionPersister
暂无
代码示例来源:origin: hibernate/hibernate-orm
@Override
public Joinable getAssociatedJoinable(SessionFactoryImplementor factory)
throws MappingException {
return (Joinable) factory.getCollectionPersister( role );
}
代码示例来源:origin: kiegroup/jbpm
private void copyCollectionPersisterKeys(Attribute embeddedAttr, PluralAttribute listAttr, EntityManager em) {
String [] keys = createOriginalAndExpectedKeys(embeddedAttr, listAttr);
try {
SessionImpl session = (SessionImpl) em.getDelegate();
SessionFactoryImplementor sessionFactory = session.getSessionFactory();
CollectionPersister persister = sessionFactory.getCollectionPersister(keys[0]);
sessionFactory.getCollectionPersisters().put(keys[1], persister);
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public CollectionPersister getCollectionPersister(String role) throws MappingException {
return delegate.getCollectionPersister( role );
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public String toString() {
return "CollectionKey"
+ MessageHelper.collectionInfoString( factory.getCollectionPersister( role ), key, factory );
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Get the Hibernate type of the collection elements
*
* @param factory The session factory.
* @return The type of the collection elements
* @throws MappingException Indicates the underlying persister could not be located.
*/
public final Type getElementType(SessionFactoryImplementor factory) throws MappingException {
return factory.getCollectionPersister( getRole() ).getElementType();
}
代码示例来源:origin: hibernate/hibernate-orm
private CollectionPersister resolvePersister(CriteriaBuilderImpl criteriaBuilder, PluralAttribute attribute) {
SessionFactoryImplementor sfi = criteriaBuilder.getEntityManagerFactory().getSessionFactory();
return sfi.getCollectionPersister( resolveRole( attribute ) );
}
代码示例来源:origin: hibernate/hibernate-orm
private void addCollection(String role, String alias, Map propertyResults) {
SQLLoadableCollection collectionPersister = ( SQLLoadableCollection ) factory.getCollectionPersister( role );
alias2CollectionPersister.put( alias, collectionPersister );
String suffix = generateCollectionSuffix();
LOG.tracev( "Mapping alias [{0}] to collection-suffix [{1}]", alias, suffix );
alias2CollectionSuffix.put( alias, suffix );
collectionPropertyResultMaps.put( alias, propertyResults );
if ( collectionPersister.isOneToMany() || collectionPersister.isManyToMany() ) {
SQLLoadable persister = ( SQLLoadable ) collectionPersister.getElementPersister();
addPersister( alias, filter( propertyResults ), persister );
}
}
代码示例来源:origin: hibernate/hibernate-orm
public MapKeyAttribute(CriteriaBuilderImpl criteriaBuilder, MapAttribute<?, K, ?> attribute) {
this.attribute = attribute;
this.jpaType = attribute.getKeyType();
this.jpaBinableJavaType = attribute.getKeyJavaType();
this.jpaBindableType = Type.PersistenceType
.ENTITY.equals( jpaType.getPersistenceType() )
? BindableType.ENTITY_TYPE
: BindableType.SINGULAR_ATTRIBUTE;
String guessedRoleName = determineRole( attribute );
SessionFactoryImplementor sfi = criteriaBuilder.getEntityManagerFactory().getSessionFactory();
mapPersister = sfi.getCollectionPersister( guessedRoleName );
if ( mapPersister == null ) {
throw new IllegalStateException( "Could not locate collection persister [" + guessedRoleName + "]" );
}
mapKeyType = mapPersister.getIndexType();
if ( mapKeyType == null ) {
throw new IllegalStateException( "Could not determine map-key type [" + guessedRoleName + "]" );
}
this.persistentAttributeType = mapKeyType.isEntityType()
? PersistentAttributeType.MANY_TO_ONE
: mapKeyType.isComponentType()
? PersistentAttributeType.EMBEDDED
: PersistentAttributeType.BASIC;
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public String getAssociatedEntityName(SessionFactoryImplementor factory)
throws MappingException {
try {
QueryableCollection collectionPersister = (QueryableCollection) factory
.getCollectionPersister( role );
if ( !collectionPersister.getElementType().isEntityType() ) {
throw new MappingException(
"collection was not an association: " +
collectionPersister.getRole()
);
}
return collectionPersister.getElementPersister().getEntityName();
}
catch (ClassCastException cce) {
throw new MappingException( "collection role is not queryable " + role );
}
}
代码示例来源:origin: hibernate/hibernate-orm
protected QueryableCollection getQueryableCollection(
String entityName,
String propertyName,
SessionFactoryImplementor factory) throws HibernateException {
final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
final Type type = ownerMapping.toType( propertyName );
if ( !type.isCollectionType() ) {
throw new MappingException(
"Property path [" + entityName + "." + propertyName + "] does not reference a collection"
);
}
final String role = ( (CollectionType) type ).getRole();
try {
return (QueryableCollection) factory.getCollectionPersister( role );
}
catch ( ClassCastException cce ) {
throw new QueryException( "collection role is not queryable: " + role );
}
catch ( Exception e ) {
throw new QueryException( "collection role not found: " + role );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
final String entityName =criteriaQuery.getEntityName( criteria, propertyName );
final String role = entityName + '.' + criteriaQuery.getPropertyName( propertyName );
final QueryableCollection cp = (QueryableCollection) criteriaQuery.getFactory().getCollectionPersister( role );
final String[] fk = cp.getKeyColumnNames();
final String[] pk = ( (Loadable) cp.getOwnerEntityPersister() ).getIdentifierColumnNames();
final ConditionFragment subQueryRestriction = new ConditionFragment()
.setTableAlias( criteriaQuery.getSQLAlias( criteria, propertyName ) )
.setCondition( pk, fk );
return String.format(
Locale.ROOT,
"? %s (select count(*) from %s where %s)",
op,
cp.getTableName(),
subQueryRestriction.toFragmentString()
);
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Reattach a detached (disassociated) initialized or uninitialized
* collection wrapper, using a snapshot carried with the collection
* wrapper
*/
protected void reattachCollection(PersistentCollection collection, CollectionType type)
throws HibernateException {
if ( collection.wasInitialized() ) {
CollectionPersister collectionPersister = getSession().getFactory()
.getCollectionPersister( type.getRole() );
getSession().getPersistenceContext()
.addInitializedDetachedCollection( collectionPersister, collection );
}
else {
if ( !isCollectionSnapshotValid(collection) ) {
throw new HibernateException( "could not reassociate uninitialized transient collection" );
}
CollectionPersister collectionPersister = getSession().getFactory()
.getCollectionPersister( collection.getRole() );
getSession().getPersistenceContext()
.addUninitializedDetachedCollection( collectionPersister, collection );
}
}
代码示例来源:origin: hibernate/hibernate-orm
final Object anything,
final CollectionType type) {
final CollectionPersister persister = eventSource.getFactory().getCollectionPersister( type.getRole() );
final Type elemType = persister.getElementType();
代码示例来源:origin: hibernate/hibernate-orm
protected void prepareTest() throws Exception {
super.prepareTest();
isContractPartiesInverse = sessionFactory().getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse();
try {
sessionFactory().getEntityPersister( Party.class.getName() ).getPropertyType( "contract" );
isContractPartiesBidirectional = true;
}
catch ( QueryException ex) {
isContractPartiesBidirectional = false;
}
try {
sessionFactory().getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" );
isContractVariationsBidirectional = true;
}
catch ( QueryException ex) {
isContractVariationsBidirectional = false;
}
isContractVersioned = sessionFactory().getEntityPersister( Contract.class.getName() ).isVersioned();
}
代码示例来源:origin: hibernate/hibernate-orm
CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testCachedValueAfterEviction() {
CollectionPersister persister = sessionFactory().getCollectionPersister( Company.class.getName() + ".users" );
Session session = openSession();
SessionImplementor sessionImplementor = (SessionImplementor) session;
CollectionDataAccess cache = persister.getCacheAccessStrategy();
Object key = cache.generateCacheKey( 1, persister, sessionFactory(), session.getTenantIdentifier() );
Object cachedValue = cache.get( sessionImplementor, key );
assertNull( cachedValue );
Company company = session.get( Company.class, 1 );
//should add in cache
assertEquals( 1, company.getUsers().size() );
session.close();
session = openSession();
sessionImplementor = (SessionImplementor) session;
key = cache.generateCacheKey( 1, persister, sessionFactory(), session.getTenantIdentifier() );
cachedValue = cache.get( sessionImplementor, key );
assertNotNull( "Collection wasn't cached", cachedValue );
session.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-5732")
public void testInverseIndex() {
final CollectionPersister transactionsPersister = sessionFactory().getCollectionPersister(
BankAccount.class.getName() + ".transactions" );
assertTrue( transactionsPersister.isInverse() );
代码示例来源:origin: hibernate/hibernate-orm
final CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );
代码示例来源:origin: hibernate/hibernate-orm
CollectionPersister persister = session.getFactory().getCollectionPersister( collectionType.getRole() );
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testCollectionInitializerCase() {
CollectionPersister cp = sessionFactory().getCollectionPersister( Poster.class.getName() + ".messages" );
FetchStyleLoadPlanBuildingAssociationVisitationStrategy strategy = new FetchStyleLoadPlanBuildingAssociationVisitationStrategy(
sessionFactory(),
LoadQueryInfluencers.NONE,
LockMode.NONE
);
LoadPlan plan = MetamodelDrivenLoadPlanBuilder.buildRootCollectionLoadPlan( strategy, cp );
assertFalse( plan.hasAnyScalarReturns() );
assertEquals( 1, plan.getReturns().size() );
Return rtn = plan.getReturns().get( 0 );
CollectionReturn collectionReturn = ExtraAssertions.assertTyping( CollectionReturn.class, rtn );
assertNotNull( collectionReturn.getElementGraph() );
assertNotNull( collectionReturn.getElementGraph().getFetches() );
// the collection Message elements are fetched, but Message.poster is not fetched
// (because that collection is owned by that Poster)
assertEquals( 0, collectionReturn.getElementGraph().getFetches().length );
EntityReference entityReference = ExtraAssertions.assertTyping( EntityReference.class, collectionReturn.getElementGraph() );
assertNotNull( entityReference.getFetches() );
assertEquals( 0, entityReference.getFetches().length );
LoadPlanTreePrinter.INSTANCE.logTree( plan, new AliasResolutionContextImpl( sessionFactory() ) );
}
内容来源于网络,如有侵权,请联系作者删除!