Package org.apache.ws.jaxme.sqls

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


      }
      return result;
   }

   public SelectStatement getSelectStatement() {
      SelectStatement result = getSchema().getSQLFactory().newSelectStatement();
      result.setTable(this);
      TableReference ref = result.getTableReference();
      for (Iterator iter = getColumns();  iter.hasNext()) {
         Column column = (Column) iter.next();
         result.addResultColumn(new ColumnReferenceImpl(ref, column));
      }
      return result;
   }
View Full Code Here


  /** <p>Basic test for creating a <code>SELECT</code> statement.</p>
   */
  public void testBasicSelect() {
    Table table = getBasicTable();
    SelectStatement selectStatement = table.getSelectStatement();
    SQLGenerator generator = sqlFactory.newSQLGenerator();
    generator.setLineTerminator("\n");
    String s = generator.getQuery(selectStatement);
    assertEquals("SELECT MyIndex, MyName, MyDate FROM MySchema.MyTable", s);
  }
View Full Code Here

  /** <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 = sqlFactory.newSQLGenerator();
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 = sqlFactory.newSQLGenerator();
    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 = sqlFactory.newSQLGenerator();
    String query = gen.getQuery(selectStatement);
    assertEquals("SELECT MyIndex, MyName, MyDate, null AS virtCol FROM MySchema.MyTable", query);
  }
View Full Code Here

                                   DirectAccessible pConn,
                                   DirectAccessible pMap,
                                   DirectAccessible pValues,
                                   boolean pReturnValue) {
    Table table = pTableInfo.getTable();
    SelectStatement statement = table.getSelectStatement();
    statement.getWhere().addColumnSetQuery(pColumnSet, statement.getTableReference());
    String s = table.getSchema().getSQLFactory().newSQLGenerator().getQuery(statement);
    Object query = JavaSource.getQuoted(s);
    if (isGeneratingLogging()) {
      LocalJavaField q = pMethod.newJavaField(String.class);
      q.addLine(query);
View Full Code Here

   
    /** <p>Basic test for creating a <code>SELECT</code> statement.</p>
     */
    public void testBasicSelect() {
        Table table = getBasicTable();
        SelectStatement selectStatement = table.getSelectStatement();
        SQLGenerator generator = getSQLGenerator();
        generator.setLineTerminator("\n");
        String s = generator.getQuery(selectStatement);
        assertEquals("SELECT MyIndex, MyName, MyDate FROM MySchema.MyTable", s);
    }
View Full Code Here

    }

    protected SelectStatement getJoinStatement() {
        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();
        return statement;
    }
View Full Code Here

    }

    /** <p>Test for a JOIN statement.</p>
     */
    public void testJoin() {
        SelectStatement statement = getJoinStatement();
        SQLGenerator generator = getSQLGenerator();
        generator.setLineTerminator("\n");
        String got = generator.getQuery(statement);
        String expect = getTestJoinResult();
        assertEquals(expect, got);
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.