Package org.apache.ws.jaxme.sqls

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


    /** <p>Test for a BETWEEN clause.</p>
     */
    public void testBetween() {
        Table table = getBasicTable();
        SelectStatement statement = table.getSelectStatement();
    BooleanConstraint between = statement.getWhere().createBETWEEN();
    between.addPart(statement.getTableReference().newColumnReference("MyIndex"));
    between.addPart(3);
    between.addPart(5);

    SQLGenerator generator = getSQLGenerator();
        generator.setLineTerminator("\n");
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

        assertEquals("SELECT MyIndex, MyName, MyDate, null AS virtCol FROM MySchema.MyTable", query);
    }

    public void testNOT() {
        Table table = getBasicTable();
        SelectStatement selectStatement = table.getSelectStatement();
        SelectTableReference ref = selectStatement.getSelectTableReference();
        CombinedConstraint and = selectStatement.getWhere();
        BooleanConstraint bc = and.createLIKE();
        bc.addPart(ref.newColumnReference("MyName"));
        bc.addPart("%a%");
        CombinedConstraint or = and.createOrConstraint();
        or.setNOT(true);
View Full Code Here

  /** Test for expressions.
   */
  public void testExpressions() {
    Table t = getBasicTable();
    SelectStatement st = t.getSelectStatement();
    SelectTableReference ref = st.getSelectTableReference();
    BooleanConstraint bc = st.getWhere().createGT();
    Expression e1 = bc.createSUM();
    e1.addPart(ref.newColumnReference("MyIndex"));
    e1.addPart(3);
    Expression e2 = bc.createSUM();
    e2.addPart(5);
View Full Code Here

        }
        return (ColumnReference[]) result.toArray(new ColumnReference[result.size()]);
    }

    private ColumnReference[] getInsertStatementsColumns(InsertStatement pStatement) {
        SelectStatement subSelect = pStatement.getSubSelect();
        if (subSelect == null) {
            return getSetStatementsColumns(pStatement);
        } else {
          List result = new ArrayList();
            for (Iterator iter = subSelect.getResultColumns();  iter.hasNext()) {
            ColumnReference cRef = (ColumnReference) iter.next();
            Column.Name name;
            if (cRef.getAlias() == null) {
                    name = cRef.getColumn().getName();
            } else {
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 if (BooleanConstraint.Type.BETWEEN.equals(type)) {
View Full Code Here

        createColumnNames();
    }

    public StatementMetaData(InsertStatement pQuery, ColumnReference[] pColumns) {
      addSetStatement(pQuery, pColumns);
        SelectStatement subSelect = pQuery.getSubSelect();
        if (subSelect != null) {
          addSelectStatement(subSelect);
        }
        createTableAliases();
        createColumnNames();
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

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.