Package org.apache.ws.jaxme.sqls

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


    }
    return result;
  }

  public DeleteStatement getDeleteStatement() {
    DeleteStatement result = getSchema().getSQLFactory().newDeleteStatement();
    result.setTable(this);
    ColumnSet primaryKey = getPrimaryKey();
    if (primaryKey == null) {
      throw new IllegalStateException("Cannot create a default delete statement without a primary key.");
    }
    result.getWhere().addColumnSetQuery(primaryKey, result.getTableReference());
    return result;
  }
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 = getSQLGenerator();
    generator.setLineTerminator("\n");
    String s = generator.getQuery(deleteStatement);
    assertEquals("DELETE FROM MySchema.MyTable WHERE MyIndex=?", s);
  }
View Full Code Here

    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

TOP

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

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.