Package org.hibernate.mapping

Examples of org.hibernate.mapping.Join


        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        final boolean mandatory = !ann.optional() || forcePersist;
        bindManyToOne(
            getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist ),
            joinColumns,
            !mandatory,
            ignoreNotFound, onDeleteCascade,
            ToOneBinder.getTargetEntity( inferredData, mappings ),
            propertyHolder,
            inferredData, false, isIdentifierMapper,
            inSecondPass, propertyBinder, mappings
        );
      }
      else if ( property.isAnnotationPresent( OneToOne.class ) ) {
        OneToOne ann = property.getAnnotation( OneToOne.class );

        //check validity
        if ( property.isAnnotationPresent( Column.class )
            || property.isAnnotationPresent( Columns.class ) ) {
          throw new AnnotationException(
              "@Column(s) not allowed on a @OneToOne property: "
                  + BinderHelper.getPath( propertyHolder, inferredData )
          );
        }

        //FIXME support a proper PKJCs
        boolean trueOneToOne = property.isAnnotationPresent( PrimaryKeyJoinColumn.class )
            || property.isAnnotationPresent( PrimaryKeyJoinColumns.class );
        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        NotFound notFound = property.getAnnotation( NotFound.class );
        boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        //MapsId means the columns belong to the pk => not null
        //@OneToOne with @PKJC can still be optional
        final boolean mandatory = !ann.optional() || forcePersist;
        bindOneToOne(
            getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ),
            joinColumns,
            !mandatory,
            getFetchMode( ann.fetch() ),
            ignoreNotFound, onDeleteCascade,
            ToOneBinder.getTargetEntity( inferredData, mappings ),
            propertyHolder,
            inferredData,
            ann.mappedBy(),
            trueOneToOne,
            isIdentifierMapper,
            inSecondPass,
            propertyBinder,
            mappings
        );
      }
      else if ( property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {

        //check validity
        if ( property.isAnnotationPresent( Column.class )
            || property.isAnnotationPresent( Columns.class ) ) {
          throw new AnnotationException(
              "@Column(s) not allowed on a @Any property: "
                  + BinderHelper.getPath( propertyHolder, inferredData )
          );
        }

        Cascade hibernateCascade = property.getAnnotation( Cascade.class );
        OnDelete onDeleteAnn = property.getAnnotation( OnDelete.class );
        boolean onDeleteCascade = onDeleteAnn != null && OnDeleteAction.CASCADE.equals( onDeleteAnn.action() );
        JoinTable assocTable = propertyHolder.getJoinTable( property );
        if ( assocTable != null ) {
          Join join = propertyHolder.addJoin( assocTable, false );
          for ( Ejb3JoinColumn joinColumn : joinColumns ) {
            joinColumn.setSecondaryTableName( join.getTable().getName() );
          }
        }
        bindAny(
            getCascadeStrategy( null, hibernateCascade, false, forcePersist ),
            //@Any has not cascade attribute
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();

    boolean hasDeferred = false;
    ArrayList subclassTables = new ArrayList();
    ArrayList joinKeyColumns = new ArrayList();
    ArrayList<Boolean> isConcretes = new ArrayList<Boolean>();
    ArrayList<Boolean> isDeferreds = new ArrayList<Boolean>();
    ArrayList<Boolean> isInverses = new ArrayList<Boolean>();
    ArrayList<Boolean> isNullables = new ArrayList<Boolean>();
    ArrayList<Boolean> isLazies = new ArrayList<Boolean>();
    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( persistentClass.isClassOrSuperclassJoin(join) );
      isDeferreds.add( join.isSequentialSelect() );
      isInverses.add( join.isInverse() );
      isNullables.add( join.isOptional() );
      isLazies.add( 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

        Map<Join, Element> joinElements = new HashMap<Join, Element>();
        entitiesJoins.put(pc.getEntityName(), joinElements);

        while (joins.hasNext()) {
            Join join = joins.next();

      // Checking if all of the join properties are audited
      if (!checkPropertiesAudited(join.getPropertyIterator(), auditingData)) {
        continue;
      }

            // Determining the table name. If there is no entry in the dictionary, just constructing the table name
            // as if it was an entity (by appending/prepending configured strings).
            String originalTableName = join.getTable().getName();
            String auditTableName = auditingData.getSecondaryTableDictionary().get(originalTableName);
            if (auditTableName == null) {
                auditTableName = verEntCfg.getAuditEntityName(originalTableName);
            }

            String schema = getSchema(auditingData.getAuditTable().schema(), join.getTable());
            String catalog = getCatalog(auditingData.getAuditTable().catalog(), join.getTable());

            Element joinElement = MetadataTools.createJoin(parent, auditTableName, schema, catalog);
            joinElements.put(join, joinElement);

            Element joinKey = joinElement.addElement("key");
            MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
            MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null, 0, 0, null, null, null);
        }
    }
View Full Code Here

    private void addJoins(PersistentClass pc, CompositeMapperBuilder currentMapper, ClassAuditingData auditingData,
                          String entityName, EntityXmlMappingData xmlMappingData,boolean firstPass) {
        Iterator<Join> joins = pc.getJoinIterator();

        while (joins.hasNext()) {
            Join join = joins.next();
            Element joinElement = entitiesJoins.get(entityName).get(join);

      if (joinElement != null) {
              addProperties(joinElement, join.getPropertyIterator(), currentMapper, auditingData, entityName,
                      xmlMappingData, firstPass);
      }
        }
    }
View Full Code Here

      else {
        //find the appropriate reference key, can be in a join
        Iterator joinsIt = referencedEntity.getJoinIterator();
        KeyValue key = null;
        while ( joinsIt.hasNext() ) {
          Join join = (Join) joinsIt.next();
          if ( join.containsProperty( property ) ) {
            key = join.getKey();
            break;
          }
        }
        if ( key == null ) key = property.getPersistentClass().getIdentifier();
        mappedByColumns = key.getColumnIterator();
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
    );

    //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.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

      else {
        //find the appropriate reference key, can be in a join
        Iterator joinsIt = referencedEntity.getJoinIterator();
        KeyValue key = null;
        while ( joinsIt.hasNext() ) {
          Join join = (Join) joinsIt.next();
          if ( join.containsProperty( property ) ) {
            key = join.getKey();
            break;
          }
        }
        if ( key == null ) key = property.getPersistentClass().getIdentifier();
        mappedByColumns = key.getColumnIterator();
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

      if ( otherSideProperty.getValue() instanceof OneToOne ) {
        propertyHolder.addProperty( prop, inferredData.getDeclaringClass() );
      }
      else if ( otherSideProperty.getValue() instanceof ManyToOne ) {
        Iterator it = otherSide.getJoinIterator();
        Join otherSideJoin = null;
        while ( it.hasNext() ) {
          Join otherSideJoinValue = (Join) it.next();
          if ( otherSideJoinValue.containsProperty( otherSideProperty ) ) {
            otherSideJoin = otherSideJoinValue;
            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, inferredData.getDeclaringClass() );
        }
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.