code_snippet
stringlengths
92
2.48k
score
float64
1.83
4.89
@Test @Resources(annotatedClasses = { SubclassOfSingleTableInheritance.class, SingleEntity.class, RootOfSingleTableInheritance.class, OtherSubclassOfSingleTableInheritance.class, SubclassOfSubclassOfSingleTableInheritance.class }) public void testNoPolymorphism() { EntityBinding noInheritanceEntityBinding = getEntityBinding( SingleEntity.class ); assertTrue( "SingleEntity should be a root entity", noInheritanceEntityBinding.isRoot() ); assertNull( noInheritanceEntityBinding.getSuperEntityBinding() ); assertSame( noInheritanceEntityBinding, getRootEntityBinding( SingleEntity.class ) ); assertFalse( noInheritanceEntityBinding.isPolymorphic() ); assertFalse( noInheritanceEntityBinding.hasSubEntityBindings() ); assertEquals( 0, noInheritanceEntityBinding.getSubEntityBindingClosureSpan() ); assertFalse( noInheritanceEntityBinding.getPostOrderSubEntityBindingClosure().iterator().hasNext() ); assertFalse( noInheritanceEntityBinding.getPreOrderSubEntityBindingClosure().iterator().hasNext() ); Set<AttributeBinding> directAttributeBindings = new HashSet<AttributeBinding>(); for ( AttributeBinding attributeBinding : noInheritanceEntityBinding.attributeBindings() ) { assertTrue( directAttributeBindings.add( attributeBinding ) ); } assertEquals( 1, directAttributeBindings.size() ); assertSame( noInheritanceEntityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding(), directAttributeBindings.iterator().next() ); assertEquals( 1, noInheritanceEntityBinding.getAttributeBindingClosureSpan() ); Iterator<AttributeBinding> iterator = noInheritanceEntityBinding.attributeBindings().iterator(); assertTrue( iterator.hasNext() ); assertSame( noInheritanceEntityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding(), iterator.next() ); assertFalse( iterator.hasNext() ); iterator = noInheritanceEntityBinding.getAttributeBindingClosure().iterator(); assertTrue( iterator.hasNext() ); assertSame( noInheritanceEntityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding(), iterator.next() ); assertFalse( iterator.hasNext() ); iterator = noInheritanceEntityBinding.getSubEntityAttributeBindingClosure().iterator(); assertTrue( iterator.hasNext() ); assertSame( noInheritanceEntityBinding.getHierarchyDetails().getEntityIdentifier().getValueBinding(), iterator.next() ); assertFalse( iterator.hasNext() ); }
2.333333
@Test @Resources(annotatedClasses = { SubclassOfSingleTableInheritance.class, SingleEntity.class, RootOfSingleTableInheritance.class, OtherSubclassOfSingleTableInheritance.class, SubclassOfSubclassOfSingleTableInheritance.class }) public void testPreOrderRootSubEntityClosure() { EntityBinding rootEntityBinding = getEntityBinding( RootOfSingleTableInheritance.class ); EntityBinding subclassEntityBinding = getEntityBinding( SubclassOfSingleTableInheritance.class ); EntityBinding otherSubclassEntityBinding = getEntityBinding( OtherSubclassOfSingleTableInheritance.class ); EntityBinding subclassOfSubclassEntityBinding = getEntityBinding( SubclassOfSubclassOfSingleTableInheritance.class ); // need to figure out the order of direct subclasses, since it's indeterminate Iterator<EntityBinding> directEntityBindingIterator = rootEntityBinding.getDirectSubEntityBindings().iterator(); boolean isSubclassEntityBindingFirst = subclassEntityBinding == directEntityBindingIterator.next(); assertEquals( 3, rootEntityBinding.getSubEntityBindingClosureSpan() ); Iterator<EntityBinding> subEntityBindingIterator = rootEntityBinding.getPreOrderSubEntityBindingClosure().iterator(); assertTrue( subEntityBindingIterator.hasNext() ); if ( isSubclassEntityBindingFirst ) { assertSame( subclassEntityBinding, subEntityBindingIterator.next() ); assertTrue( subEntityBindingIterator.hasNext() ); assertSame( subclassOfSubclassEntityBinding, subEntityBindingIterator.next() ); assertTrue( subEntityBindingIterator.hasNext() ); assertSame( otherSubclassEntityBinding, subEntityBindingIterator.next() ); } else { assertSame( otherSubclassEntityBinding, subEntityBindingIterator.next() ); assertTrue( subEntityBindingIterator.hasNext() ); assertSame( subclassEntityBinding, subEntityBindingIterator.next() ); assertTrue( subEntityBindingIterator.hasNext() ); assertSame( subclassOfSubclassEntityBinding, subEntityBindingIterator.next() ); } assertFalse( subEntityBindingIterator.hasNext() ); }
2.555556
@Override protected void applyRootReturnSelectFragments(SelectStatementBuilder selectStatementBuilder) { selectStatementBuilder.appendSelectClauseFragment( getQueryableCollection().selectFragment( getCollectionReferenceAliases().getCollectionTableAlias(), getCollectionReferenceAliases().getCollectionColumnAliases().getSuffix() ) ); if ( getQueryableCollection().isManyToMany() ) { final OuterJoinLoadable elementPersister = (OuterJoinLoadable) getQueryableCollection().getElementPersister(); selectStatementBuilder.appendSelectClauseFragment( elementPersister.selectFragment( getCollectionReferenceAliases().getElementTableAlias(), getCollectionReferenceAliases().getEntityElementAliases().getColumnAliases().getSuffix() ) ); } super.applyRootReturnSelectFragments( selectStatementBuilder ); }
3.333333
@Override public void startingCollectionElements(CollectionElementDefinition elementDefinition) { final Type elementType = elementDefinition.getType(); log.tracef( "%s Starting collection element graph : %s", StringHelper.repeat( ">>", fetchSourceStack.size() ), elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); final CollectionReference collectionReference = currentCollection(); final CollectionFetchableElement elementGraph = collectionReference.getElementGraph(); if ( elementType.isAssociationType() || elementType.isComponentType() ) { if ( elementGraph == null ) { throw new IllegalStateException( "CollectionReference did not return an expected element graph : " + elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); } if ( !elementType.isAnyType() ) { pushToStack( (ExpandingFetchSource) elementGraph ); } } else { if ( elementGraph != null ) { throw new IllegalStateException( "CollectionReference returned an unexpected element graph : " + elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); } } }
3.555556
@Override protected void beforeTransactionCommit() { transactionCoordinator().sendBeforeTransactionCompletionNotifications( this ); final boolean flush = ! transactionCoordinator().getTransactionContext().isFlushModeNever() && ( isDriver || ! transactionCoordinator().getTransactionContext().isFlushBeforeCompletionEnabled() ); if ( flush ) { // if an exception occurs during flush, user must call rollback() transactionCoordinator().getTransactionContext().managedFlush(); } if ( isDriver && isInitiator ) { transactionCoordinator().getTransactionContext().beforeTransactionCompletion( this ); } closeIfRequired(); }
4.222222
@Test public void testRevisionsCounts() { assertEquals( Arrays.asList( 1, 2, 3, 4 ), getAuditReader().getRevisions( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing1_id ) ); assertEquals( Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id ) ); assertEquals( Arrays.asList( 1, 3, 4 ), getAuditReader().getRevisions( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed1_id ) ); assertEquals( Arrays.asList( 1, 2, 4 ), getAuditReader().getRevisions( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id ) ); assertEquals( Arrays.asList( 1, 2, 3, 4 ), getAuditReader().getRevisions( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed3_id ) ); }
3.888889
@Test public void testHistoryOfIng2() { ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity ed2 = getEntityManager().find( ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity.class, ed2_id ); ChildIndexedListJoinColumnBidirectionalRefIngEntity rev1 = getAuditReader().find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 1 ); ChildIndexedListJoinColumnBidirectionalRefIngEntity rev2 = getAuditReader().find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 2 ); ChildIndexedListJoinColumnBidirectionalRefIngEntity rev3 = getAuditReader().find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 3 ); ChildIndexedListJoinColumnBidirectionalRefIngEntity rev4 = getAuditReader().find( ChildIndexedListJoinColumnBidirectionalRefIngEntity.class, ing2_id, 4 ); assertEquals( rev1.getReferences().size(), 0 ); assertEquals( rev2.getReferences().size(), 1 ); assertEquals( rev2.getReferences().get( 0 ), ed2 ); assertEquals( rev3.getReferences().size(), 1 ); assertEquals( rev3.getReferences().get( 0 ), ed2 ); assertEquals( rev4.getReferences().size(), 0 ); }
3.555556
@Test public void testObtainEntityNameAssociationWithEntityNameAndNotAuditedModeInNewSession() { //force a new session and AR forceNewSession(); loadDataOnSessionAndAuditReader(); checkEntities(); checkEntityNames(); }
4.444444
@Test @Priority(10) public void initData() { EntityManager em = getEntityManager(); EmbeddableListEntity1 ele1 = new EmbeddableListEntity1(); // Revision 1 (ele1: initially 1 element in both collections) em.getTransaction().begin(); ele1.getComponentList().add( c3_1 ); em.persist( ele1 ); em.getTransaction().commit(); // Revision (still 1) (ele1: removing non-existing element) em.getTransaction().begin(); ele1 = em.find( EmbeddableListEntity1.class, ele1.getId() ); ele1.getComponentList().remove( c3_2 ); em.getTransaction().commit(); // Revision 2 (ele1: adding one element) em.getTransaction().begin(); ele1 = em.find( EmbeddableListEntity1.class, ele1.getId() ); ele1.getComponentList().add( c3_2 ); em.getTransaction().commit(); // Revision 3 (ele1: adding one existing element) em.getTransaction().begin(); ele1 = em.find( EmbeddableListEntity1.class, ele1.getId() ); ele1.getComponentList().add( c3_1 ); em.getTransaction().commit(); // Revision 4 (ele1: removing one existing element) em.getTransaction().begin(); ele1 = em.find( EmbeddableListEntity1.class, ele1.getId() ); ele1.getComponentList().remove( c3_2 ); em.getTransaction().commit(); ele1_id = ele1.getId(); em.close(); }
3.888889
@Test @Priority(10) public void initData() { EntityManager em = getEntityManager(); // Revision 1 em.getTransaction().begin(); PropertyOverrideEntity propertyEntity = new PropertyOverrideEntity( "data 1", 1, "data 2" ); em.persist( propertyEntity ); em.getTransaction().commit(); propertyEntityId = propertyEntity.getId(); // Revision 2 em.getTransaction().begin(); TransitiveOverrideEntity transitiveEntity = new TransitiveOverrideEntity( "data 1", 1, "data 2", 2, "data 3" ); em.persist( transitiveEntity ); em.getTransaction().commit(); transitiveEntityId = transitiveEntity.getId(); // Revision 3 em.getTransaction().begin(); AuditedSpecialEntity auditedEntity = new AuditedSpecialEntity( "data 1", 1, "data 2" ); em.persist( auditedEntity ); em.getTransaction().commit(); auditedEntityId = auditedEntity.getId(); propertyTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.superclass.auditoverride.PropertyOverrideEntity_AUD" ).getTable(); transitiveTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.superclass.auditoverride.TransitiveOverrideEntity_AUD" ).getTable(); auditedTable = getCfg().getClassMapping( "org.hibernate.envers.test.integration.superclass.auditoverride.AuditedSpecialEntity_AUD" ).getTable(); }
3.555556
protected void resetRegionUsageState(CacheAccessListener localListener, CacheAccessListener remoteListener) { String stdName = StandardQueryCache.class.getName(); String acctName = Account.class.getName(); localListener.getSawRegionModification( stdName ); localListener.getSawRegionModification( acctName ); localListener.getSawRegionAccess( stdName ); localListener.getSawRegionAccess( acctName ); remoteListener.getSawRegionModification( stdName ); remoteListener.getSawRegionModification( acctName ); remoteListener.getSawRegionAccess( stdName ); remoteListener.getSawRegionAccess( acctName ); log.info( "Region usage state cleared" ); }
3.777778
@Override public void configure(Configuration cfg) { super.configure( cfg ); cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" ); cfg.setProperty( Environment.GENERATE_STATISTICS, "true" ); cfg.setProperty( Environment.USE_QUERY_CACHE, "false" ); cfg.setProperty( Environment.CACHE_REGION_FACTORY, getCacheRegionFactory().getName() ); cfg.setProperty( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() ); cfg.getProperties().put( AvailableSettings.JTA_PLATFORM, getJtaPlatform() ); cfg.setProperty( Environment.CONNECTION_PROVIDER, getConnectionProviderClass().getName() ); }
4.444444
@Test public void testOrphanDelete() { Session session = openSession(); Transaction t = session.beginTransaction(); Product prod = new Product( "Widget" ); Part part = new Part( "Widge", "part if a Widget" ); MapKey mapKey = new MapKey( "Top" ); prod.getParts().put( mapKey, part ); Part part2 = new Part( "Get", "another part if a Widget" ); prod.getParts().put( new MapKey( "Bottom" ), part2 ); session.persist( prod ); t.commit(); session.close(); sessionFactory().getCache().evictEntityRegion(Product.class); sessionFactory().getCache().evictEntityRegion(Part.class); session = openSession(); t = session.beginTransaction(); prod = (Product) session.get(Product.class, "Widget"); assertTrue( Hibernate.isInitialized( prod.getParts() ) ); part = (Part) session.get(Part.class, "Widge"); prod.getParts().remove(mapKey); t.commit(); session.close(); sessionFactory().getCache().evictEntityRegion( Product.class ); sessionFactory().getCache().evictEntityRegion(Part.class); session = openSession(); t = session.beginTransaction(); prod = (Product) session.get(Product.class, "Widget"); assertTrue( Hibernate.isInitialized( prod.getParts() ) ); assertNull( prod.getParts().get(new MapKey("Top"))); assertNotNull( session.get(Part.class, "Get") ); session.delete( session.get(Product.class, "Widget") ); t.commit(); session.close(); }
3.111111
protected AnnotationInstance parserPrimaryKeyJoinColumnList(List<JaxbPrimaryKeyJoinColumn> primaryKeyJoinColumnList, AnnotationTarget target) { if ( MockHelper.isNotEmpty( primaryKeyJoinColumnList ) ) { if ( primaryKeyJoinColumnList.size() == 1 ) { return parserPrimaryKeyJoinColumn( primaryKeyJoinColumnList.get( 0 ), target ); } else { return create( PRIMARY_KEY_JOIN_COLUMNS, target, nestedPrimaryKeyJoinColumnList( "value", primaryKeyJoinColumnList, null ) ); } } return null; }
3.777778
public static <T> JaxbRoot<T> unmarshallXml(String fileName, String schemaName, Class<T> clazz, ClassLoaderService classLoaderService) throws JAXBException { Schema schema = getMappingSchema( schemaName, classLoaderService ); InputStream in = classLoaderService.locateResourceStream( fileName ); JAXBContext jc = JAXBContext.newInstance( clazz ); Unmarshaller unmarshaller = jc.createUnmarshaller(); unmarshaller.setSchema( schema ); StreamSource stream = new StreamSource( in ); JAXBElement<T> elem = unmarshaller.unmarshal( stream, clazz ); Origin origin = new Origin( null, fileName ); return new JaxbRoot<T>( elem.getValue(), origin ); }
3.111111
private AnnotationInstance overrideSchemaCatalogByDefault(AnnotationInstance annotationInstance, EntityMappingsMocker.Default defaults) { List<AnnotationValue> newAnnotationValueList = new ArrayList<AnnotationValue>(); newAnnotationValueList.addAll( annotationInstance.values() ); boolean schemaDefined = false; boolean catalogDefined = false; if ( annotationInstance.value( "schema" ) != null ) { schemaDefined = true; } if ( annotationInstance.value( "catalog" ) != null ) { catalogDefined = true; } if ( schemaDefined && catalogDefined ) { return annotationInstance; } if ( !catalogDefined && StringHelper.isNotEmpty( defaults.getCatalog() ) ) { newAnnotationValueList.add( AnnotationValue.createStringValue( "catalog", defaults.getCatalog() ) ); } if ( !schemaDefined && StringHelper.isNotEmpty( defaults.getSchema() ) ) { newAnnotationValueList.add( AnnotationValue.createStringValue( "schema", defaults.getSchema() ) ); } return MockHelper.create( annotationInstance.name(), annotationInstance.target(), MockHelper.toArray( newAnnotationValueList ) ); }
3.333333
public AbstractRowReader(ReaderCollector readerCollector) { this.entityReferenceInitializers = readerCollector.getEntityReferenceInitializers() != null ? new ArrayList<EntityReferenceInitializer>( readerCollector.getEntityReferenceInitializers() ) : Collections.<EntityReferenceInitializer>emptyList(); this.arrayReferenceInitializers = readerCollector.getArrayReferenceInitializers() != null ? new ArrayList<CollectionReferenceInitializer>( readerCollector.getArrayReferenceInitializers() ) : Collections.<CollectionReferenceInitializer>emptyList(); this.collectionReferenceInitializers = readerCollector.getNonArrayCollectionReferenceInitializers() != null ? new ArrayList<CollectionReferenceInitializer>( readerCollector.getNonArrayCollectionReferenceInitializers() ) : Collections.<CollectionReferenceInitializer>emptyList(); }
2.555556
private void resolveEntityKey( ResultSet resultSet, ResultSetProcessingContextImpl context, FetchSource fetchSource, Map<EntityReference,EntityReferenceInitializer> initializerByEntityReference) throws SQLException { // Resolve any bidirectional entity references first. for ( BidirectionalEntityReference bidirectionalEntityReference : fetchSource.getBidirectionalEntityReferences() ) { final EntityReferenceInitializer targetEntityReferenceInitializer = initializerByEntityReference.get( bidirectionalEntityReference.getTargetEntityReference() ); resolveEntityKey( resultSet, context, targetEntityReferenceInitializer, initializerByEntityReference ); targetEntityReferenceInitializer.hydrateEntityState( resultSet, context ); } for ( Fetch fetch : fetchSource.getFetches() ) { if ( EntityFetch.class.isInstance( fetch ) ) { final EntityFetch entityFetch = (EntityFetch) fetch; final EntityReferenceInitializer entityReferenceInitializer = initializerByEntityReference.get( entityFetch ); if ( entityReferenceInitializer != null ) { resolveEntityKey( resultSet, context, entityReferenceInitializer, initializerByEntityReference ); entityReferenceInitializer.hydrateEntityState( resultSet, context ); } } else if ( CompositeFetch.class.isInstance( fetch ) ) { resolveEntityKey( resultSet, context, (CompositeFetch) fetch, initializerByEntityReference ); } } }
3
public EntityKey interpretEntityKey( SessionImplementor session, String optionalEntityName, Serializable optionalId, Object optionalObject) { if ( optionalEntityName != null ) { final EntityPersister entityPersister; if ( optionalObject != null ) { entityPersister = session.getEntityPersister( optionalEntityName, optionalObject ); } else { entityPersister = session.getFactory().getEntityPersister( optionalEntityName ); } if ( entityPersister.isInstance( optionalId ) && !entityPersister.getEntityMetamodel().getIdentifierProperty().isVirtual() && entityPersister.getEntityMetamodel().getIdentifierProperty().isEmbedded() ) { // non-encapsulated composite identifier final Serializable identifierState = ((CompositeType) entityPersister.getIdentifierType()).getPropertyValues( optionalId, session ); return session.generateEntityKey( identifierState, entityPersister ); } else { return session.generateEntityKey( optionalId, entityPersister ); } } else { return null; } }
3
@Test public void testChildIdColumnName() { Assert.assertEquals( "other_id", ((Column) getCfg() .getClassMapping( "org.hibernate.envers.test.integration.inheritance.joined.primarykeyjoin.ChildPrimaryKeyJoinEntity_AUD" ) .getKey().getColumnIterator().next()).getName() ); }
3.666667
@After public void cleanup() { b.setC( null ); b.setD( null ); b.getGCollection().remove( g ); c.getBCollection().remove( b ); c.getDCollection().remove( d ); d.getBCollection().remove( b ); d.setC( null ); d.setE( null ); d.getFCollection().remove( f ); e.getDCollection().remove( d ); e.setF( null ); f.setD( null ); f.getECollection().remove( e ); f.setG( null ); g.setB( null ); g.getFCollection().remove( f ); Session s = openSession(); s.getTransaction().begin(); b = ( B ) s.merge( b ); c = ( C ) s.merge( c ); d = ( D ) s.merge( d ); e = ( E ) s.merge( e ); f = ( F ) s.merge( f ); g = ( G ) s.merge( g ); s.delete( f ); s.delete( g ); s.delete( b ); s.delete( d ); s.delete( e ); s.delete( c ); s.getTransaction().commit(); s.close(); }
3.222222