Package org.hibernate.mapping

Examples of org.hibernate.mapping.Join


    Iterator joins = secondaryTables.values().iterator();
    Iterator joinColumns = secondaryTableJoins.values().iterator();

    while ( joins.hasNext() ) {
      Object uncastedColumn = joinColumns.next();
      Join join = (Join) joins.next();
      createPrimaryColumnsToSecondaryTable( uncastedColumn, propertyHolder, join );
    }
    mappings.addJoins( persistentClass, secondaryTables );
  }
View Full Code Here


   */
  private Join addJoin(
      SecondaryTable secondaryTable, JoinTable joinTable, PropertyHolder propertyHolder,
      boolean noDelayInPkColumnCreation
  ) {
    Join join = new Join();
    join.setPersistentClass( persistentClass );
    String schema;
    String catalog;
    String table;
    String realTable;
    UniqueConstraint[] uniqueConstraintsAnn;
    if ( secondaryTable != null ) {
      schema = secondaryTable.schema();
      catalog = secondaryTable.catalog();
      table = secondaryTable.name();
      realTable = mappings.getNamingStrategy().tableName( table ); //always an explicit table name
      uniqueConstraintsAnn = secondaryTable.uniqueConstraints();
    }
    else if ( joinTable != null ) {
      schema = joinTable.schema();
      catalog = joinTable.catalog();
      table = joinTable.name();
      realTable = mappings.getNamingStrategy().tableName( table ); //always an explicit table name
      uniqueConstraintsAnn = joinTable.uniqueConstraints();
    }
    else {
      throw new AssertionFailure( "Both JoinTable and SecondaryTable are null" );
    }
    List uniqueConstraints = new ArrayList( uniqueConstraintsAnn == null ?
        0 :
        uniqueConstraintsAnn.length );
    if ( uniqueConstraintsAnn != null && uniqueConstraintsAnn.length != 0 ) {
      for (UniqueConstraint uc : uniqueConstraintsAnn) {
        uniqueConstraints.add( uc.columnNames() );
      }
    }
    Table tableMapping = TableBinder.fillTable(
        schema,
        catalog,
        realTable,
        table, false, uniqueConstraints, null, null, mappings
    );
    //no check constraints available on joins
    join.setTable( tableMapping );

    //somehow keep joins() for later.
    //Has to do the work later because it needs persistentClass id!
    Object joinColumns = null;
    //get the appropriate pk columns
    if ( secondaryTable != null ) {
      joinColumns = secondaryTable.pkJoinColumns();
    }
    else if ( joinTable != null ) {
      joinColumns = joinTable.joinColumns();
    }
    log.info(
        "Adding secondary table to entity {} -> {}", persistentClass.getEntityName(), join.getTable().getName()
    );

    org.hibernate.annotations.Table matchingTable = findMatchingComplimentTableAnnotation( join );
    if ( matchingTable != null ) {
      join.setSequentialSelect( FetchMode.JOIN != matchingTable.fetch() );
      join.setInverse( matchingTable.inverse() );
      join.setOptional( matchingTable.optional() );
      if ( !BinderHelper.isDefault( matchingTable.sqlInsert().sql() ) ) {
        join.setCustomSQLInsert( matchingTable.sqlInsert().sql().trim(),
            matchingTable.sqlInsert().callable(),
            ExecuteUpdateResultCheckStyle.parse( matchingTable.sqlInsert().check().toString().toLowerCase() )
        );
      }
      if ( !BinderHelper.isDefault( matchingTable.sqlUpdate().sql() ) ) {
        join.setCustomSQLUpdate( matchingTable.sqlUpdate().sql().trim(),
            matchingTable.sqlUpdate().callable(),
            ExecuteUpdateResultCheckStyle.parse( matchingTable.sqlUpdate().check().toString().toLowerCase() )
        );
      }
      if ( !BinderHelper.isDefault( matchingTable.sqlDelete().sql() ) ) {
        join.setCustomSQLDelete( matchingTable.sqlDelete().sql().trim(),
            matchingTable.sqlDelete().callable(),
            ExecuteUpdateResultCheckStyle.parse( matchingTable.sqlDelete().check().toString().toLowerCase() )
        );
      }
    }
    else {
      //default
      join.setSequentialSelect( false );
      join.setInverse( false );
      join.setOptional( true ); //perhaps not quite per-spec, but a Good Thing anyway
    }

    if ( noDelayInPkColumnCreation ) {
      createPrimaryColumnsToSecondaryTable( joinColumns, propertyHolder, join );
    }
View Full Code Here

      if ( otherSideProperty.getValue() instanceof OneToOne ) {
        propertyHolder.addProperty( prop );
      }
      else if ( otherSideProperty.getValue() instanceof ManyToOne ) {
        Iterator it = otherSide.getJoinIterator();
        Join otherSideJoin = null;
        while ( it.hasNext() ) {
          otherSideJoin = (Join) it.next();
          if ( otherSideJoin.containsProperty( otherSideProperty ) ) {
            break;
          }
        }
        if ( otherSideJoin != null ) {
          //@OneToOne @JoinTable
          Join mappedByJoin = buildJoinFromMappedBySide(
              (PersistentClass) persistentClasses.get( ownerEntity ), otherSideProperty, otherSideJoin
          );
          ManyToOne manyToOne = new ManyToOne( mappedByJoin.getTable() );
          //FIXME use ignore not found here
          manyToOne.setIgnoreNotFound( ignoreNotFound );
          manyToOne.setCascadeDeleteEnabled( value.isCascadeDeleteEnabled() );
          manyToOne.setEmbedded( value.isEmbedded() );
          manyToOne.setFetchMode( value.getFetchMode() );
          manyToOne.setLazy( value.isLazy() );
          manyToOne.setReferencedEntityName( value.getReferencedEntityName() );
          manyToOne.setUnwrapProxy( value.isUnwrapProxy() );
          prop.setValue( manyToOne );
          Iterator otherSideJoinKeyColumns = otherSideJoin.getKey().getColumnIterator();
          while ( otherSideJoinKeyColumns.hasNext() ) {
            Column column = (Column) otherSideJoinKeyColumns.next();
            Column copy = new Column();
            copy.setLength( column.getLength() );
            copy.setScale( column.getScale() );
            copy.setValue( manyToOne );
            copy.setName( column.getQuotedName() );
            copy.setNullable( column.isNullable() );
            copy.setPrecision( column.getPrecision() );
            copy.setUnique( column.isUnique() );
            copy.setSqlType( column.getSqlType() );
            copy.setCheckConstraint( column.getCheckConstraint() );
            copy.setComment( column.getComment() );
            copy.setDefaultValue( column.getDefaultValue() );
            manyToOne.addColumn( copy );
          }
          mappedByJoin.addProperty( prop );
        }
        else {
          propertyHolder.addProperty( prop );
        }
View Full Code Here

   * <li>From the mappedBy side we should not create the PK nor the FK, this is handled from the other side.</li>
   * <li>This method is a dirty dupe of EntityBinder.bindSecondaryTable</i>.
   * </p>
   */
  private Join buildJoinFromMappedBySide(PersistentClass persistentClass, Property otherSideProperty, Join originalJoin) {
    Join join = new Join();
    join.setPersistentClass( persistentClass );

    //no check constraints available on joins
    join.setTable( originalJoin.getTable() );
    join.setInverse( true );
    SimpleValue key = new DependantValue( join.getTable(), persistentClass.getIdentifier() );
    //TODO support @ForeignKey
    join.setKey( key );
    join.setSequentialSelect( false );
    //TODO support for inverse and optional
    join.setOptional( true ); //perhaps not quite per-spec, but a Good Thing anyway
    key.setCascadeDeleteEnabled( false );
    Iterator mappedByColumns = otherSideProperty.getValue().getColumnIterator();
    while ( mappedByColumns.hasNext() ) {
      Column column = (Column) mappedByColumns.next();
      Column copy = new Column();
View Full Code Here

            inheritedMetas,
            false
          );
      }
      else if ( "join".equals( name ) ) {
        Join join = new Join();
        join.setPersistentClass( persistentClass );
        bindJoin( subnode, join, mappings, inheritedMetas );
        persistentClass.addJoin( join );
      }
      else if ( "subclass".equals( name ) ) {
        handleSubclass( persistentClass, mappings, subnode, inheritedMetas );
View Full Code Here

    // else {
    return false;
  }

  public Join getJoin() {
    Join join = joins.get( secondaryTableName );
    if ( join == null ) {
      throw new AnnotationException(
          "Cannot find the expected secondary table: no "
              + secondaryTableName + " available for " + propertyHolder.getClassName()
      );
View Full Code Here

    // JOINS

    Iterator joinIter = persistentClass.getJoinClosureIterator();
    int j = 1;
    while ( joinIter.hasNext() ) {
      Join join = (Join) joinIter.next();
      qualifiedTableNames[j] = join.getTable().getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      isInverseTable[j] = join.isInverse();
      isNullableTable[j] = join.isOptional();
      cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() &&
        factory.getDialect().supportsCascadeDelete();

      customSQLInsert[j] = join.getCustomSQLInsert();
      insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable();
      insertResultCheckStyles[j] = join.getCustomSQLInsertCheckStyle() == null
                                    ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[j], insertCallable[j] )
                                      : join.getCustomSQLInsertCheckStyle();
      customSQLUpdate[j] = join.getCustomSQLUpdate();
      updateCallable[j] = customSQLUpdate[j] != null && join.isCustomUpdateCallable();
      updateResultCheckStyles[j] = join.getCustomSQLUpdateCheckStyle() == null
                                    ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[j], updateCallable[j] )
                                      : join.getCustomSQLUpdateCheckStyle();
      customSQLDelete[j] = join.getCustomSQLDelete();
      deleteCallable[j] = customSQLDelete[j] != null && join.isCustomDeleteCallable();
      deleteResultCheckStyles[j] = join.getCustomSQLDeleteCheckStyle() == null
                                    ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] )
                                      : join.getCustomSQLDeleteCheckStyle();

      Iterator iter = join.getKey().getColumnIterator();
      keyColumnNames[j] = new String[ join.getKey().getColumnSpan() ];
      int i = 0;
      while ( iter.hasNext() ) {
        Column col = (Column) iter.next();
        keyColumnNames[j][i++] = col.getQuotedName( factory.getDialect() );
      }

      j++;
    }

    constraintOrderedTableNames = new String[qualifiedTableNames.length];
    constraintOrderedKeyColumnNames = new String[qualifiedTableNames.length][];
    for ( int i = qualifiedTableNames.length - 1, position = 0; i >= 0; i--, position++ ) {
      constraintOrderedTableNames[position] = qualifiedTableNames[i];
      constraintOrderedKeyColumnNames[position] = keyColumnNames[i];
    }

    spaces = ArrayHelper.join(
        qualifiedTableNames,
        ArrayHelper.toStringArray( persistentClass.getSynchronizedTables() )
    );
   
    final boolean lazyAvailable = isInstrumented(EntityMode.POJO);

    boolean hasDeferred = false;
    ArrayList subclassTables = new ArrayList();
    ArrayList joinKeyColumns = new ArrayList();
    ArrayList isConcretes = new ArrayList();
    ArrayList isDeferreds = new ArrayList();
    ArrayList isInverses = new ArrayList();
    ArrayList isNullables = new ArrayList();
    ArrayList isLazies = new ArrayList();
    subclassTables.add( qualifiedTableNames[0] );
    joinKeyColumns.add( getIdentifierColumnNames() );
    isConcretes.add(Boolean.TRUE);
    isDeferreds.add(Boolean.FALSE);
    isInverses.add(Boolean.FALSE);
    isNullables.add(Boolean.FALSE);
    isLazies.add(Boolean.FALSE);
    joinIter = persistentClass.getSubclassJoinClosureIterator();
    while ( joinIter.hasNext() ) {
      Join join = (Join) joinIter.next();
      isConcretes.add( new Boolean( persistentClass.isClassOrSuperclassJoin(join) ) );
      isDeferreds.add( new Boolean( join.isSequentialSelect() ) );
      isInverses.add( new Boolean( join.isInverse() ) );
      isNullables.add( new Boolean( join.isOptional() ) );
      isLazies.add( new Boolean( lazyAvailable && join.isLazy() ) );
      if ( join.isSequentialSelect() && !persistentClass.isClassOrSuperclassJoin(join) ) hasDeferred = true;
      subclassTables.add( join.getTable().getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      ) );
      Iterator iter = join.getKey().getColumnIterator();
      String[] keyCols = new String[ join.getKey().getColumnSpan() ];
      int i = 0;
      while ( iter.hasNext() ) {
        Column col = (Column) iter.next();
        keyCols[i++] = col.getQuotedName( factory.getDialect() );
      }
View Full Code Here

            inheritedMetas,
            false
          );
      }
      else if ( "join".equals( name ) ) {
        Join join = new Join();
        join.setPersistentClass( persistentClass );
        bindJoin( subnode, join, mappings, inheritedMetas );
        persistentClass.addJoin( join );
      }
      else if ( "subclass".equals( name ) ) {
        handleSubclass( persistentClass, mappings, subnode, inheritedMetas );
View Full Code Here

    Iterator joins = secondaryTables.values().iterator();
    Iterator joinColumns = secondaryTableJoins.values().iterator();

    while ( joins.hasNext() ) {
      Object uncastedColumn = joinColumns.next();
      Join join = (Join) joins.next();
      createPrimaryColumnsToSecondaryTable( uncastedColumn, propertyHolder, join );
    }
    mappings.addJoins( persistentClass, secondaryTables );
  }
View Full Code Here

      SecondaryTable secondaryTable,
      JoinTable joinTable,
      PropertyHolder propertyHolder,
      boolean noDelayInPkColumnCreation) {
    // A non null propertyHolder means than we process the Pk creation without delay
    Join join = new Join();
    join.setPersistentClass( persistentClass );

    final String schema;
    final String catalog;
    final SecondaryTableNameSource secondaryTableNameContext;
    final Object joinColumns;
    final List<UniqueConstraintHolder> uniqueConstraintHolders;

    if ( secondaryTable != null ) {
      schema = secondaryTable.schema();
      catalog = secondaryTable.catalog();
      secondaryTableNameContext = new SecondaryTableNameSource( secondaryTable.name() );
      joinColumns = secondaryTable.pkJoinColumns();
      uniqueConstraintHolders = TableBinder.buildUniqueConstraintHolders( secondaryTable.uniqueConstraints() );
    }
    else if ( joinTable != null ) {
      schema = joinTable.schema();
      catalog = joinTable.catalog();
      secondaryTableNameContext = new SecondaryTableNameSource( joinTable.name() );
      joinColumns = joinTable.joinColumns();
      uniqueConstraintHolders = TableBinder.buildUniqueConstraintHolders( joinTable.uniqueConstraints() );
    }
    else {
      throw new AssertionFailure( "Both JoinTable and SecondaryTable are null" );
    }

    final Table table = TableBinder.buildAndFillTable(
        schema,
        catalog,
        secondaryTableNameContext,
        SEC_TBL_NS_HELPER,
        false,
        uniqueConstraintHolders,
        null,
        null,
        mappings,
        null
    );

    if ( secondaryTable != null ) {
      TableBinder.addIndexes( table, secondaryTable.indexes(), mappings );
    }

      //no check constraints available on joins
    join.setTable( table );

    //somehow keep joins() for later.
    //Has to do the work later because it needs persistentClass id!
    LOG.debugf( "Adding secondary table to entity %s -> %s", persistentClass.getEntityName(), join.getTable().getName() );
    org.hibernate.annotations.Table matchingTable = findMatchingComplimentTableAnnotation( join );
    if ( matchingTable != null ) {
      join.setSequentialSelect( FetchMode.JOIN != matchingTable.fetch() );
      join.setInverse( matchingTable.inverse() );
      join.setOptional( matchingTable.optional() );
      if ( !BinderHelper.isEmptyAnnotationValue( matchingTable.sqlInsert().sql() ) ) {
        join.setCustomSQLInsert( matchingTable.sqlInsert().sql().trim(),
            matchingTable.sqlInsert().callable(),
            ExecuteUpdateResultCheckStyle.fromExternalName(
                matchingTable.sqlInsert().check().toString().toLowerCase()
            )
        );
      }
      if ( !BinderHelper.isEmptyAnnotationValue( matchingTable.sqlUpdate().sql() ) ) {
        join.setCustomSQLUpdate( matchingTable.sqlUpdate().sql().trim(),
            matchingTable.sqlUpdate().callable(),
            ExecuteUpdateResultCheckStyle.fromExternalName(
                matchingTable.sqlUpdate().check().toString().toLowerCase()
            )
        );
      }
      if ( !BinderHelper.isEmptyAnnotationValue( matchingTable.sqlDelete().sql() ) ) {
        join.setCustomSQLDelete( matchingTable.sqlDelete().sql().trim(),
            matchingTable.sqlDelete().callable(),
            ExecuteUpdateResultCheckStyle.fromExternalName(
                matchingTable.sqlDelete().check().toString().toLowerCase()
            )
        );
      }
    }
    else {
      //default
      join.setSequentialSelect( false );
      join.setInverse( false );
      join.setOptional( true ); //perhaps not quite per-spec, but a Good Thing anyway
    }

    if ( noDelayInPkColumnCreation ) {
      createPrimaryColumnsToSecondaryTable( joinColumns, propertyHolder, join );
    }
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Join

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.