Package org.apache.ws.jaxme.sqls

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


     CombinedConstraint cc = statement.getWhere();
     BooleanConstraint bc = cc.createEQ();
     bc.addPart(tableReference.newColumnReference("MyIndex"));
     bc.addPlaceholder();

     SQLGenerator generator = getSQLGenerator();
     generator.setLineTerminator("\n");
     String got = generator.getQuery(statement);
     String expect = getTestJoinResult();
     assertEquals(expect, got);
  }
View Full Code Here


     CombinedConstraint cc = statement.getWhere();
     BooleanConstraint bc = cc.createEQ();
     bc.addPart(tableReference.newColumnReference("MyIndex"));
     bc.addPlaceholder();

     SQLGenerator generator = getSQLGenerator();
     generator.setLineTerminator("\n");
     String got = generator.getQuery(statement);
     String expect = getTestLeftOuterJoinResult();
     assertEquals(expect, got);
  }
View Full Code Here

    BooleanConstraint bc = existsStatement.getWhere().createEQ();
    bc.addPart(existsTableReference.newColumnReference("RefIndex"));
    bc.addPart(tableReference.newColumnReference("MyIndex"));
    statement.getWhere().createEXISTS(existsStatement);
  
    SQLGenerator generator = getSQLGenerator();
    generator.setLineTerminator("\n");
    String got = generator.getQuery(statement);
    String expect = "SELECT MyTable.MyIndex, MyName, MyDate FROM MySchema.MyTable" +
                    " WHERE EXISTS(SELECT OtherTable.MyIndex, RefIndex, Company" +
                    " FROM MySchema.OtherTable WHERE RefIndex=MyTable.MyIndex)";
    assertEquals(expect, got);
  }
View Full Code Here

  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);
    }

    Collection coll = gen.getCreate(schema, true);
    String[] cmds = (String[]) coll.toArray(new String[coll.size()]);
    assertEquals(12, cmds.length);
    assertEquals("CREATE SCHEMA MySchema", cmds[0]);
    assertEquals("CREATE TABLE MySchema.MyTable (  MyIndex INT NOT NULL,  MyName VARCHAR(60) NOT NULL,  MyDate DATE)", cmds[1]);
    for (int i = 0;  i < 10;  i++) {
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));
      }
    }
    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);
    String expect = "DELETE FROM MySchema.MyTable WHERE (MyIndex, VerNum) IN ((SELECT RefMyIndex, RefVerNum FROM MySchema.OtherTable WHERE RefMyName=?))";
    String got = gen.getQuery(deleteStatement);
    assertEquals(expect, got);
  }
View Full Code Here

    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

TOP

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

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.