Package com.caucho.amber.table

Examples of com.caucho.amber.table.LinkColumns


        from = from + ", " + subTable.getName() + " o" + i;
      else
        from = subTable.getName() + " o" + i;

      if (where != null) {
        LinkColumns link = subTable.getDependentIdLink();

        where = where + " and " + link.generateJoin("o" + i, "o");
      }
      else
        throw new IllegalStateException();
    }
View Full Code Here


      OneToManyExpr oneToMany = (OneToManyExpr) arg;

      _groupList = new ArrayList<AmberExpr>();

      LinkColumns linkColumns = oneToMany.getLinkColumns();
      ForeignColumn fkColumn = linkColumns.getColumns().get(0);

      AmberExpr groupExpr = oneToMany.getParent();

      if (groupExpr instanceof PathExpr) {
        // jpa/119n
View Full Code Here

    }

    manyToManyField.setAssociationTable(mapTable);
    manyToManyField.setTable(sqlTable);

    manyToManyField.setSourceLink(new LinkColumns(mapTable,
              _sourceType.getTable(),
              sourceColumns));

    manyToManyField.setTargetLink(new LinkColumns(mapTable,
              targetType.getTable(),
              targetColumns));
      /*
      if (mapKey != null) {

View Full Code Here

    if (type.getSecondaryTables().size() > 0) {
      for (AmberField field : type.getFields()) {
        AmberTable subTable = field.getTable();

        if (subTable != null && subTable != type.getTable()) {
          LinkColumns link = subTable.getDependentIdLink();

          FromItem item = parser.createDependentFromItem(_fromItem, link);

          _subItems.add(item);
        }
View Full Code Here

    manyToManyField.setAssociationTable(mapTable);
    manyToManyField.setTable(sqlTable);
    manyToManyField.setLazy(isFetchLazy());

    manyToManyField.setSourceLink(new LinkColumns(mapTable,
                                                  _sourceType.getTable(),
                                                  sourceColumns));

    manyToManyField.setTargetLink(new LinkColumns(mapTable,
                                                  targetType.getTable(),
                                                  targetColumns));

    _sourceType.addField(manyToManyField);
  }
View Full Code Here

    // jpa/0i5-
    // Update column names for bidirectional many-to-many

    if (! sourceField.hasJoinColumns()) {
      LinkColumns sourceLink = sourceField.getSourceLink();
      ArrayList<ForeignColumn> columns = sourceLink.getColumns();
      for (ForeignColumn column : columns) {
  String columnName = column.getName();
  columnName = columnName.substring(columnName.indexOf('_'));
  columnName = toSqlName(manyToManyField.getName()) + columnName;
  column.setName(columnName);
      }
    }

    if (! sourceField.hasInverseJoinColumns()) {
      LinkColumns targetLink = sourceField.getTargetLink();
      ArrayList<ForeignColumn> columns = targetLink.getColumns();
      for (ForeignColumn column : columns) {
  String columnName = column.getName();
  columnName = columnName.substring(columnName.indexOf('_'));
  columnName = toSqlName(sourceField.getName()) + columnName;
  column.setName(columnName);
View Full Code Here

      oneToMany = (OneToManyExpr) _collectionExpr;
    }
    else
      throw new UnsupportedOperationException();

    LinkColumns join = oneToMany.getLinkColumns();

    if (_isNot)
      cb.append("NOT ");

    // jpa/10ca
    // XXX: needs to handle compound PK.
    ForeignColumn fk = (ForeignColumn) join.getColumns().get(0);
    cb.append(oneToMany.getParent().getChildFromItem().getName());
    cb.append('.');
    cb.append(fk.getTargetColumn().getName());

    // changed to IN for jpa/10ca cb.append("EXISTS (SELECT *");
    cb.append(" IN (SELECT "); // SELECT *");
    cb.append(fk.getName());
    AmberTable table = join.getSourceTable();
    cb.append(" FROM " + table.getName() + " caucho");
    cb.append(" WHERE ");

    String targetTable = oneToMany.getParent().getChildFromItem().getName();

    cb.append(join.generateJoin("caucho", targetTable));

    if (_itemExpr instanceof ArgExpr) {

      cb.append(" AND caucho.");

      if (_collectionExpr instanceof ManyToOneExpr) {
        join = ((ManyToOneExpr) _collectionExpr).getLinkColumns();

        String name = join.getColumns().get(0).getName();

        cb.append(name);
      }
      else {
        // XXX: needs to handle compound PK.
        ArrayList<AmberColumn> idColumns =
          join.getSourceTable().getIdColumns();

        cb.append(idColumns.get(0).getName());
      }

      cb.append(" = ?");
    }
    else if (_collectionExpr instanceof ManyToOneExpr) {
      join = ((ManyToOneExpr) _collectionExpr).getLinkColumns();

      String itemWhere;
      boolean isArg = false;

      String where;

      if (_itemExpr instanceof ManyToOneExpr) {
        LinkColumns manyToOneJoin = ((ManyToOneExpr) _itemExpr).getLinkColumns();

        itemWhere = ((ManyToOneExpr) _itemExpr).getParent().getChildFromItem().getName();

        where = join.generateJoin(manyToOneJoin, "caucho", itemWhere);
      }
View Full Code Here

      oneToMany = (OneToManyExpr) _collectionExpr;
    }
    else
      throw new UnsupportedOperationException();

    LinkColumns join = oneToMany.getLinkColumns();

    AmberTable table = join.getSourceTable();
    cb.append("EXISTS(SELECT ");

    if (table.getIdColumns().size() > 0)
      cb.append(table.getIdColumns().get(0).getName());
    else
      cb.append('*');

    cb.append(" FROM " + table.getName() + " " + _tableName);
    cb.append(" WHERE ");

    String targetTable = oneToMany.getParent().getChildFromItem().getName();

    cb.append(join.generateJoin(_tableName, targetTable));

    cb.append(')');
  }
View Full Code Here

  /**
   * Generates the where clause.
   */
  private void generateMatchArgWhere(CharBuffer cb, IdField parentId, String id)
  {
    LinkColumns link = getOwnerType().getTable().getDependentIdLink();

    ArrayList<AmberColumn> columns = parentId.getColumns();

    for (int i = 0; i < columns.size(); i++) {
      AmberColumn column = columns.get(i);

      if (i != 0)
        cb.append(" and ");

      cb.append(id);
      cb.append('.');
      cb.append(link.getSourceColumn(column).getName());
      cb.append("=?");
    }
  }
View Full Code Here

      foreignColumn.setUnique(unique);

      foreignColumns.add(foreignColumn);
    }

    LinkColumns linkColumns = new LinkColumns(sourceTable,
                                              _targetType.getTable(),
                                              foreignColumns);

    setLinkColumns(linkColumns);

    super.init();

    Id id = getEntityTargetType().getId();
    ArrayList<AmberColumn> keys = id.getColumns();

    if (_linkColumns == null) {
      ArrayList<ForeignColumn> columns = new ArrayList<ForeignColumn>();

      for (int i = 0; i < keys.size(); i++) {
        AmberColumn key = keys.get(i);

        String name;

        if (keys.size() == 1)
          name = getName();
        else
          name = getName() + "_" + key.getName();

        columns.add(sourceTable.createForeignColumn(name, key));
      }

      _linkColumns = new LinkColumns(relatedType.getTable(),
                                     _targetType.getTable(),
                                     columns);
    }

    if (relatedType.getId() != null) {
View Full Code Here

TOP

Related Classes of com.caucho.amber.table.LinkColumns

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.