Package org.hibernate.mapping

Examples of org.hibernate.mapping.Table


    joinSpan = persistentClass.getJoinClosureSpan()+1;
    qualifiedTableNames = new String[joinSpan];
    isInverseTable = new boolean[joinSpan];
    isNullableTable = new boolean[joinSpan];
    keyColumnNames = new String[joinSpan][];
    final Table table = persistentClass.getRootTable();
    qualifiedTableNames[0] = table.getQualifiedName(
        factory.getDialect(),
        factory.getSettings().getDefaultCatalogName(),
        factory.getSettings().getDefaultSchemaName()
    );
    isInverseTable[0] = false;
View Full Code Here


      final HashSet<String> schemas = new HashSet<String>();
//      final HashSet<String> catalogs = new HashSet<String>();

      final Iterator<Table> tables = hibernateConfiguration.getTableMappings();
      while ( tables.hasNext() ) {
        final Table table = tables.next();
//        catalogs.add( table.getCatalog() );
        schemas.add( table.getSchema() );
      }

//      final Iterator<IdentifierGenerator> generators = hibernateConfiguration.iterateGenerators( dialect );
//      while ( generators.hasNext() ) {
//        final IdentifierGenerator generator = generators.next();
View Full Code Here

      }
      catch (MappingException e) {
        throw new RecoverableException(e);
      }
    }
    Table matchingTable = columnOwner instanceof PersistentClass ?
        ( (PersistentClass) columnOwner ).getTable() :
        ( (Join) columnOwner ).getTable();
    //check each referenced column
    for (Ejb3JoinColumn ejb3Column : columns) {
      String logicalReferencedColumnName = ejb3Column.getReferencedColumn();
      if ( StringHelper.isNotEmpty( logicalReferencedColumnName ) ) {
        String referencedColumnName;
        try {
          referencedColumnName = mappings.getPhysicalColumnName( logicalReferencedColumnName, matchingTable );
        }
        catch (MappingException me) {
          //rewrite the exception
          throw new MappingException(
              "Unable to find column with logical name: "
                  + logicalReferencedColumnName + " in " + matchingTable.getName()
          );
        }
        noReferencedColumn = false;
        Column refCol = new Column( referencedColumnName );
        boolean contains = idColumns.contains( refCol );
View Full Code Here

    }
   
    HashSet subclassTables = new HashSet();
    iter = persistentClass.getSubclassTableClosureIterator();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      subclassTables.add( table.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      ) );
    }
    subclassSpaces = ArrayHelper.toStringArray(subclassTables);

    subquery = generateSubquery(persistentClass, mapping);

    if ( isMultiTable() ) {
      int idColumnSpan = getIdentifierColumnSpan();
      ArrayList tableNames = new ArrayList();
      ArrayList keyColumns = new ArrayList();
      if ( !isAbstract() ) {
        tableNames.add( tableName );
        keyColumns.add( getIdentifierColumnNames() );
      }
      iter = persistentClass.getSubclassTableClosureIterator();
      while ( iter.hasNext() ) {
        Table tab = ( Table ) iter.next();
        if ( !tab.isAbstractUnionTable() ) {
          String tableName = tab.getQualifiedName(
              factory.getDialect(),
              factory.getSettings().getDefaultCatalogName(),
              factory.getSettings().getDefaultSchemaName()
          );
          tableNames.add( tableName );
          String[] key = new String[idColumnSpan];
          Iterator citer = tab.getPrimaryKey().getColumnIterator();
          for ( int k=0; k<idColumnSpan; k++ ) {
            key[k] = ( ( Column ) citer.next() ).getQuotedName( factory.getDialect() );
          }
          keyColumns.add( key );
        }
View Full Code Here

    }

    HashSet columns = new LinkedHashSet();
    Iterator titer = model.getSubclassTableClosureIterator();
    while ( titer.hasNext() ) {
      Table table = (Table) titer.next();
      if ( !table.isAbstractUnionTable() ) {
        Iterator citer = table.getColumnIterator();
        while ( citer.hasNext() ) columns.add( citer.next() );
      }
    }

    StringBuffer buf = new StringBuffer()
      .append("( ");

    Iterator siter = new JoinedIterator(
      new SingletonIterator(model),
      model.getSubclassIterator()
    );

    while ( siter.hasNext() ) {
      PersistentClass clazz = (PersistentClass) siter.next();
      Table table = clazz.getTable();
      if ( !table.isAbstractUnionTable() ) {
        //TODO: move to .sql package!!
        buf.append("select ");
        Iterator citer = columns.iterator();
        while ( citer.hasNext() ) {
          Column col = (Column) citer.next();
          if ( !table.containsColumn(col) ) {
            int sqlType = col.getSqlTypeCode(mapping);
            buf.append( dialect.getSelectClauseNullString(sqlType) )
              .append(" as ");
          }
          buf.append( col.getName() );
          buf.append(", ");
        }
        buf.append( clazz.getSubclassId() )
          .append(" as clazz_");
        buf.append(" from ")
          .append( table.getQualifiedName(
              dialect,
              settings.getDefaultCatalogName(),
              settings.getDefaultSchemaName()
          ) );
        buf.append(" union ");
View Full Code Here

    }

    if ( dialect.dropConstraints() ) {
      Iterator itr = getTableMappings();
      while ( itr.hasNext() ) {
        Table table = (Table) itr.next();
        if ( table.isPhysicalTable() ) {
          Iterator subItr = table.getForeignKeyIterator();
          while ( subItr.hasNext() ) {
            ForeignKey fk = (ForeignKey) subItr.next();
            if ( fk.isPhysicalConstraint() ) {
              script.add(
                  fk.sqlDropString(
                      dialect,
                      defaultCatalog,
                      defaultSchema
                    )
                );
            }
          }
        }
      }
    }


    Iterator itr = getTableMappings();
    while ( itr.hasNext() ) {

      Table table = (Table) itr.next();
      if ( table.isPhysicalTable() ) {

        /*Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          Index index = (Index) subIter.next();
          if ( !index.isForeignKey() || !dialect.hasImplicitIndexForForeignKey() ) {
            script.add( index.sqlDropString(dialect) );
          }
        }*/

        script.add(
            table.sqlDropString(
                dialect,
                defaultCatalog,
                defaultSchema
              )
          );
 
View Full Code Here

    String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG );
    String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA );

    Iterator iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      if ( table.isPhysicalTable() ) {
        script.add(
            table.sqlCreateString(
                dialect,
                mapping,
                defaultCatalog,
                defaultSchema
              )
          );
        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          script.add( comments.next() );
        }
      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      if ( table.isPhysicalTable() ) {

        if ( !dialect.supportsUniqueConstraintInCreateAlterTable() ) {
          Iterator subIter = table.getUniqueKeyIterator();
          while ( subIter.hasNext() ) {
            UniqueKey uk = (UniqueKey) subIter.next();
            String constraintString = uk.sqlCreateString( dialect, mapping, defaultCatalog, defaultSchema );
            if (constraintString != null) script.add( constraintString );
          }
        }


        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          Index index = (Index) subIter.next();
          script.add(
              index.sqlCreateString(
                  dialect,
                  mapping,
                  defaultCatalog,
                  defaultSchema
                )
            );
        }

        if ( dialect.hasAlterTable() ) {
          subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              script.add(
                  fk.sqlCreateString(
View Full Code Here

    ArrayList<String> script = new ArrayList<String>( 50 );

    Iterator iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      if ( table.isPhysicalTable() ) {
       
        TableMetadata tableInfo = databaseMetadata.getTableMetadata(
            table.getName(),
            ( table.getSchema() == null ) ? defaultSchema : table.getSchema(),
            ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog(),
                table.isQuoted()

          );
        if ( tableInfo == null ) {
          script.add(
              table.sqlCreateString(
                  dialect,
                  mapping,
                  defaultCatalog,
                  defaultSchema
                )
            );
        }
        else {
          Iterator<String> subiter = table.sqlAlterStrings(
              dialect,
              mapping,
              tableInfo,
              defaultCatalog,
              defaultSchema
            );
          while ( subiter.hasNext() ) {
            script.add( subiter.next() );
          }
        }

        Iterator<String> comments = table.sqlCommentStrings( dialect, defaultCatalog, defaultSchema );
        while ( comments.hasNext() ) {
          script.add( comments.next() );
        }

      }
    }

    iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      if ( table.isPhysicalTable() ) {

        TableMetadata tableInfo = databaseMetadata.getTableMetadata(
            table.getName(),
            table.getSchema(),
            table.getCatalog(),
            table.isQuoted()
          );

        if ( dialect.hasAlterTable() ) {
          Iterator subIter = table.getForeignKeyIterator();
          while ( subIter.hasNext() ) {
            ForeignKey fk = (ForeignKey) subIter.next();
            if ( fk.isPhysicalConstraint() ) {
              boolean create = tableInfo == null || (
                  tableInfo.getForeignKeyMetadata( fk ) == null && (
                      //Icky workaround for MySQL bug:
                      !( dialect instanceof MySQLDialect ) ||
                          tableInfo.getIndexMetadata( fk.getName() ) == null
                    )
                );
              if ( create ) {
                script.add(
                    fk.sqlCreateString(
                        dialect,
                        mapping,
                        defaultCatalog,
                        defaultSchema
                      )
                  );
              }
            }
          }
        }

        Iterator subIter = table.getIndexIterator();
        while ( subIter.hasNext() ) {
          final Index index = (Index) subIter.next();
          // Skip if index already exists
          if ( tableInfo != null && StringHelper.isNotEmpty( index.getName() ) ) {
            final IndexMetadata meta = tableInfo.getIndexMetadata( index.getName() );
View Full Code Here

    String defaultCatalog = properties.getProperty( Environment.DEFAULT_CATALOG );
    String defaultSchema = properties.getProperty( Environment.DEFAULT_SCHEMA );
   
    Iterator iter = getTableMappings();
    while ( iter.hasNext() ) {
      Table table = (Table) iter.next();
      if ( table.isPhysicalTable() ) {
       

        TableMetadata tableInfo = databaseMetadata.getTableMetadata(
            table.getName(),
            ( table.getSchema() == null ) ? defaultSchema : table.getSchema(),
            ( table.getCatalog() == null ) ? defaultCatalog : table.getCatalog(),
                table.isQuoted());
        if ( tableInfo == null ) {
          throw new HibernateException( "Missing table: " + table.getName() );
        }
        else {
          table.validateColumns( dialect, mapping, tableInfo );
        }

      }
    }
View Full Code Here

      //the exception was not recoverable after all
      throw ( RuntimeException ) e.getCause();
    }

    for ( Map.Entry<Table, List<UniqueConstraintHolder>> tableListEntry : uniqueConstraintHoldersByTable.entrySet() ) {
      final Table table = tableListEntry.getKey();
      final List<UniqueConstraintHolder> uniqueConstraints = tableListEntry.getValue();
      int uniqueIndexPerTable = 0;
      for ( UniqueConstraintHolder holder : uniqueConstraints ) {
        uniqueIndexPerTable++;
        final String keyName = StringHelper.isEmpty( holder.getName() )
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Table

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.