OneToOneAttributeSourceImpl(
      MappingDocument sourceMappingDocument,
      AttributeSourceContainer container,
      final JaxbOneToOneElement oneToOneElement,
      final String logicalTableName,
      NaturalIdMutability naturalIdMutability) {
    super(sourceMappingDocument, naturalIdMutability, oneToOneElement.getPropertyRef());
    this.oneToOneElement = oneToOneElement;
    this.containingTableName = logicalTableName;
    this.valueSources =
        Helper.buildValueSources(
            sourceMappingDocument(),
            new Helper.ValueSourcesAdapter() {
              @Override
              public String getColumnAttribute() {
                // Not applicable to one-to-one
                return null;
              }

              @Override
              public String getFormulaAttribute() {
                return oneToOneElement.getFormulaAttribute();
              }

              @Override
              public List<JaxbColumnElement> getColumn() {
                // Not applicable to one-to-one
                return null;
              }

              @Override
              public List<String> getFormula() {
                return oneToOneElement.getFormula();
              }

              @Override
              public String getContainingTableName() {
                return logicalTableName;
              }

              @Override
              public boolean isIncludedInInsertByDefault() {
                return true;
              }

              @Override
              public boolean isIncludedInUpdateByDefault() {
                return false;
              }
            });

    this.attributeRole = container.getAttributeRoleBase().append(oneToOneElement.getName());
    this.attributePath = container.getAttributePathBase().append(oneToOneElement.getName());
  }
  public KeyManyToOneSourceImpl(
      MappingDocument mappingDocument,
      final JaxbKeyManyToOneElement keyManyToOneElement,
      final SingularAttributeBinding.NaturalIdMutability naturalIdMutability) {
    super(mappingDocument, naturalIdMutability, null);
    this.keyManyToOneElement = keyManyToOneElement;
    this.valueSources =
        Helper.buildValueSources(
            sourceMappingDocument(),
            new Helper.ValueSourcesAdapter() {
              @Override
              public String getColumnAttribute() {
                return keyManyToOneElement.getColumnAttribute();
              }

              @Override
              public String getFormulaAttribute() {
                return null;
              }

              @Override
              public List<JaxbColumnElement> getColumn() {
                return keyManyToOneElement.getColumn();
              }

              @Override
              public List<String> getFormula() {
                return Collections.emptyList();
              }

              @Override
              public String getContainingTableName() {
                return null;
              }

              @Override
              public boolean isIncludedInInsertByDefault() {
                return true;
              }

              @Override
              public boolean isIncludedInUpdateByDefault() {
                return false;
              }
            });
  }
  public ManyToManyPluralAttributeElementSourceImpl(
      MappingDocument mappingDocument,
      final PluralAttributeSource pluralAttributeSource,
      final JaxbManyToManyElement manyToManyElement,
      String cascadeString) {
    super(mappingDocument, pluralAttributeSource);
    this.manyToManyElement = manyToManyElement;
    this.cascadeStyles = Helper.interpretCascadeStyles(cascadeString, bindingContext());

    this.valueSources =
        Helper.buildValueSources(
            sourceMappingDocument(),
            new Helper.ValueSourcesAdapter() {
              @Override
              public boolean isIncludedInInsertByDefault() {
                return true;
              }

              @Override
              public boolean isIncludedInUpdateByDefault() {
                return true;
              }

              @Override
              public String getColumnAttribute() {
                return manyToManyElement.getColumnAttribute();
              }

              @Override
              public String getFormulaAttribute() {
                return manyToManyElement.getFormulaAttribute();
              }

              @Override
              public List<JaxbColumnElement> getColumn() {
                return manyToManyElement.getColumn();
              }

              @Override
              public List<String> getFormula() {
                return manyToManyElement.getFormula();
              }
            });
    this.filterSources = buildFilterSources();
  }
Esempio n. 4
0
  public IdBagSourceImpl(
      MappingDocument mappingDocument,
      final JaxbIdbagElement element,
      AbstractEntitySourceImpl abstractEntitySource) {
    super(mappingDocument, element, abstractEntitySource);

    final List<RelationalValueSource> relationalValueSources =
        Helper.buildValueSources(
            sourceMappingDocument(),
            new Helper.ValueSourcesAdapter() {
              @Override
              public String getColumnAttribute() {
                return element.getCollectionId().getColumnAttribute();
              }

              @Override
              public SizeSource getSizeSource() {
                return Helper.createSizeSourceIfMapped(
                    element.getCollectionId().getLength(), null, null);
              }

              @Override
              public List<JaxbColumnElement> getColumn() {
                return element.getCollectionId().getColumn();
              }

              @Override
              public boolean isIncludedInInsertByDefault() {
                return true;
              }

              @Override
              public boolean isForceNotNull() {
                return true;
              }
            });

    ColumnSource collectionIdColumnSource = null;
    if (relationalValueSources != null && relationalValueSources.isEmpty()) {
      if (relationalValueSources.size() > 1) {
        throw makeMappingException("Expecting just a single column for collection id (idbag)");
      }

      final RelationalValueSource relationalValueSource = relationalValueSources.get(0);
      if (!ColumnSource.class.isInstance(relationalValueSource)) {
        throw makeMappingException("Expecting column for collection id (idbag), but found formula");
      }

      collectionIdColumnSource = (ColumnSource) relationalValueSource;
    }

    final HibernateTypeSource typeSource =
        new HibernateTypeSource() {
          private final String name = element.getCollectionId().getType();

          @Override
          public String getName() {
            return name;
          }

          @Override
          public Map<String, String> getParameters() {
            return Collections.emptyMap();
          }

          @Override
          public JavaTypeDescriptor getJavaType() {
            return null;
          }
        };

    this.collectionIdSource =
        new CollectionIdSourceImpl(
            collectionIdColumnSource,
            typeSource,
            element.getCollectionId().getGenerator().getClazz());
  }