Package org.apache.ws.jaxme.sqls

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


    }
   
    /** <p>Basic test for creating an <code>DELETE</code> statement.</p>
     */
    public void testBasicDelete() {
        Table table = getPrimaryKeyTable();
        DeleteStatement deleteStatement = table.getDeleteStatement();
        SQLGenerator generator = getSQLGenerator();
        generator.setLineTerminator("\n");
        String s = generator.getQuery(deleteStatement);
        assertEquals("DELETE FROM MySchema.MyTable WHERE MyIndex=?", s);
    }
View Full Code Here


    }
   
    /** <p>Test for a FOREIGN KEY definition.</p>
     */
    public void testCreateForeignKey() {
        Table table = getPrimaryKeyTable();
        Table otherTable = getForeignKeyTable(table);
        SQLGenerator generator = getSQLGenerator();
        Collection c = generator.getCreate(otherTable);
        assertEquals(1, c.size());
        String expect = getCreateForeignKeyResult();
        String got = (String) c.iterator().next();
View Full Code Here

    protected String getTestJoinResult() {
        return "SELECT OtherTable.MyIndex, RefIndex, Company FROM MySchema.OtherTable JOIN MySchema.MyTable ON RefIndex=MyTable.MyIndex WHERE OtherTable.MyIndex=?";
    }

    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();
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();
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);
View Full Code Here

    }
   
    /** <p>Creates a table with a composed primary key.</p>
     */
    protected Table getComposedKeyTable() {
        Table table = getPrimaryKeyTable();
        Column verNumColumn = table.newColumn("VerNum", Column.Type.INTEGER);
        assertTrue(!verNumColumn.isStringColumn());
        assertTrue(!verNumColumn.isBinaryColumn());
        Index index = table.getPrimaryKey();
        index.addColumn("VerNum");
        return table;
    }
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

   
    /** <p>Test for index names.</p>
     */
    public void testIndexNames() {
        SQLGenerator gen = getSQLGenerator();
        Table table = getBasicTable();
        for (int i = 0;  i < 10;  i++) {
            Index index = table.newIndex();
            index.addColumn("MyName");
            String s = (String) gen.getCreate(index).iterator().next();
            assertEquals("CREATE INDEX MyTable_I" + i + " ON MySchema.MyTable (MyName)", s);
        }
       
View Full Code Here

   
    /** <p>Test for subselects.</p>
     */
    public void testSubSelect() {
        SQLGenerator gen = getSQLGenerator();
        Table table = getComposedKeyTable();
       
        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));
            }
View Full Code Here

        String got = gen.getQuery(deleteStatement);
        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);
View Full Code Here

TOP

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

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.