コード例 #1
0
  @Override
  protected void addColumnBinding(SimpleValue value) {
    if (StringHelper.isEmpty(mappedBy)) {
      // was the column explicitly quoted in the mapping/annotation
      // TODO: in metamodel, we need to better split global quoting and explicit quoting w/ respect
      // to logical names
      boolean isLogicalColumnQuoted = StringHelper.isQuoted(getLogicalColumnName());

      final ObjectNameNormalizer nameNormalizer = getBuildingContext().getObjectNameNormalizer();
      final String logicalColumnName =
          nameNormalizer.normalizeIdentifierQuotingAsString(getLogicalColumnName());
      final String referencedColumn =
          nameNormalizer.normalizeIdentifierQuotingAsString(getReferencedColumn());
      final String unquotedLogColName = StringHelper.unquote(logicalColumnName);
      final String unquotedRefColumn = StringHelper.unquote(referencedColumn);

      String logicalCollectionColumnName =
          StringHelper.isNotEmpty(unquotedLogColName)
              ? unquotedLogColName
              : getPropertyName() + '_' + unquotedRefColumn;
      logicalCollectionColumnName =
          getBuildingContext()
              .getMetadataCollector()
              .getDatabase()
              .getJdbcEnvironment()
              .getIdentifierHelper()
              .toIdentifier(logicalCollectionColumnName, isLogicalColumnQuoted)
              .render();
      getBuildingContext()
          .getMetadataCollector()
          .addColumnNameBinding(value.getTable(), logicalCollectionColumnName, getMappingColumn());
    }
  }
コード例 #2
0
  /** Build JoinColumn for a JOINED hierarchy */
  public static Ejb3JoinColumn buildJoinColumn(
      PrimaryKeyJoinColumn pkJoinAnn,
      JoinColumn joinAnn,
      Value identifier,
      Map<String, Join> joins,
      PropertyHolder propertyHolder,
      MetadataBuildingContext context) {

    final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer();

    Column col = (Column) identifier.getColumnIterator().next();
    String defaultName =
        context
            .getMetadataCollector()
            .getLogicalColumnName(identifier.getTable(), col.getQuotedName());

    if (pkJoinAnn != null || joinAnn != null) {
      String colName;
      String columnDefinition;
      String referencedColumnName;
      if (pkJoinAnn != null) {
        colName = pkJoinAnn.name();
        columnDefinition = pkJoinAnn.columnDefinition();
        referencedColumnName = pkJoinAnn.referencedColumnName();
      } else {
        colName = joinAnn.name();
        columnDefinition = joinAnn.columnDefinition();
        referencedColumnName = joinAnn.referencedColumnName();
      }

      final String sqlType;
      if (columnDefinition.equals("")) {
        sqlType = null;
      } else {
        sqlType = normalizer.toDatabaseIdentifierText(columnDefinition);
      }

      final String name;
      if ("".equals(colName)) {
        name = normalizer.normalizeIdentifierQuotingAsString(defaultName);
      } else {
        name = context.getObjectNameNormalizer().normalizeIdentifierQuotingAsString(colName);
      }
      return new Ejb3JoinColumn(
          sqlType,
          name,
          false,
          false,
          true,
          true,
          referencedColumnName,
          null,
          joins,
          propertyHolder,
          null,
          null,
          false,
          context);
    } else {
      defaultName =
          context.getObjectNameNormalizer().normalizeIdentifierQuotingAsString(defaultName);
      return new Ejb3JoinColumn(
          null,
          defaultName,
          false,
          false,
          true,
          true,
          null,
          null,
          joins,
          propertyHolder,
          null,
          null,
          true,
          context);
    }
  }