Package org.hibernate.mapping

Examples of org.hibernate.mapping.Column


    if ( schema != null ) {
      idTable.setSchema( schema );
    }
    Iterator itr = entityMapping.getTable().getPrimaryKey().getColumnIterator();
    while( itr.hasNext() ) {
      Column column = (Column) itr.next();
      idTable.addColumn( column.clone()  );
    }
    Column sessionIdColumn = new Column( "hib_sess_id" );
    sessionIdColumn.setSqlType( "CHAR(36)" );
    sessionIdColumn.setComment( "Used to hold the Hibernate Session identifier" );
    idTable.addColumn( sessionIdColumn );

    idTable.setComment( "Used to hold id values for the " + entityMapping.getEntityName() + " class" );
    return idTable;
  }
View Full Code Here


    loaderName = persistentClass.getLoaderName();

    Iterator iter = persistentClass.getIdentifier().getColumnIterator();
    int i = 0;
    while ( iter.hasNext() ) {
      Column col = ( Column ) iter.next();
      rootTableKeyColumnNames[i] = col.getQuotedName( factory.getDialect() );
      rootTableKeyColumnReaders[i] = col.getReadExpr( factory.getDialect() );
      rootTableKeyColumnReaderTemplates[i] = col.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
      identifierAliases[i] = col.getAlias( factory.getDialect(), persistentClass.getRootTable() );
      i++;
    }

    // VERSION

    if ( persistentClass.isVersioned() ) {
      versionColumnName = ( ( Column ) persistentClass.getVersion().getColumnIterator().next() ).getQuotedName( factory.getDialect() );
    }
    else {
      versionColumnName = null;
    }

    //WHERE STRING

    sqlWhereString = StringHelper.isNotEmpty( persistentClass.getWhere() ) ? "( " + persistentClass.getWhere() + ") " : null;
    sqlWhereStringTemplate = sqlWhereString == null ?
        null :
        Template.renderWhereStringTemplate( sqlWhereString, factory.getDialect(), factory.getSqlFunctionRegistry() );

    // PROPERTIES

    final boolean lazyAvailable = isInstrumented();

    int hydrateSpan = entityMetamodel.getPropertySpan();
    propertyColumnSpans = new int[hydrateSpan];
    propertySubclassNames = new String[hydrateSpan];
    propertyColumnAliases = new String[hydrateSpan][];
    propertyColumnNames = new String[hydrateSpan][];
    propertyColumnFormulaTemplates = new String[hydrateSpan][];
    propertyColumnReaderTemplates = new String[hydrateSpan][];
    propertyColumnWriters = new String[hydrateSpan][];
    propertyUniqueness = new boolean[hydrateSpan];
    propertySelectable = new boolean[hydrateSpan];
    propertyColumnUpdateable = new boolean[hydrateSpan][];
    propertyColumnInsertable = new boolean[hydrateSpan][];
    HashSet thisClassProperties = new HashSet();

    lazyProperties = new HashSet();
    ArrayList lazyNames = new ArrayList();
    ArrayList lazyNumbers = new ArrayList();
    ArrayList lazyTypes = new ArrayList();
    ArrayList lazyColAliases = new ArrayList();

    iter = persistentClass.getPropertyClosureIterator();
    i = 0;
    boolean foundFormula = false;
    while ( iter.hasNext() ) {
      Property prop = ( Property ) iter.next();
      thisClassProperties.add( prop );

      int span = prop.getColumnSpan();
      propertyColumnSpans[i] = span;
      propertySubclassNames[i] = prop.getPersistentClass().getEntityName();
      String[] colNames = new String[span];
      String[] colAliases = new String[span];
      String[] colReaderTemplates = new String[span];
      String[] colWriters = new String[span];
      String[] formulaTemplates = new String[span];
      Iterator colIter = prop.getColumnIterator();
      int k = 0;
      while ( colIter.hasNext() ) {
        Selectable thing = ( Selectable ) colIter.next();
        colAliases[k] = thing.getAlias( factory.getDialect() , prop.getValue().getTable() );
        if ( thing.isFormula() ) {
          foundFormula = true;
          formulaTemplates[k] = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        }
        else {
          Column col = (Column)thing;
          colNames[k] = col.getQuotedName( factory.getDialect() );
          colReaderTemplates[k] = col.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
          colWriters[k] = col.getWriteExpr();
        }
        k++;
      }
      propertyColumnNames[i] = colNames;
      propertyColumnFormulaTemplates[i] = formulaTemplates;
      propertyColumnReaderTemplates[i] = colReaderTemplates;
      propertyColumnWriters[i] = colWriters;
      propertyColumnAliases[i] = colAliases;

      if ( lazyAvailable && prop.isLazy() ) {
        lazyProperties.add( prop.getName() );
        lazyNames.add( prop.getName() );
        lazyNumbers.add( i );
        lazyTypes.add( prop.getValue().getType() );
        lazyColAliases.add( colAliases );
      }

      propertyColumnUpdateable[i] = prop.getValue().getColumnUpdateability();
      propertyColumnInsertable[i] = prop.getValue().getColumnInsertability();

      propertySelectable[i] = prop.isSelectable();

      propertyUniqueness[i] = prop.getValue().isAlternateUniqueKey();
     
      if (prop.isLob() && getFactory().getDialect().forceLobAsLastValue() ) {
        lobProperties.add( i );
      }

      i++;

    }
    hasFormulaProperties = foundFormula;
    lazyPropertyColumnAliases = ArrayHelper.to2DStringArray( lazyColAliases );
    lazyPropertyNames = ArrayHelper.toStringArray( lazyNames );
    lazyPropertyNumbers = ArrayHelper.toIntArray( lazyNumbers );
    lazyPropertyTypes = ArrayHelper.toTypeArray( lazyTypes );

    // SUBCLASS PROPERTY CLOSURE

    ArrayList columns = new ArrayList();
    ArrayList columnsLazy = new ArrayList();
    ArrayList columnReaderTemplates = new ArrayList();
    ArrayList aliases = new ArrayList();
    ArrayList formulas = new ArrayList();
    ArrayList formulaAliases = new ArrayList();
    ArrayList formulaTemplates = new ArrayList();
    ArrayList formulasLazy = new ArrayList();
    ArrayList types = new ArrayList();
    ArrayList names = new ArrayList();
    ArrayList classes = new ArrayList();
    ArrayList templates = new ArrayList();
    ArrayList propColumns = new ArrayList();
    ArrayList propColumnReaders = new ArrayList();
    ArrayList propColumnReaderTemplates = new ArrayList();
    ArrayList joinedFetchesList = new ArrayList();
    ArrayList cascades = new ArrayList();
    ArrayList definedBySubclass = new ArrayList();
    ArrayList propColumnNumbers = new ArrayList();
    ArrayList propFormulaNumbers = new ArrayList();
    ArrayList columnSelectables = new ArrayList();
    ArrayList propNullables = new ArrayList();

    iter = persistentClass.getSubclassPropertyClosureIterator();
    while ( iter.hasNext() ) {
      Property prop = ( Property ) iter.next();
      names.add( prop.getName() );
      classes.add( prop.getPersistentClass().getEntityName() );
      boolean isDefinedBySubclass = !thisClassProperties.contains( prop );
      definedBySubclass.add( Boolean.valueOf( isDefinedBySubclass ) );
      propNullables.add( Boolean.valueOf( prop.isOptional() || isDefinedBySubclass ) ); //TODO: is this completely correct?
      types.add( prop.getType() );

      Iterator colIter = prop.getColumnIterator();
      String[] cols = new String[prop.getColumnSpan()];
      String[] readers = new String[prop.getColumnSpan()];
      String[] readerTemplates = new String[prop.getColumnSpan()];
      String[] forms = new String[prop.getColumnSpan()];
      int[] colnos = new int[prop.getColumnSpan()];
      int[] formnos = new int[prop.getColumnSpan()];
      int l = 0;
      Boolean lazy = Boolean.valueOf( prop.isLazy() && lazyAvailable );
      while ( colIter.hasNext() ) {
        Selectable thing = ( Selectable ) colIter.next();
        if ( thing.isFormula() ) {
          String template = thing.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
          formnos[l] = formulaTemplates.size();
          colnos[l] = -1;
          formulaTemplates.add( template );
          forms[l] = template;
          formulas.add( thing.getText( factory.getDialect() ) );
          formulaAliases.add( thing.getAlias( factory.getDialect() ) );
          formulasLazy.add( lazy );
        }
        else {
          Column col = (Column)thing;
          String colName = col.getQuotedName( factory.getDialect() );
          colnos[l] = columns.size(); //before add :-)
          formnos[l] = -1;
          columns.add( colName );
          cols[l] = colName;
          aliases.add( thing.getAlias( factory.getDialect(), prop.getValue().getTable() ) );
          columnsLazy.add( lazy );
          columnSelectables.add( Boolean.valueOf( prop.isSelectable() ) );

          readers[l] = col.getReadExpr( factory.getDialect() );
          String readerTemplate = col.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
          readerTemplates[l] = readerTemplate;
          columnReaderTemplates.add( readerTemplate );
        }
        l++;
      }
View Full Code Here

    if ( Min.class.equals( descriptor.getAnnotation().annotationType() ) ) {
      @SuppressWarnings("unchecked")
      ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor;
      long min = minConstraint.getAnnotation().value();

      Column col = (Column) property.getColumnIterator().next();
      String checkConstraint = col.getName() + ">=" + min;
      applySQLCheck( col, checkConstraint );
    }
  }
View Full Code Here

  private static void applyMax(Property property, ConstraintDescriptor<?> descriptor) {
    if ( Max.class.equals( descriptor.getAnnotation().annotationType() ) ) {
      @SuppressWarnings("unchecked")
      ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor;
      long max = maxConstraint.getAnnotation().value();
      Column col = (Column) property.getColumnIterator().next();
      String checkConstraint = col.getName() + "<=" + max;
      applySQLCheck( col, checkConstraint );
    }
  }
View Full Code Here

    if ( Digits.class.equals( descriptor.getAnnotation().annotationType() ) ) {
      @SuppressWarnings("unchecked")
      ConstraintDescriptor<Digits> digitsConstraint = (ConstraintDescriptor<Digits>) descriptor;
      int integerDigits = digitsConstraint.getAnnotation().integer();
      int fractionalDigits = digitsConstraint.getAnnotation().fraction();
      Column col = (Column) property.getColumnIterator().next();
      col.setPrecision( integerDigits + fractionalDigits );
      col.setScale( fractionalDigits );
    }
  }
View Full Code Here

    if ( Size.class.equals( descriptor.getAnnotation().annotationType() )
        && String.class.equals( propertyDescriptor.getElementClass() ) ) {
      @SuppressWarnings("unchecked")
      ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
      int max = sizeConstraint.getAnnotation().max();
      Column col = (Column) property.getColumnIterator().next();
      if ( max < Integer.MAX_VALUE ) {
        col.setLength( max );
      }
    }
  }
View Full Code Here

        descriptor.getAnnotation().annotationType().getName()
    )
        && String.class.equals( propertyDescriptor.getElementClass() ) ) {
      @SuppressWarnings("unchecked")
      int max = (Integer) descriptor.getAttributes().get( "max" );
      Column col = (Column) property.getColumnIterator().next();
      if ( max < Integer.MAX_VALUE ) {
        col.setLength( max );
      }
    }
  }
View Full Code Here

      addConstraintToColumn( mappings.getLogicalColumnName( column.getMappingColumn().getQuotedName(), table ) );
    }
  }

  private void addConstraintToColumn(String columnName) {
    Column column = table.getColumn(
        new Column(
            mappings.getPhysicalColumnName( columnName, table )
        )
    );
    if ( column == null ) {
      throw new AnnotationException(
View Full Code Here

      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() );
      }
      joinKeyColumns.add(keyCols);
    }
   
    subclassTableSequentialSelect = ArrayHelper.toBooleanArray(isDeferreds);
    subclassTableNameClosure = ArrayHelper.toStringArray(subclassTables);
    subclassTableIsLazyClosure = ArrayHelper.toBooleanArray(isLazies);
    subclassTableKeyColumnClosure = ArrayHelper.to2DStringArray( joinKeyColumns );
    isClassOrSuperclassTable = ArrayHelper.toBooleanArray(isConcretes);
    isInverseSubclassTable = ArrayHelper.toBooleanArray(isInverses);
    isNullableSubclassTable = ArrayHelper.toBooleanArray(isNullables);
    hasSequentialSelects = hasDeferred;

    // DISCRIMINATOR

    if ( persistentClass.isPolymorphic() ) {
      Value discrimValue = persistentClass.getDiscriminator();
      if (discrimValue==null) {
        throw new MappingException("discriminator mapping required for single table polymorphic persistence");
      }
      forceDiscriminator = persistentClass.isForceDiscriminator();
      Selectable selectable = (Selectable) discrimValue.getColumnIterator().next();
      if ( discrimValue.hasFormula() ) {
        Formula formula = (Formula) selectable;
        discriminatorFormula = formula.getFormula();
        discriminatorFormulaTemplate = formula.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        discriminatorColumnName = null;
        discriminatorColumnReaders = null;
        discriminatorColumnReaderTemplate = null;
        discriminatorAlias = "clazz_";
      }
      else {
        Column column = (Column) selectable;
        discriminatorColumnName = column.getQuotedName( factory.getDialect() );
        discriminatorColumnReaders = column.getReadExpr( factory.getDialect() );
        discriminatorColumnReaderTemplate = column.getTemplate( factory.getDialect(), factory.getSqlFunctionRegistry() );
        discriminatorAlias = column.getAlias( factory.getDialect(), persistentClass.getRootTable() );
        discriminatorFormula = null;
        discriminatorFormulaTemplate = null;
      }
      discriminatorType = persistentClass.getDiscriminator().getType();
      if ( persistentClass.isDiscriminatorValueNull() ) {
View Full Code Here

        }
        else {
          fkRefs = fk.getReferencedColumns();
        }
        for ( int i = 0; i < fk.getColumnSpan(); i++ ) {
          Column column = fk.getColumn( i );
          Column ref = ( Column ) fkRefs.get( i );
          if ( !hasReference( column, ref ) ) {
            return false;
          }
        }
        return true;
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Column

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.