Package org.apache.ws.jaxme.sqls

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


  }

  /** <p>Creates a table with primary key</p>
   */
  protected Table getPrimaryKeyTable() {
    Table table = getBasicTable();
    Index index = table.newPrimaryKey();
    index.addColumn("MyIndex");
    return table;
  }
View Full Code Here


    index.addColumn("MyIndex");
    return table;
  }

  protected Table getForeignKeyTable(Table pTable) {
     Table otherTable = pTable.getSchema().newTable("OtherTable");
     Column otherIndex = otherTable.newColumn("MyIndex", Column.Type.INTEGER);
     Column referenceColumn = otherTable.newColumn("RefIndex", Column.Type.INTEGER);
     Column companyColumn = otherTable.newColumn("Company", Column.Type.VARCHAR);
     ((StringColumn) companyColumn).setLength(60);
     otherTable.newPrimaryKey().addColumn(otherIndex);

     ForeignKey reference = otherTable.newForeignKey(pTable);
     reference.addColumnLink(referenceColumn, pTable.getColumn("MyIndex"));
     return otherTable;
  }
View Full Code Here

  /** <p>Basic test for creating a <code>CREATE TABLE</code>
   * statement.</p>
   */
  public void testBasicCreate() {
    Table table = getBasicTable();
    SQLGenerator generator = sqlFactory.newSQLGenerator();
    generator.setLineTerminator("\n");
    Collection statements = generator.getCreate(table.getSchema(), true);
    Iterator iter = statements.iterator();
    assertTrue(iter.hasNext());
    assertEquals("CREATE SCHEMA MySchema", iter.next());
    assertTrue(iter.hasNext());
    assertEquals("CREATE TABLE MySchema.MyTable (\n" +
View Full Code Here

  }

  /** <p>Basic test for creating an <code>INSERT</code> statement.</p>
   */
  public void testBasicInsert() {
    Table table = getBasicTable();
    InsertStatement insertStatement = table.getInsertStatement();
    SQLGenerator generator = sqlFactory.newSQLGenerator();
    generator.setLineTerminator("\n");
    String s = generator.getQuery(insertStatement);
    assertEquals("INSERT INTO MySchema.MyTable (MyIndex, MyName, MyDate) VALUES (?, ?, ?)", s);
  }
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>Basic test for creating an <code>UPDATE</code> statement.</p>
   */
  public void testBasicUpdate() {
    Table table = getPrimaryKeyTable();
    UpdateStatement updateStatement = table.getUpdateStatement();
    SQLGenerator generator = sqlFactory.newSQLGenerator();
    generator.setLineTerminator("\n");
    String s = generator.getQuery(updateStatement);
    assertEquals("UPDATE MySchema.MyTable SET MyName=?, MyDate=? WHERE MyIndex=?", s);
  }
View Full Code Here

  }

  /** <p>Basic test for creating an <code>DELETE</code> statement.</p>
   */
  public void testBasicDelete() {
    Table table = getPrimaryKeyTable();
    DeleteStatement deleteStatement = table.getDeleteStatement();
    SQLGenerator generator = sqlFactory.newSQLGenerator();
    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 = sqlFactory.newSQLGenerator();
     Collection c = generator.getCreate(otherTable);
     assertEquals(1, c.size());
     String expect = getCreateForeignKeyResult();
     String got = (String) c.iterator().next();
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();
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

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.