Examples of IdGenerator


Examples of org.hibernate.mapping.IdGenerator

      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

Examples of org.hibernate.mapping.IdGenerator

        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

Examples of org.hibernate.mapping.IdGenerator

    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

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

Examples of org.hibernate.mapping.IdGenerator

      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

Examples of org.hibernate.mapping.IdGenerator

    // YUCK!  but cannot think of a clean way to do this given the string-config based scheme
    params.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, mappings.getObjectNameNormalizer() );

    if ( !isEmptyAnnotationValue( generatorName ) ) {
      //we have a named generator
      IdGenerator gen = mappings.getGenerator( generatorName, localGenerators );
      if ( gen == null ) {
        throw new AnnotationException( "Unknown Id.generator: " + generatorName );
      }
      //This is quite vague in the spec but a generator could override the generate choice
      String identifierGeneratorStrategy = gen.getIdentifierGeneratorStrategy();
      //yuk! this is a hack not to override 'AUTO' even if generator is set
      final boolean avoidOverriding =
          identifierGeneratorStrategy.equals( "identity" )
              || identifierGeneratorStrategy.equals( "seqhilo" )
              || identifierGeneratorStrategy.equals( MultipleHiLoPerTableGenerator.class.getName() );
      if ( generatorType == null || !avoidOverriding ) {
        id.setIdentifierGeneratorStrategy( identifierGeneratorStrategy );
      }
      //checkIfMatchingGenerator(gen, generatorType, generatorName);
      Iterator genParams = gen.getParams().entrySet().iterator();
      while ( genParams.hasNext() ) {
        Map.Entry elt = (Map.Entry) genParams.next();
        params.setProperty( (String) elt.getKey(), (String) elt.getValue() );
      }
    }
View Full Code Here

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

Examples of org.hibernate.mapping.IdGenerator

      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

Examples of org.hibernate.metamodel.binding.IdGenerator

    final BasicAttributeBinding idAttributeBinding = doBasicSingularAttributeBindingCreation(
        identifierSource.getIdentifierAttributeSource(), entityBinding
    );

    entityBinding.getHierarchyDetails().getEntityIdentifier().setValueBinding( idAttributeBinding );
    IdGenerator generator = identifierSource.getIdentifierGeneratorDescriptor();
    if ( generator == null ) {
      Map<String, String> params = new HashMap<String, String>();
      params.put( IdentifierGenerator.ENTITY_NAME, entityBinding.getEntity().getName() );
      generator = new IdGenerator( "default_assign_identity_generator", "assigned", params );
    }
    entityBinding.getHierarchyDetails()
        .getEntityIdentifier()
        .setIdGenerator( generator );
View Full Code Here

Examples of org.hibernate.metamodel.binding.IdGenerator

    }
    return checkCondition;
  }

  private IdGenerator checkGeneratedValueAnnotation() {
    IdGenerator generator = null;
    AnnotationInstance generatedValueAnnotation = JandexHelper.getSingleAnnotation(
        annotations(),
        JPADotNames.GENERATED_VALUE
    );
    if ( generatedValueAnnotation != null ) {
      String name = JandexHelper.getValue( generatedValueAnnotation, "generator", String.class );
      if ( StringHelper.isNotEmpty( name ) ) {
        generator = getContext().getMetadataImplementor().getIdGenerator( name );
        if ( generator == null ) {
          throw new MappingException( String.format( "Unable to find named generator %s", name ), null );
        }
      }
      else {
        GenerationType genType = JandexHelper.getEnumValue(
            generatedValueAnnotation,
            "strategy",
            GenerationType.class
        );
        String strategy = EnumConversionHelper.generationTypeToGeneratorStrategyName(
            genType,
            getContext().getMetadataImplementor().getOptions().useNewIdentifierGenerators()
        );
        generator = new IdGenerator( null, strategy, null );
      }
    }
    return generator;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.