Package org.apache.ws.jaxme.sqls

Examples of org.apache.ws.jaxme.sqls.SelectStatement


  /** <p>Test for a JOIN statement.</p>
   */
  public void testJoin() {
     Table table = getPrimaryKeyTable();
     Table otherTable = getForeignKeyTable(table);
     SelectStatement statement = otherTable.getSelectStatement();
     SelectTableReference tableReference = statement.getSelectTableReference();
     JoinReference joinReference = tableReference.join(table);

     TableReference refLocal = tableReference;
     TableReference refRef = tableReference.getRightJoinedTableReference();

     joinReference.getOn().addJoin((ForeignKey) otherTable.getForeignKeys().next(),
                                   refLocal, refRef);
     CombinedConstraint cc = statement.getWhere();
     BooleanConstraint bc = cc.createEQ();
     bc.addPart(tableReference.newColumnReference("MyIndex"));
     bc.addPlaceholder();

     SQLGenerator generator = getSQLGenerator();
View Full Code Here


  /** <p>Test for a LEFT OUTER JOIN statement.</p>
   */
  public void testLeftOuterJoin() {
     Table table = getPrimaryKeyTable();
     Table otherTable = getForeignKeyTable(table);
     SelectStatement statement = otherTable.getSelectStatement();
     SelectTableReference tableReference = statement.getSelectTableReference();
     JoinReference joinReference = tableReference.leftOuterJoin(table);

     TableReference refLocal = tableReference;
     TableReference refRef = tableReference.getRightJoinedTableReference();

     joinReference.getOn().addJoin((ForeignKey) otherTable.getForeignKeys().next(),
                                   refLocal, refRef);
     CombinedConstraint cc = statement.getWhere();
     BooleanConstraint bc = cc.createEQ();
     bc.addPart(tableReference.newColumnReference("MyIndex"));
     bc.addPlaceholder();

     SQLGenerator generator = getSQLGenerator();
View Full Code Here

  /** <p>Test for an EXISTS clause.</p>
   */
  public void testExists() {
    Table table = getPrimaryKeyTable();
    Table otherTable = getForeignKeyTable(table);
    SelectStatement statement = table.getSelectStatement();
    SelectTableReference tableReference = statement.getSelectTableReference();
    SelectStatement existsStatement = otherTable.getSelectStatement();
    SelectTableReference existsTableReference = existsStatement.getSelectTableReference();
    BooleanConstraint bc = existsStatement.getWhere().createEQ();
    bc.addPart(existsTableReference.newColumnReference("RefIndex"));
    bc.addPart(tableReference.newColumnReference("MyIndex"));
    statement.getWhere().createEXISTS(existsStatement);
  
    SQLGenerator generator = getSQLGenerator();
View Full Code Here

  /** <p>Test for composed primary keys.</p>
   */
  public void testComposedPrimaryKey() {
    Table table = getComposedKeyTable();

    SelectStatement statement = table.getSelectStatement();
    statement.getWhere().addColumnSetQuery(table.getPrimaryKey(), statement.getTableReference());
    SQLGenerator generator = getSQLGenerator();
    generator.setLineTerminator("\n");
    String s = generator.getQuery(statement);
    assertEquals("SELECT MyIndex, MyName, MyDate, VerNum FROM MySchema.MyTable WHERE (MyIndex=? AND VerNum=?)", s);
  }
View Full Code Here

    Table otherTable = table.getSchema().newTable("OtherTable");
    Column otherIndex = otherTable.newColumn("MyIndex", Column.Type.INTEGER);
    otherTable.newPrimaryKey().addColumn(otherIndex);
    ForeignKey foreignKey = otherTable.newForeignKey(table);
    SelectStatement selectStatement = sqlFactory.newSelectStatement();
    selectStatement.setTable(otherTable);
    DeleteStatement deleteStatement = sqlFactory.newDeleteStatement();
    deleteStatement.setTable(table);
    List columns = new ArrayList();
    for (Iterator iter = table.getColumns();  iter.hasNext()) {
      Column column = (Column) iter.next();
      Column refColumn = otherTable.newColumn("Ref" + column.getName(), column.getType());
      foreignKey.addColumnLink(refColumn, column);
      if (column.isPrimaryKeyPart()) {
        selectStatement.addResultColumn(selectStatement.getTableReference().newColumnReference(refColumn));
        columns.add(deleteStatement.getTableReference().newColumnReference(column));
      }
    }
    BooleanConstraint eq = selectStatement.getWhere().createEQ();
    eq.addPart(selectStatement.getTableReference().newColumnReference("RefMyName"));
    eq.addPlaceholder();

    BooleanConstraint bc = deleteStatement.getWhere().createIN();
    bc.addPart((ColumnReference[]) columns.toArray(new ColumnReference[columns.size()]));
    bc.addPart(selectStatement);
View Full Code Here

    assertEquals(expect, got);
  }

  public void testVirtualColumn() {
    Table table = getBasicTable();
    SelectStatement selectStatement = table.getSelectStatement();
    VirtualColumn col = new VirtualColumn("virtCol", Column.Type.VARCHAR);
    selectStatement.addResultColumn(col);
    col.setValue("null");
    SQLGenerator gen = getSQLGenerator();
    String query = gen.getQuery(selectStatement);
    assertEquals("SELECT MyIndex, MyName, MyDate, null AS virtCol FROM MySchema.MyTable", query);
  }
View Full Code Here

      return getBooleanConstraintPart(pData, o) + " IN (" + getParts(pData, parts) + ')';
    }
    StringBuffer result = new StringBuffer();
    int expected;
    if (BooleanConstraint.Type.EXISTS.equals(type)) {
      SelectStatement selectStatement = (SelectStatement) parts.next();
      result.append("EXISTS(");
      result.append(getSelectQuery(selectStatement, pData));
      result.append(")");
      expected = 1;
    } else {
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.sqls.SelectStatement

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.