Package org.hibernate.mapping

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


    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

      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

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

      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

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

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

      }
    }
  }

  private static void bindGenericGenerator(GenericGenerator def, ExtendedMappings mappings) {
    IdGenerator idGen = buildIdGenerator( def, mappings );
    mappings.addGenerator( idGen );
  }
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.