Package org.hibernate.mapping

Examples of org.hibernate.mapping.UniqueKey


      }
      else if ( "filter".equals( name ) ) {
        parseFilter( subnode, persistentClass, mappings );
      }
      else if ( "natural-id".equals( name ) ) {
        UniqueKey uk = new UniqueKey();
        uk.setName("_UniqueKey");
        uk.setTable(table);
        //by default, natural-ids are "immutable" (constant)
        boolean mutableId = "true".equals( subnode.attributeValue("mutable") );
        createClassProperties(
            subnode,
            persistentClass,
View Full Code Here


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

        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 );
        }


        subIter = table.getIndexIterator();
View Full Code Here

            tableCatalog, table.isQuoted() );

        if (! constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.SKIP )) {
          Iterator uniqueIter = table.getUniqueKeyIterator();
          while ( uniqueIter.hasNext() ) {
            final UniqueKey uniqueKey = (UniqueKey) uniqueIter.next();
            // Skip if index already exists. Most of the time, this
            // won't work since most Dialects use Constraints. However,
            // keep it for the few that do use Indexes.
            if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
              final IndexMetadata meta = tableInfo.getIndexMetadata( uniqueKey.getName() );
              if ( meta != null ) {
                continue;
              }
            }
            String constraintString = uniqueKey.sqlCreateString( dialect, mapping, tableCatalog, tableSchema );
            if ( constraintString != null && !constraintString.isEmpty() )
              if ( constraintMethod.equals( UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) ) {
                String constraintDropString = uniqueKey.sqlDropString( dialect, tableCatalog, tableSchema );
                scripts.add( new SchemaUpdateScript( constraintDropString, true) );
              }
              scripts.add( new SchemaUpdateScript( constraintString, true) );
          }
        }
View Full Code Here

      keyName = Constraint.generateName( "UK_", table, columns );
    }
    keyName = normalizer.normalizeIdentifierQuoting( keyName );
   
    if ( unique ) {
      UniqueKey uk = table.getOrCreateUniqueKey( keyName );
      for ( int i = 0; i < columns.length; i++ ) {
        Column column = columns[i];
        String order = orderings != null ? orderings[i] : null;
        if ( table.containsColumn( column ) ) {
          uk.addColumn( column, order );
          unbound.remove( column );
        }
      }
    }
    else {
View Full Code Here

      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 );
          }
        }

View Full Code Here

  }

  private void buildUniqueKeyFromColumnNames(Table table, String keyName, String[] columnNames) {
    keyName = normalizer.normalizeIdentifierQuoting( keyName );

    UniqueKey uc;
    int size = columnNames.length;
    Column[] columns = new Column[size];
    Set<Column> unbound = new HashSet<Column>();
    Set<Column> unboundNoLogical = new HashSet<Column>();
    for ( int index = 0; index < size; index++ ) {
      final String logicalColumnName = normalizer.normalizeIdentifierQuoting( columnNames[index] );
      try {
        final String columnName = createMappings().getPhysicalColumnName( logicalColumnName, table );
        columns[index] = new Column( columnName );
        unbound.add( columns[index] );
        //column equals and hashcode is based on column name
      }
      catch ( MappingException e ) {
        unboundNoLogical.add( new Column( logicalColumnName ) );
      }
    }
    for ( Column column : columns ) {
      if ( table.containsColumn( column ) ) {
        uc = table.getOrCreateUniqueKey( keyName );
        uc.addColumn( table.getColumn( column ) );
        unbound.remove( column );
      }
    }
    if ( unbound.size() > 0 || unboundNoLogical.size() > 0 ) {
      StringBuilder sb = new StringBuilder( "Unable to create unique key constraint (" );
View Full Code Here

      }
      else if ( "filter".equals( name ) ) {
        parseFilter( subnode, persistentClass, mappings );
      }
      else if ( "natural-id".equals( name ) ) {
        UniqueKey uk = new UniqueKey();
        uk.setName("_UniqueKey");
        uk.setTable(table);
        //by default, natural-ids are "immutable" (constant)
        boolean mutableId = "true".equals( subnode.attributeValue("mutable") );
        createClassProperties(
            subnode,
            persistentClass,
View Full Code Here

      }
      else if ( "filter".equals( name ) ) {
        parseFilter( subnode, persistentClass, mappings );
      }
      else if ( "natural-id".equals( name ) ) {
        UniqueKey uk = new UniqueKey();
        uk.setName("_UniqueKey");
        uk.setTable(table);
        //by default, natural-ids are "immutable" (constant)
        boolean mutableId = "true".equals( subnode.attributeValue("mutable") );
        createClassProperties(
            subnode,
            persistentClass,
View Full Code Here

      }
      else if ( "filter".equals( name ) ) {
        parseFilter( subnode, persistentClass, mappings );
      }
      else if ( "natural-id".equals( name ) ) {
        UniqueKey uk = new UniqueKey();
        uk.setName("_UniqueKey");
        uk.setTable(table);
        //by default, natural-ids are "immutable" (constant)
        boolean mutableId = "true".equals( subnode.attributeValue("mutable") );
        createClassProperties(
            subnode,
            persistentClass,
View Full Code Here

      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 );
          }
        }

View Full Code Here

TOP

Related Classes of org.hibernate.mapping.UniqueKey

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.