Package org.hibernate.mapping

Examples of org.hibernate.mapping.Table$ForeignKeyKey


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


      name = getObjectNameNormalizer().normalizeIdentifierQuoting( name );
      schema = getObjectNameNormalizer().normalizeIdentifierQuoting( schema );
      catalog = getObjectNameNormalizer().normalizeIdentifierQuoting( catalog );

      String key = subselect == null ? Table.qualify( catalog, schema, name ) : subselect;
      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

      String key = subselect == null ? Table.qualify(catalog, schema, name) : subselect;
      if ( tables.containsKey( key ) ) {
        throw new DuplicateMappingException( "table", name );
      }

      Table table = new DenormalizedTable( includedTable );
      table.setAbstract( isAbstract );
      table.setName( name );
      table.setSchema( schema );
      table.setCatalog( catalog );
      table.setSubselect( subselect );

      tables.put( key, table );
      return table;
    }
View Full Code Here

    }

    public String getPhysicalColumnName(String logicalName, Table table) throws MappingException {
      logicalName = logicalName.toLowerCase();
      String finalName = null;
      Table currentTable = table;
      do {
        TableColumnNameBinding binding = ( TableColumnNameBinding ) columnNameBindingPerTable.get( currentTable );
        if ( binding != null ) {
          finalName = ( String ) binding.logicalToPhysical.get( logicalName );
        }
        String key = buildTableNameKey(
            currentTable.getQuotedSchema(), currentTable.getCatalog(), currentTable.getQuotedName()
        );
        TableDescription description = ( TableDescription ) tableNameBinding.get( key );
        if ( description != null ) {
          currentTable = description.denormalizedSupertable;
        }
View Full Code Here

      return finalName;
    }

    public String getLogicalColumnName(String physicalName, Table table) throws MappingException {
      String logical = null;
      Table currentTable = table;
      TableDescription description = null;
      do {
        TableColumnNameBinding binding = ( TableColumnNameBinding ) columnNameBindingPerTable.get( currentTable );
        if ( binding != null ) {
          logical = ( String ) binding.physicalToLogical.get( physicalName );
        }
        String key = buildTableNameKey(
            currentTable.getQuotedSchema(), currentTable.getCatalog(), currentTable.getQuotedName()
        );
        description = ( TableDescription ) tableNameBinding.get( key );
        if ( description != null ) {
          currentTable = description.denormalizedSupertable;
        }
View Full Code Here

    @Override
    public void initializeSchema(Configuration configuration, SessionFactoryImplementor factory) {
      Iterator<Table> tables = configuration.getTableMappings();
      while ( tables.hasNext() ) {
        Table table = tables.next();
        if ( table.isPhysicalTable() ) {
          String tableName = table.getQuotedName();
          // do something with table
          Iterator<Column> columns = table.getColumnIterator();
          while ( columns.hasNext() ) {
            Column column = columns.next();
            String columnName = column.getCanonicalName();
            // do something with column
          }
View Full Code Here

    }

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

    if ( isMultiTable() ) {
      int idColumnSpan = getIdentifierColumnSpan();
      ArrayList<String> tableNames = new ArrayList<String>();
      ArrayList<String[]> keyColumns = new ArrayList<String[]>();
      if ( !isAbstract() ) {
        tableNames.add( tableName );
        keyColumns.add( getIdentifierColumnNames() );
      }
      @SuppressWarnings( "unchecked" )
      Iterator<Table> iter = persistentClass.getSubclassTableClosureIterator();
      while ( iter.hasNext() ) {
        Table tab = 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<Column> citer = tab.getPrimaryKey().getColumnIterator();
          for ( int k = 0; k < idColumnSpan; k++ ) {
            key[k] = citer.next().getQuotedName( factory.getDialect() );
          }
          keyColumns.add( key );
        }
View Full Code Here

    }

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

    if ( isMultiTable() ) {
      int idColumnSpan = getIdentifierColumnSpan();
      ArrayList<String> tableNames = new ArrayList<String>();
      ArrayList<String[]> keyColumns = new ArrayList<String[]>();
      if ( !isAbstract() ) {
        tableNames.add( tableName );
        keyColumns.add( getIdentifierColumnNames() );
      }
      @SuppressWarnings( "unchecked" )
      Iterator<Table> iter = persistentClass.getSubclassTableClosureIterator();
      while ( iter.hasNext() ) {
        Table tab = 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];
          @SuppressWarnings( "unchecked" )
          Iterator<Column> citer = tab.getPrimaryKey().getColumnIterator();
          for ( int k = 0; k < idColumnSpan; k++ ) {
            key[k] = citer.next().getQuotedName( factory.getDialect() );
          }
          keyColumns.add( key );
        }
View Full Code Here

   */
  private void createPersistentClasses(DatabaseCollector collector, Mapping mapping) {
    Map manyToOneCandidates = collector.getOneToManyCandidates();

    for (Iterator iter = mappings.iterateTables(); iter.hasNext();) {
      Table table = (Table) iter.next();
      if(table.getColumnSpan()==0) {
        log.warn("Cannot create persistent class for " + table + " as no columns were found.");
        continue;
      }
      // TODO: this naively just create an entity per table
      // should have an opt-out option to mark some as helper tables, subclasses etc.
      /*if(table.getPrimaryKey()==null || table.getPrimaryKey().getColumnSpan()==0) {
          log.warn("Cannot create persistent class for " + table + " as no primary key was found.");
                continue;
                // TODO: just create one big embedded composite id instead.
            }*/

      if(revengStrategy.isManyToManyTable(table)) {
        log.debug( "Ignoring " + table + " as class since rev.eng. says it is a many-to-many" );
        continue;
      }

       
      RootClass rc = new RootClass();
      TableIdentifier tableIdentifier = TableIdentifier.create(table);
      String className = revengStrategy.tableToClassName( tableIdentifier );
      log.debug("Building entity " + className + " based on " + tableIdentifier);
      rc.setEntityName( className );
      rc.setClassName( className );
      rc.setProxyInterfaceName( rc.getEntityName() ); // TODO: configurable ?
      rc.setLazy(true);

      rc.setMetaAttributes( safeMeta(revengStrategy.tableToMetaAttributes( tableIdentifier )) );


      rc.setDiscriminatorValue( rc.getEntityName() );
      rc.setTable(table);
      try {
        mappings.addClass(rc);
      } catch(DuplicateMappingException dme) {
        // TODO: detect this and generate a "permutation" of it ?
        PersistentClass class1 = mappings.getClass(dme.getName());
        Table table2 = class1.getTable();
        throw new JDBCBinderException("Duplicate class name '" + rc.getEntityName() + "' generated for '" + table + "'. Same name where generated for '" + table2 + "'");
      }
      mappings.addImport( rc.getEntityName(), rc.getEntityName() );

      Set processed = new HashSet();
View Full Code Here

   * @param table
   * @param object
   */
  private Property bindOneToMany(PersistentClass rc, ForeignKey foreignKey, Set processed, Mapping mapping) {

    Table collectionTable = foreignKey.getTable();

    Collection collection = new org.hibernate.mapping.Set(rc); // MASTER TODO: allow overriding collection type

    collection.setCollectionTable(collectionTable); // CHILD+

View Full Code Here

TOP

Related Classes of org.hibernate.mapping.Table$ForeignKeyKey

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.