/** * @deprecated User {@link Component#Component(MetadataBuildingContext, Join)} instead. */ @Deprecated public Component(MetadataImplementor metadata, Join join) throws MappingException { this( metadata, join.getTable(), join.getPersistentClass() ); }
/** * Needed for proper compliance with naming strategy, the property table * can be overriden if the properties are part of secondary tables */ private Map<String, Join> getJoinsPerRealTableName() { if ( joinsPerRealTableName == null ) { joinsPerRealTableName = new HashMap<String, Join>( joins.size() ); for (Join join : joins.values()) { joinsPerRealTableName.put( join.getTable().getName(), join ); } } return joinsPerRealTableName; }
public Component(MetadataBuildingContext metadata, Join join) throws MappingException { this( metadata, join.getTable(), join.getPersistentClass() ); }
@Override public Table resolveTable(Identifier tableName) { if ( tableName == null ) { return primaryTable; } if ( Identifier.areEqual( primaryTableLogicalName, tableName ) ) { return primaryTable; } Join secondaryTableJoin = null; if ( secondaryTableJoinMap != null ) { //secondaryTableJoin = secondaryTableJoinMap.get( tableName ); secondaryTableJoin = secondaryTableJoinMap.get( tableName.getCanonicalName() ); } if ( secondaryTableJoin != null ) { return secondaryTableJoin.getTable(); } if ( superEntityTableXref != null ) { return superEntityTableXref.resolveTable( tableName ); } return null; }
/** * Find appropriate table of the column. * It can come from a secondary table or from the main table of the persistent class * * @return appropriate table * @throws AnnotationException missing secondary table */ public Table getTable() { if ( table != null ){ return table; } if ( isSecondary() ) { return getJoin().getTable(); } else { return propertyHolder.getTable(); } }
private SecondaryTable findMatchingSecondaryTable(Join join) { final String nameToMatch = join.getTable().getQuotedName(); SecondaryTable secondaryTable = annotatedClass.getAnnotation( SecondaryTable.class ); if ( secondaryTable != null && nameToMatch.equals( secondaryTable.name() ) ) { return secondaryTable; } SecondaryTables secondaryTables = annotatedClass.getAnnotation( SecondaryTables.class ); if ( secondaryTables != null ) { for ( SecondaryTable secondaryTablesEntry : secondaryTables.value() ) { if ( secondaryTablesEntry != null && nameToMatch.equals( secondaryTablesEntry.name() ) ) { return secondaryTablesEntry; } } } return null; }
private org.hibernate.annotations.Table findMatchingComplimentTableAnnotation(Join join) { String tableName = join.getTable().getQuotedName(); org.hibernate.annotations.Table table = annotatedClass.getAnnotation( org.hibernate.annotations.Table.class ); org.hibernate.annotations.Table matchingTable = null; if ( table != null && tableName.equals( table.appliesTo() ) ) { matchingTable = table; } else { Tables tables = annotatedClass.getAnnotation( Tables.class ); if ( tables != null ) { for (org.hibernate.annotations.Table current : tables.value()) { if ( tableName.equals( current.appliesTo() ) ) { matchingTable = current; break; } } } } return matchingTable; }
@SuppressWarnings({"unchecked"}) @Test public void testTableNames() { assert "sec_embid_versions".equals( ((Iterator<Join>) metadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.ids.SecondaryEmbIdTestEntity_AUD" ).getJoinIterator()).next().getTable().getName() ); } }
@SuppressWarnings({"unchecked"}) @Test public void testTableNames() { assert "secondary_AUD".equals( ((Iterator<Join>) metadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.SecondaryTestEntity_AUD" ) .getJoinIterator()) .next().getTable().getName() ); } }
@SuppressWarnings({"unchecked"}) @Test public void testTableNames() { assert "sec_mulid_versions".equals( ((Iterator<Join>) metadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.ids.SecondaryMulIdTestEntity_AUD" ) .getJoinIterator()) .next().getTable().getName() ); } }
@SuppressWarnings({"unchecked"}) @Test public void testTableNames() { assert "sec_versions".equals( ((Iterator<Join>) metadata().getEntityBinding( "org.hibernate.envers.test.integration.secondary.SecondaryNamingTestEntity_AUD" ) .getJoinIterator()) .next().getTable().getName() ); } }
final String originalTableName = join.getTable().getName(); String auditTableName = auditingData.getSecondaryTableDictionary().get( originalTableName ); if ( auditTableName == null ) { final String schema = getSchema( auditingData.getAuditTable().schema(), join.getTable() ); final String catalog = getCatalog( auditingData.getAuditTable().catalog(), join.getTable() );
while ( !found && joins.hasNext() ) { result = joins.next(); currentTable = ( (Join) result ).getTable(); try { context.getMetadataCollector().getPhysicalColumnName( currentTable, columnName );
private void bindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColumns, MetadataBuildingContext buildingContext) { SimpleValue key = new DependantValue( buildingContext, join.getTable(), persistentClass.getIdentifier() ); join.setKey( key ); setFKNameIfDefined( join ); key.setCascadeDeleteEnabled( false ); TableBinder.bindFk( persistentClass, null, ejb3JoinColumns, key, false, buildingContext ); join.createPrimaryKey(); join.createForeignKey(); persistentClass.addJoin( join ); }
@Test public void testDefaultValue() throws Exception { Join join = (Join) metadata().getEntityBinding( Life.class.getName() ).getJoinClosureIterator().next(); assertEquals( "ExtendedLife", join.getTable().getName() ); org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column(); owner.setName( "LIFE_ID" ); assertTrue( join.getTable().getPrimaryKey().containsColumn( owner ) ); Session s = openSession(); Transaction tx = s.beginTransaction(); Life life = new Life(); life.duration = 15; life.fullDescription = "Long long description"; s.persist( life ); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); Query q = s.createQuery( "from " + Life.class.getName() ); life = (Life) q.uniqueResult(); assertEquals( "Long long description", life.fullDescription ); tx.commit(); s.close(); }
@Test public void testSecondaryTableIndex(){ PersistentClass entity = metadata().getEntityBinding( Car.class.getName() ); Join join = (Join)entity.getJoinIterator().next(); Iterator<Index> itr = join.getTable().getIndexIterator(); assertTrue( itr.hasNext() ); Index index = itr.next(); assertFalse( itr.hasNext() ); assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) ); assertEquals( 2, index.getColumnSpan() ); Iterator<Column> columnIterator = index.getColumnIterator(); Column column = columnIterator.next(); assertEquals( "dealer_name", column.getName() ); column = columnIterator.next(); assertEquals( "rate", column.getName() ); assertSame( join.getTable(), index.getTable() ); }
@Test public void testCompositePK() throws Exception { Join join = (Join) metadata().getEntityBinding( Dog.class.getName() ).getJoinClosureIterator().next(); assertEquals( "DogThoroughbred", join.getTable().getName() ); org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column(); owner.setName( "OWNER_NAME" ); assertTrue( join.getTable().getPrimaryKey().containsColumn( owner ) ); Session s = openSession(); Transaction tx = s.beginTransaction(); Dog dog = new Dog(); DogPk id = new DogPk(); id.name = "Thalie"; id.ownerName = "Martine"; dog.id = id; dog.weight = 30; dog.thoroughbredName = "Colley"; s.persist( dog ); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); Query q = s.createQuery( "from Dog" ); dog = (Dog) q.uniqueResult(); assertEquals( "Colley", dog.thoroughbredName ); tx.commit(); s.close(); }
private void associateSubclassNamesToSubclassTableIndexes( PersistentClass persistentClass, Set<String> classNames, String[][] mapping, SessionFactoryImplementor factory) { final String tableName = persistentClass.getTable().getQualifiedName( factory.getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping ); Iterator itr = persistentClass.getJoinIterator(); while ( itr.hasNext() ) { final Join join = (Join) itr.next(); final String secondaryTableName = join.getTable().getQualifiedName( factory.getDialect(), factory.getSettings().getDefaultCatalogName(), factory.getSettings().getDefaultSchemaName() ); associateSubclassNamesToSubclassTableIndex( secondaryTableName, classNames, mapping ); } }