Package org.hibernate.mapping

Examples of org.hibernate.mapping.IdGenerator


      return getGenerator( name, null );
    }

    public IdGenerator getGenerator(String name, Map<String, IdGenerator> localGenerators) {
      if ( localGenerators != null ) {
        IdGenerator result = localGenerators.get( name );
        if ( result != null ) {
          return result;
        }
      }
      return namedGenerators.get( name );
View Full Code Here


      return namedGenerators.get( name );
    }

    public void addGenerator(IdGenerator generator) {
      if ( !defaultNamedGenerators.contains( generator.getName() ) ) {
        IdGenerator old = namedGenerators.put( generator.getName(), generator );
        if ( old != null ) {
          LOG.duplicateGeneratorName( old.getName() );
        }
      }
    }
View Full Code Here

      return getGenerator( name, null );
    }

    public IdGenerator getGenerator(String name, Map<String, IdGenerator> localGenerators) {
      if ( localGenerators != null ) {
        IdGenerator result = localGenerators.get( name );
        if ( result != null ) {
          return result;
        }
      }
      return namedGenerators.get( name );
View Full Code Here

      return namedGenerators.get( name );
    }

    public void addGenerator(IdGenerator generator) {
      if ( !defaultNamedGenerators.contains( generator.getName() ) ) {
        IdGenerator old = namedGenerators.put( generator.getName(), generator );
        if ( old != null ) {
          log.warn( "duplicate generator name {}", old.getName() );
        }
      }
    }
View Full Code Here

      return getGenerator( name, null );
    }

    public IdGenerator getGenerator(String name, Map<String, IdGenerator> localGenerators) {
      if ( localGenerators != null ) {
        IdGenerator result = localGenerators.get( name );
        if ( result != null ) {
          return result;
        }
      }
      return namedGenerators.get( name );
View Full Code Here

      return namedGenerators.get( name );
    }

    public void addGenerator(IdGenerator generator) {
      if ( !defaultNamedGenerators.contains( generator.getName() ) ) {
        IdGenerator old = namedGenerators.put( generator.getName(), generator );
                if (old != null) LOG.duplicateGeneratorName(old.getName());
      }
    }
View Full Code Here

    {
      List<SequenceGenerator> anns = ( List<SequenceGenerator> ) defaults.get( SequenceGenerator.class );
      if ( anns != null ) {
        for ( SequenceGenerator ann : anns ) {
          IdGenerator idGen = buildIdGenerator( ann, mappings );
          if ( idGen != null ) {
            mappings.addDefaultGenerator( idGen );
          }
        }
      }
    }
    {
      List<TableGenerator> anns = ( List<TableGenerator> ) defaults.get( TableGenerator.class );
      if ( anns != null ) {
        for ( TableGenerator ann : anns ) {
          IdGenerator idGen = buildIdGenerator( ann, mappings );
          if ( idGen != null ) {
            mappings.addDefaultGenerator( idGen );
          }
        }
      }
View Full Code Here

      LOG.packageNotFound( packageName );
      return;
    }
    if ( pckg.isAnnotationPresent( SequenceGenerator.class ) ) {
      SequenceGenerator ann = pckg.getAnnotation( SequenceGenerator.class );
      IdGenerator idGen = buildIdGenerator( ann, mappings );
      mappings.addGenerator( idGen );
      if ( LOG.isTraceEnabled() ) {
        LOG.tracev( "Add sequence generator with name: {0}", idGen.getName() );
      }
    }
    if ( pckg.isAnnotationPresent( TableGenerator.class ) ) {
      TableGenerator ann = pckg.getAnnotation( TableGenerator.class );
      IdGenerator idGen = buildIdGenerator( ann, mappings );
      mappings.addGenerator( idGen );

    }
    bindGenericGenerators( pckg, mappings );
    bindQueries( pckg, mappings );
View Full Code Here

      }
    }
  }

  private static void bindGenericGenerator(GenericGenerator def, Mappings mappings) {
    IdGenerator idGen = buildIdGenerator( def, mappings );
    mappings.addGenerator( idGen );
  }
View Full Code Here

      QueryBinder.bindNamedStoredProcedureQuery( annotation, mappings, isDefault );
    }
  }

  private static IdGenerator buildIdGenerator(java.lang.annotation.Annotation ann, Mappings mappings) {
    IdGenerator idGen = new IdGenerator();
    if ( mappings.getSchemaName() != null ) {
      idGen.addParam( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() );
    }
    if ( mappings.getCatalogName() != null ) {
      idGen.addParam( PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName() );
    }
    final boolean useNewGeneratorMappings = mappings.useNewGeneratorMappings();
    if ( ann == null ) {
      idGen = null;
    }
    else if ( ann instanceof TableGenerator ) {
      TableGenerator tabGen = ( TableGenerator ) ann;
      idGen.setName( tabGen.name() );
      if ( useNewGeneratorMappings ) {
        idGen.setIdentifierGeneratorStrategy( org.hibernate.id.enhanced.TableGenerator.class.getName() );
        idGen.addParam( org.hibernate.id.enhanced.TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" );

        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.catalog() ) ) {
          idGen.addParam( PersistentIdentifierGenerator.CATALOG, tabGen.catalog() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.schema() ) ) {
          idGen.addParam( PersistentIdentifierGenerator.SCHEMA, tabGen.schema() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.table() ) ) {
          idGen.addParam( org.hibernate.id.enhanced.TableGenerator.TABLE_PARAM, tabGen.table() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnName() ) ) {
          idGen.addParam(
              org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM, tabGen.pkColumnName()
          );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnValue() ) ) {
          idGen.addParam(
              org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM, tabGen.pkColumnValue()
          );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.valueColumnName() ) ) {
          idGen.addParam(
              org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM, tabGen.valueColumnName()
          );
        }
        idGen.addParam(
            org.hibernate.id.enhanced.TableGenerator.INCREMENT_PARAM,
            String.valueOf( tabGen.allocationSize() )
        );
        // See comment on HHH-4884 wrt initialValue.  Basically initialValue is really the stated value + 1
        idGen.addParam(
            org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM,
            String.valueOf( tabGen.initialValue() + 1 )
        );
                if (tabGen.uniqueConstraints() != null && tabGen.uniqueConstraints().length > 0) LOG.warn(tabGen.name());
      }
      else {
        idGen.setIdentifierGeneratorStrategy( MultipleHiLoPerTableGenerator.class.getName() );

        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.table() ) ) {
          idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tabGen.table() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.catalog() ) ) {
          idGen.addParam( PersistentIdentifierGenerator.CATALOG, tabGen.catalog() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.schema() ) ) {
          idGen.addParam( PersistentIdentifierGenerator.SCHEMA, tabGen.schema() );
        }
        //FIXME implement uniqueconstrains
                if (tabGen.uniqueConstraints() != null && tabGen.uniqueConstraints().length > 0) LOG.ignoringTableGeneratorConstraints(tabGen.name());

        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnName() ) ) {
          idGen.addParam( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, tabGen.pkColumnName() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.valueColumnName() ) ) {
          idGen.addParam( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, tabGen.valueColumnName() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnValue() ) ) {
          idGen.addParam( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, tabGen.pkColumnValue() );
        }
        idGen.addParam( TableHiLoGenerator.MAX_LO, String.valueOf( tabGen.allocationSize() - 1 ) );
      }
      if ( LOG.isTraceEnabled() ) {
        LOG.tracev( "Add table generator with name: {0}", idGen.getName() );
      }
    }
    else if ( ann instanceof SequenceGenerator ) {
      SequenceGenerator seqGen = ( SequenceGenerator ) ann;
      idGen.setName( seqGen.name() );
      if ( useNewGeneratorMappings ) {
        idGen.setIdentifierGeneratorStrategy( SequenceStyleGenerator.class.getName() );

        if ( !BinderHelper.isEmptyAnnotationValue( seqGen.catalog() ) ) {
          idGen.addParam( PersistentIdentifierGenerator.CATALOG, seqGen.catalog() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( seqGen.schema() ) ) {
          idGen.addParam( PersistentIdentifierGenerator.SCHEMA, seqGen.schema() );
        }
        if ( !BinderHelper.isEmptyAnnotationValue( seqGen.sequenceName() ) ) {
          idGen.addParam( SequenceStyleGenerator.SEQUENCE_PARAM, seqGen.sequenceName() );
        }
        idGen.addParam( SequenceStyleGenerator.INCREMENT_PARAM, String.valueOf( seqGen.allocationSize() ) );
        idGen.addParam( SequenceStyleGenerator.INITIAL_PARAM, String.valueOf( seqGen.initialValue() ) );
      }
      else {
        idGen.setIdentifierGeneratorStrategy( "seqhilo" );

        if ( !BinderHelper.isEmptyAnnotationValue( seqGen.sequenceName() ) ) {
          idGen.addParam( org.hibernate.id.SequenceGenerator.SEQUENCE, seqGen.sequenceName() );
        }
        //FIXME: work on initialValue() through SequenceGenerator.PARAMETERS
        //    steve : or just use o.h.id.enhanced.SequenceStyleGenerator
        if ( seqGen.initialValue() != 1 ) {
          LOG.unsupportedInitialValue( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS );
        }
        idGen.addParam( SequenceHiLoGenerator.MAX_LO, String.valueOf( seqGen.allocationSize() - 1 ) );
        if ( LOG.isTraceEnabled() ) {
          LOG.tracev( "Add sequence generator with name: {0}", idGen.getName() );
        }
      }
    }
    else if ( ann instanceof GenericGenerator ) {
      GenericGenerator genGen = ( GenericGenerator ) ann;
      idGen.setName( genGen.name() );
      idGen.setIdentifierGeneratorStrategy( genGen.strategy() );
      Parameter[] params = genGen.parameters();
      for ( Parameter parameter : params ) {
        idGen.addParam( parameter.name(), parameter.value() );
      }
      if ( LOG.isTraceEnabled() ) {
        LOG.tracev( "Add generic generator with name: {0}", idGen.getName() );
      }
    }
    else {
      throw new AssertionFailure( "Unknown Generator annotation: " + ann );
    }
View Full Code Here

TOP

Related Classes of org.hibernate.mapping.IdGenerator

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.