コード例 #1
0
  public static InDatabaseValueGenerationStrategyImpl create(
      SessionFactoryImplementor sessionFactoryImplementor,
      Property mappingProperty,
      ValueGeneration valueGeneration) {
    final int numberOfMappedColumns =
        mappingProperty.getType().getColumnSpan(sessionFactoryImplementor);
    if (numberOfMappedColumns == 1) {
      return new InDatabaseValueGenerationStrategyImpl(
          valueGeneration.getGenerationTiming(),
          valueGeneration.referenceColumnInSql(),
          new String[] {valueGeneration.getDatabaseGeneratedReferencedColumnValue()});

    } else {
      if (valueGeneration.getDatabaseGeneratedReferencedColumnValue() != null) {
        LOG.debugf(
            "Value generator specified column value in reference to multi-column attribute [%s -> %s]; ignoring",
            mappingProperty.getPersistentClass(), mappingProperty.getName());
      }
      return new InDatabaseValueGenerationStrategyImpl(
          valueGeneration.getGenerationTiming(),
          valueGeneration.referenceColumnInSql(),
          new String[numberOfMappedColumns]);
    }
  }
コード例 #2
0
  private static GenerationStrategyPair buildGenerationStrategyPair(
      final SessionFactoryImplementor sessionFactory, final Property mappingProperty) {
    final ValueGeneration valueGeneration = mappingProperty.getValueGenerationStrategy();
    if (valueGeneration != null
        && valueGeneration.getGenerationTiming() != GenerationTiming.NEVER) {
      // the property is generated in full. build the generation strategy pair.
      if (valueGeneration.getValueGenerator() != null) {
        // in-memory generation
        return new GenerationStrategyPair(
            FullInMemoryValueGenerationStrategy.create(valueGeneration));
      } else {
        // in-db generation
        return new GenerationStrategyPair(create(sessionFactory, mappingProperty, valueGeneration));
      }
    } else if (mappingProperty.getValue() instanceof Component) {
      final CompositeGenerationStrategyPairBuilder builder =
          new CompositeGenerationStrategyPairBuilder(mappingProperty);
      interpretPartialCompositeValueGeneration(
          sessionFactory, (Component) mappingProperty.getValue(), builder);
      return builder.buildPair();
    }

    return NO_GEN_PAIR;
  }
コード例 #3
0
 /**
  * Whether the given value generation strategy requires to read the value from the database or
  * not.
  */
 private boolean isReadRequired(ValueGeneration valueGeneration, GenerationTiming matchTiming) {
   return valueGeneration != null
       && valueGeneration.getValueGenerator() == null
       && timingsMatch(valueGeneration.getGenerationTiming(), matchTiming);
 }
コード例 #4
0
 public static FullInMemoryValueGenerationStrategy create(ValueGeneration valueGeneration) {
   return new FullInMemoryValueGenerationStrategy(
       valueGeneration.getGenerationTiming(), valueGeneration.getValueGenerator());
 }