Package org.hibernate.mapping

Examples of org.hibernate.mapping.Table


      boolean isAbstract
  ) {
        String key = subselect==null ?
      Table.qualify(catalog, schema, name) :
      subselect;
    Table table = (Table) tables.get(key);

    if (table == null) {
      table = new Table();
      table.setAbstract(isAbstract);
      table.setName(name);
      table.setSchema(schema);
      table.setCatalog(catalog);
      table.setSubselect(subselect);
      tables.put(key, table);
    }
    else {
      if (!isAbstract) table.setAbstract(false);
    }

    return table;
  }
View Full Code Here


    ArrayList keyColumns = new ArrayList();
    ArrayList cascadeDeletes = new ArrayList();
    Iterator titer = persistentClass.getTableClosureIterator();
    Iterator kiter = persistentClass.getKeyClosureIterator();
    while ( titer.hasNext() ) {
      Table tab = (Table) titer.next();
      KeyValue key = (KeyValue) kiter.next();
      String tabname = tab.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      tables.add(tabname);
      String[] keyCols = new String[idColumnSpan];
      Iterator citer = key.getColumnIterator();
      for ( int k=0; k<idColumnSpan; k++ ) {
        keyCols[k] = ( (Column) citer.next() ).getQuotedName( factory.getDialect() );
      }
      keyColumns.add(keyCols);
      cascadeDeletes.add( new Boolean( key.isCascadeDeleteEnabled() && factory.getDialect().supportsCascadeDelete() ) );
    }
    naturalOrderTableNames = ArrayHelper.toStringArray(tables);
    naturalOrderTableKeyColumns = ArrayHelper.to2DStringArray(keyColumns);
    naturalOrderCascadeDeleteEnabled = ArrayHelper.toBooleanArray(cascadeDeletes);

    ArrayList subtables = new ArrayList();
    ArrayList isConcretes = new ArrayList();
    keyColumns = new ArrayList();
    titer = persistentClass.getSubclassTableClosureIterator();
    while ( titer.hasNext() ) {
      Table tab = (Table) titer.next();
      isConcretes.add( new Boolean( persistentClass.isClassOrSuperclassTable(tab) ) );
      String tabname = tab.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      subtables.add(tabname);
      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);
    }
    subclassTableNameClosure = ArrayHelper.toStringArray(subtables);
    subclassTableKeyColumnClosure = ArrayHelper.to2DStringArray(keyColumns);
    isClassOrSuperclassTable = ArrayHelper.toBooleanArray(isConcretes);

    constraintOrderedTableNames = new String[subclassTableNameClosure.length];
    constraintOrderedKeyColumnNames = new String[subclassTableNameClosure.length][];
    int currentPosition = 0;
    for ( int i = subclassTableNameClosure.length - 1; i >= 0 ; i--, currentPosition++ ) {
      constraintOrderedTableNames[currentPosition] = subclassTableNameClosure[i];
      constraintOrderedKeyColumnNames[currentPosition] = subclassTableKeyColumnClosure[i];
    }

    tableSpan = naturalOrderTableNames.length;
    tableNames = reverse(naturalOrderTableNames);
    tableKeyColumns = reverse(naturalOrderTableKeyColumns);
    reverse(subclassTableNameClosure, tableSpan);
    reverse(subclassTableKeyColumnClosure, tableSpan);

    spaces = ArrayHelper.join(
        tableNames,
        ArrayHelper.toStringArray( persistentClass.getSynchronizedTables() )
    );

    // Custom sql
    customSQLInsert = new String[tableSpan];
    customSQLUpdate = new String[tableSpan];
    customSQLDelete = new String[tableSpan];
    insertCallable = new boolean[tableSpan];
    updateCallable = new boolean[tableSpan];
    deleteCallable = new boolean[tableSpan];
    insertResultCheckStyles = new ExecuteUpdateResultCheckStyle[tableSpan];
    updateResultCheckStyles = new ExecuteUpdateResultCheckStyle[tableSpan];
    deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[tableSpan];

    PersistentClass pc = persistentClass;
    int jk = tableSpan-1;
    while (pc!=null) {
      customSQLInsert[jk] = pc.getCustomSQLInsert();
      insertCallable[jk] = customSQLInsert[jk] != null && pc.isCustomInsertCallable();
      insertResultCheckStyles[jk] = pc.getCustomSQLInsertCheckStyle() == null
                                    ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[jk], insertCallable[jk] )
                                      : pc.getCustomSQLInsertCheckStyle();
      customSQLUpdate[jk] = pc.getCustomSQLUpdate();
      updateCallable[jk] = customSQLUpdate[jk] != null && pc.isCustomUpdateCallable();
      updateResultCheckStyles[jk] = pc.getCustomSQLUpdateCheckStyle() == null
                                    ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[jk], updateCallable[jk] )
                                      : pc.getCustomSQLUpdateCheckStyle();
      customSQLDelete[jk] = pc.getCustomSQLDelete();
      deleteCallable[jk] = customSQLDelete[jk] != null && pc.isCustomDeleteCallable();
      deleteResultCheckStyles[jk] = pc.getCustomSQLDeleteCheckStyle() == null
                                    ? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[jk], deleteCallable[jk] )
                                      : pc.getCustomSQLDeleteCheckStyle();
      jk--;
      pc = pc.getSuperclass();
    }
    if ( jk != -1 ) {
      throw new AssertionFailure( "Tablespan does not match height of joined-subclass hiearchy." );
    }

    // PROPERTIES

    int hydrateSpan = getPropertySpan();
    naturalOrderPropertyTableNumbers = new int[hydrateSpan];
    propertyTableNumbers = new int[hydrateSpan];
    Iterator iter = persistentClass.getPropertyClosureIterator();
    int i=0;
    while( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      String tabname = prop.getValue().getTable().getQualifiedName(
        factory.getDialect(),
        factory.getSettings().getDefaultCatalogName(),
        factory.getSettings().getDefaultSchemaName()
      );
      propertyTableNumbers[i] = getTableId(tabname, tableNames);
      naturalOrderPropertyTableNumbers[i] = getTableId(tabname, naturalOrderTableNames);
      i++;
    }

    // subclass closure properties

    //TODO: code duplication with SingleTableEntityPersister

    ArrayList columnTableNumbers = new ArrayList();
    ArrayList formulaTableNumbers = new ArrayList();
    ArrayList propTableNumbers = new ArrayList();

    iter = persistentClass.getSubclassPropertyClosureIterator();
    while ( iter.hasNext() ) {
      Property prop = (Property) iter.next();
      Table tab = prop.getValue().getTable();
      String tabname = tab.getQualifiedName(
          factory.getDialect(),
          factory.getSettings().getDefaultCatalogName(),
          factory.getSettings().getDefaultSchemaName()
      );
      Integer tabnum = new Integer( getTableId(tabname, subclassTableNameClosure) );
View Full Code Here

        }
      }
     
      Iterator tables = foundTables.iterator(); // not dbs.iterateTables() to avoid "double-read" of columns etc.
      while ( tables.hasNext() ) {
        Table table = (Table) tables.next();
        processBasicColumns(table, progress);
        processPrimaryKey(dbs, table);
        if(hasIndices.contains(table)) {
          processIndices(table);
        }
View Full Code Here

   * @return
   */
  private Map resolveForeignKeys(DatabaseCollector dbs, Iterator tables, ProgressListener progress) {
    List fks = new ArrayList();
    while ( tables.hasNext() ) {
      Table table = (Table) tables.next();
      // Done here after the basic process of collections as we might not have touched
      // all referenced tables (this ensure the columns are the same instances througout the basic JDBC derived model.
      // after this stage it should be "ok" to divert from keeping columns in sync as it can be required if the same
      //column is used with different aliases in the ORM mapping.
      ForeignKeysInfo foreignKeys = processForeignKeys(dbs, table, progress);
View Full Code Here

        String fkColumnName = (String) exportedKeyRs.get("FKCOLUMN_NAME");
        String pkColumnName = (String) exportedKeyRs.get("PKCOLUMN_NAME");
        String fkName = (String) exportedKeyRs.get("FK_NAME");
        short keySeq = ((Short)exportedKeyRs.get("KEY_SEQ")).shortValue();
               
        Table fkTable = dbs.getTable(fkSchema, fkCatalog, fkTableName);
        if(fkTable==null) {
          //  filter out stuff we don't have tables for!
          log.debug("Foreign key " + fkName + " references unknown or filtered table " + Table.qualify(fkCatalog, fkSchema, fkTableName) );
          continue;
        } else {
          log.debug("Foreign key " + fkName);
        }
       
        // TODO: if there is a relation to a column which is not a pk
        //       then handle it as a property-ref
       
        if (keySeq == 0) {
          bogusFkName++;
        }
       
        if (fkName == null) {
          // somehow reuse hibernates name generator ?
          fkName = Short.toString(bogusFkName);
        }
        //Table fkTable = mappings.addTable(fkSchema, fkCatalog, fkTableName, null, false);
       
       
        List depColumns =  (List) dependentColumns.get(fkName);
        if (depColumns == null) {
          depColumns = new ArrayList();
          dependentColumns.put(fkName,depColumns);
          dependentTables.put(fkName, fkTable);
        }
        else {
          Object previousTable = dependentTables.get(fkName);
          if(fkTable != previousTable) {
            throw new JDBCBinderException("Foreign key name (" + fkName + ") mapped to different tables! previous: " + previousTable + " current:" + fkTable);
          }
        }
       
        Column column = new Column(fkColumnName);
        Column existingColumn = fkTable.getColumn(column);
        column = existingColumn==null ? column : existingColumn;
       
        depColumns.add(column);
       
        List primColumns = (List) referencedColumns.get(fkName);
        if (primColumns == null) {
          primColumns = new ArrayList();
          referencedColumns.put(fkName,primColumns);         
        }
       
        Column refColumn = new Column(pkColumnName);
        existingColumn = referencedTable.getColumn(refColumn);
        refColumn = existingColumn==null?refColumn:existingColumn;
       
        primColumns.add(refColumn);
       
      }
    }
        finally {
          try {
            if(exportedKeyIterator!=null) {
              getMetaDataDialect().close(exportedKeyIterator);
            }
          } catch(JDBCException se) {
            log.warn("Exception while closing result set for foreign key meta data",se);
          }
        }
        } catch(JDBCException se) {
          //throw sec.convert(se, "Exception while reading foreign keys for " + referencedTable, null);
          log.warn("Exception while reading foreign keys for " + referencedTable + " [" + se.toString() + "]", se);
          // sybase (and possibly others has issues with exportedkeys) see HBX-411
          // we continue after this to allow user provided keys to be added.
        }
       
        List userForeignKeys = revengStrategy.getForeignKeys(TableIdentifier.create(referencedTable));
        if(userForeignKeys!=null) {
          Iterator iterator = userForeignKeys.iterator();
          while ( iterator.hasNext() ) {
            ForeignKey element = (ForeignKey) iterator.next();
           
            if(!equalTable(referencedTable, element.getReferencedTable() ) ) {
              log.debug("Referenced table " + element.getReferencedTable().getName() + " is not " +  referencedTable + ". Ignoring userdefined foreign key " + element );
              continue; // skip non related foreign keys
            }
           
            String userfkName = element.getName();           
            Table userfkTable = element.getTable();
           
            List userColumns = element.getColumns();
            List userrefColumns = element.getReferencedColumns();
           
            Table deptable = (Table) dependentTables.get(userfkName);
            if(deptable!=null) { // foreign key already defined!?
              throw new MappingException("Foreign key " + userfkName + " already defined in the database!");
            }
           
            deptable = dbs.getTable(userfkTable.getSchema(), userfkTable.getCatalog(), userfkTable.getName() );
            if(deptable==null) {
          //  filter out stuff we don't have tables for!
          log.debug("User defined foreign key " + userfkName + " references unknown or filtered table " + TableIdentifier.create(userfkTable) );
          continue;             
            }
           
            dependentTables.put(userfkName, deptable);
           
            List depColumns = new ArrayList(userColumns.size() );
            Iterator colIterator = userColumns.iterator();
            while(colIterator.hasNext() ) {
              Column jdbcColumn = (Column) colIterator.next();
              Column column = new Column(jdbcColumn.getName() );
            Column existingColumn = deptable.getColumn(column);
            column = existingColumn==null ? column : existingColumn;
            depColumns.add(column);
            }
           
            List refColumns = new ArrayList(userrefColumns.size() );
View Full Code Here

            if(catalogName!=null && catalogName.trim().length()==0) {
              catalogName=null;
            }
            log.debug("Adding table " + tableName + " of type " + tableType);
            progress.startSubTask("Found " + tableName);
            Table table = dbs.addTable(getSchemaForModel(schemaName), getCatalogForModel(catalogName), tableName);
            table.setComment(comment);
            if(tableType.equalsIgnoreCase("TABLE")) {
              hasIndices.add(table);
            }
            processedTables.add( table );
          }
View Full Code Here

      Map oneToManyCandidates = new HashMap();
          Iterator iterator = dependentTables.entrySet().iterator();
      while (iterator.hasNext() ) {
        Map.Entry entry = (Map.Entry) iterator.next();
        String fkName = (String) entry.getKey();
        Table fkTable = (Table) entry.getValue();     
        List columns = (List) dependentColumns.get(fkName);
        List refColumns = (List) referencedColumns.get(fkName);
       
        String className = revengStrategy.tableToClassName(TableIdentifier.create(referencedTable) );

        ForeignKey key = fkTable.createForeignKey(fkName, columns, className, refColumns);     
        key.setReferencedTable(referencedTable);

        addToMultiMap(oneToManyCandidates, className, key);       
      }
      // map<className, foreignkey>
View Full Code Here

    return clazz.getIdentifierProperty();
  }

  public String generateAnnTableUniqueConstraint() {
    if ( ! ( clazz instanceof Subclass ) ) {
      Table table = clazz.getTable();
      return generateAnnTableUniqueConstraint( table );
    }
    return "";
  }
View Full Code Here

        }
        annotation.append(ab.getResult());
        if (mappedBy == null) {
          annotation.append("\n    @");
          annotation.append( importType( "javax.persistence.JoinTable") ).append( "(name=\"" );
          Table table = collection.getCollectionTable();

          annotation.append( table.getName() );
          annotation.append( "\"" );
          if ( StringHelper.isNotEmpty( table.getSchema() ) ) {
            annotation.append(", schema=\"").append( table.getSchema() ).append("\"");
          }
          if ( StringHelper.isNotEmpty( table.getCatalog() ) ) {
            annotation.append(", catalog=\"").append( table.getCatalog() ).append("\"");
          }
          String uniqueConstraint = generateAnnTableUniqueConstraint(table);
          if ( uniqueConstraint.length() > 0 ) {
            annotation.append(", uniqueConstraints=").append(uniqueConstraint);
          }
View Full Code Here

        }

        Iterator tablesIter = cfg.getTableMappings();
       
        while (tablesIter.hasNext() ) {
          Table table = (Table) tablesIter.next();
         
          if(!table.isPhysicalTable()) {
            continue;
          }
            tables.add(table);

            StringBuffer sb = new StringBuffer();

            String catalog = table.getCatalog();
            if (catalog == null) {
                catalog = defaultCatalog;
            }
            if (catalog != null) {
                sb.append(catalog + ".");
            }

            String schema = table.getSchema();
            if (schema == null) {
                schema = defaultSchema;
            }

            sb.append(schema);

            String qualSchemaName = sb.toString();

            tableSchemaNames.put(table, qualSchemaName);

            List tableList = (List) tablesBySchema.get(qualSchemaName);
            if (tableList == null) {
                tableList = new ArrayList();
                tablesBySchema.put(qualSchemaName, tableList);
            }
            tableList.add(table);

            Iterator columns = table.getColumnIterator();
            while (columns.hasNext() ) {
                Column column = (Column) columns.next();
                String columnFQN = getQualifiedColumnName(table, column);
                List values = (List) valuesByColumn.get(columnFQN);
                if (values == null) {
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.