Package org.hibernate.mapping

Examples of org.hibernate.mapping.IdGenerator


      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.bindNativeQueries( ann, mappings );
    }
  }

  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

    HashMap<String, IdGenerator> generators = new HashMap<String, IdGenerator>();
    TableGenerator tabGen = annElt.getAnnotation( TableGenerator.class );
    SequenceGenerator seqGen = annElt.getAnnotation( SequenceGenerator.class );
    GenericGenerator genGen = annElt.getAnnotation( GenericGenerator.class );
    if ( tabGen != null ) {
      IdGenerator idGen = buildIdGenerator( tabGen, mappings );
      generators.put( idGen.getName(), idGen );
    }
    if ( seqGen != null ) {
      IdGenerator idGen = buildIdGenerator( seqGen, mappings );
      generators.put( idGen.getName(), idGen );
    }
    if ( genGen != null ) {
      IdGenerator idGen = buildIdGenerator( genGen, mappings );
      generators.put( idGen.getName(), idGen );
    }
    return generators;
  }
View Full Code Here

    Map defaults = mappings.getReflectionManager().getDefaults();
    {
      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.warn( "Package not found or wo package-info.java: " + packageName );
      return;
    }
    if ( pckg.isAnnotationPresent( SequenceGenerator.class ) ) {
      SequenceGenerator ann = pckg.getAnnotation( SequenceGenerator.class );
      IdGenerator idGen = buildIdGenerator( ann, mappings );
      mappings.addGenerator( idGen );
      log.debug( "Add sequence generator with name: " + idGen.getName() );
    }
    if ( pckg.isAnnotationPresent( TableGenerator.class ) ) {
      TableGenerator ann = pckg.getAnnotation( TableGenerator.class );
      IdGenerator idGen = buildIdGenerator( ann, mappings );
      mappings.addGenerator( idGen );

    }
    if ( pckg.isAnnotationPresent( GenericGenerator.class ) ) {
      GenericGenerator ann = pckg.getAnnotation( GenericGenerator.class );
      IdGenerator idGen = buildIdGenerator( ann, mappings );
      mappings.addGenerator( idGen );
    }
    bindQueries( pckg, mappings );
    bindFilterDefs( pckg, mappings );
    bindTypeDefs( pckg, mappings );
View Full Code Here

      QueryBinder.bindNativeQueries( ann, mappings );
    }
  }

  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() );
    }
    if ( ann == null ) {
      idGen = null;
    }
    else if ( ann instanceof TableGenerator ) {
      TableGenerator tabGen = (TableGenerator) ann;
      idGen.setName( tabGen.name() );
      idGen.setIdentifierGeneratorStrategy( MultipleHiLoPerTableGenerator.class.getName() );

      if ( ! BinderHelper.isDefault( tabGen.table() ) ) {
        idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tabGen.table() );
      }
      if ( ! BinderHelper.isDefault( tabGen.catalog() ) ) {
        idGen.addParam( MultipleHiLoPerTableGenerator.CATALOG, tabGen.catalog() );
      }
      if ( ! BinderHelper.isDefault( tabGen.schema() ) ) {
        idGen.addParam( MultipleHiLoPerTableGenerator.SCHEMA, tabGen.schema() );
      }
      //FIXME implements uniqueconstrains

      if ( ! BinderHelper.isDefault( tabGen.pkColumnName() ) ) {
        idGen.addParam( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, tabGen.pkColumnName() );
      }
      if ( ! BinderHelper.isDefault( tabGen.valueColumnName() ) ) {
        idGen.addParam( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, tabGen.valueColumnName() );
      }
      if ( ! BinderHelper.isDefault( tabGen.pkColumnValue() ) ) {
        idGen.addParam( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, tabGen.pkColumnValue() );
      }
      idGen.addParam( TableHiLoGenerator.MAX_LO, String.valueOf( tabGen.allocationSize() - 1 ) );
      log.debug( "Add table generator with name: " + idGen.getName() );
    }
    else if ( ann instanceof SequenceGenerator ) {
      SequenceGenerator seqGen = (SequenceGenerator) ann;
      idGen.setName( seqGen.name() );
      idGen.setIdentifierGeneratorStrategy( "seqhilo" );

      if ( ! BinderHelper.isDefault( seqGen.sequenceName() ) ) {
        idGen.addParam( org.hibernate.id.SequenceGenerator.SEQUENCE, seqGen.sequenceName() );
      }
      //FIXME: work on initialValue() through SequenceGenerator.PARAMETERS
      if ( seqGen.initialValue() != 1 ) {
        log.warn(
            "Hibernate does not support SequenceGenerator.initialValue()"
        );
      }
      idGen.addParam( SequenceHiLoGenerator.MAX_LO, String.valueOf( seqGen.allocationSize() - 1 ) );
      log.debug( "Add sequence generator with name: " + 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() );
      }
      log.debug( "Add generic generator with name: " + idGen.getName() );
    }
    else {
      throw new AssertionFailure( "Unknown Generator annotation: " + ann );
    }
    return idGen;
View Full Code Here

        if ( isOverridden ) {
          final PropertyData mapsIdProperty = BinderHelper.getPropertyOverriddenByMapperOrMapsId(
              isId, propertyHolder, property.getName(), mappings
          );
          Map<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
          final IdGenerator foreignGenerator = new IdGenerator();
          foreignGenerator.setIdentifierGeneratorStrategy( "assigned" );
          foreignGenerator.setName( "Hibernate-local--foreign generator" );
          foreignGenerator.setIdentifierGeneratorStrategy( "foreign" );
          foreignGenerator.addParam( "property", mapsIdProperty.getPropertyName() );
          localGenerators.put( foreignGenerator.getName(), foreignGenerator );

          BinderHelper.makeIdGenerator(
              ( SimpleValue ) propertyBinder.getValue(),
              foreignGenerator.getIdentifierGeneratorStrategy(),
              foreignGenerator.getName(),
              mappings,
              localGenerators
          );
        }
        if ( isId ) {
View Full Code Here

    HashMap<String, IdGenerator> generators = new HashMap<String, IdGenerator>();
    TableGenerator tabGen = annElt.getAnnotation( TableGenerator.class );
    SequenceGenerator seqGen = annElt.getAnnotation( SequenceGenerator.class );
    GenericGenerator genGen = annElt.getAnnotation( GenericGenerator.class );
    if ( tabGen != null ) {
      IdGenerator idGen = buildIdGenerator( tabGen, mappings );
      generators.put( idGen.getName(), idGen );
    }
    if ( seqGen != null ) {
      IdGenerator idGen = buildIdGenerator( seqGen, mappings );
      generators.put( idGen.getName(), idGen );
    }
    if ( genGen != null ) {
      IdGenerator idGen = buildIdGenerator( genGen, mappings );
      generators.put( idGen.getName(), idGen );
    }
    return generators;
  }
View Full Code Here

        if ( isOverridden ) {
          final PropertyData mapsIdProperty = BinderHelper.getPropertyOverriddenByMapperOrMapsId(
              isId, propertyHolder, property.getName(), mappings
          );
          Map<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
          final IdGenerator foreignGenerator = new IdGenerator();
          foreignGenerator.setIdentifierGeneratorStrategy( "assigned" );
          foreignGenerator.setName( "Hibernate-local--foreign generator" );
          foreignGenerator.setIdentifierGeneratorStrategy( "foreign" );
          foreignGenerator.addParam( "property", mapsIdProperty.getPropertyName() );
          localGenerators.put( foreignGenerator.getName(), foreignGenerator );

          BinderHelper.makeIdGenerator(
              ( SimpleValue ) propertyBinder.getValue(),
              foreignGenerator.getIdentifierGeneratorStrategy(),
              foreignGenerator.getName(),
              mappings,
              localGenerators
          );
        }
        if ( isId ) {
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.