Package org.apache.ws.jaxme.sqls

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


    JavaMethod jm = pSource.newJavaMethod("select", JavaQNameImpl.VOID, JavaSource.PUBLIC);
    Parameter pObserver = jm.addParam(Observer.class, "pObserver");
    Parameter pQuery = jm.addParam(String.class, "pQuery");
    Parameter pParams = jm.addParam(PMParams.class, "pParams");
    jm.addThrows(PMException.class);
    Table table = pData.getTable();

    JavaQName qName = pController.getComplexTypeSG().getClassContext().getXMLInterfaceName();
    StringBuffer sb = new StringBuffer();
    for (Iterator iter = table.getColumns();  iter.hasNext()) {
      Column col = (Column) iter.next();
      if (sb.length() > 0) sb.append(", ");
      sb.append(col.getName().getName());
    }
    LocalJavaField query = jm.newJavaField(String.class);
    jm.addIf(pParams, " != null  &&  pParams.isDistinct()");
    jm.addLine(query, " = ", JavaSource.getQuoted("SELECT DISTINCT"), ";");
    jm.addElse();
    jm.addLine(query, " = ", JavaSource.getQuoted("SELECT"), ";");
    jm.addEndIf();
    jm.addLine(query, " += ", JavaSource.getQuoted(" " + sb + " FROM " + table.getQName()), ";");
    jm.addIf(pQuery, " != null");
    jm.addLine(query, " += ", JavaSource.getQuoted(" WHERE "), " + ", pQuery, ";");
    jm.addEndIf();

    LocalJavaField connection = jm.newJavaField(Connection.class);
    connection.addLine("null");
    jm.addTry();
    jm.addLine(connection, " = getConnection();");
    LocalJavaField stmt = jm.newJavaField(PreparedStatement.class);
    stmt.addLine(connection, ".prepareStatement(", query, ")");
    jm.addTry();
    LocalJavaField rs = jm.newJavaField(ResultSet.class);
    rs.addLine(stmt, ".executeQuery();");
    jm.addTry();
    jm.addWhile(rs, ".next()");
    LocalJavaField elem = jm.newJavaField(qName);
    elem.addLine("(", qName, ") create()");
    getResultSet(jm, rs, elem, table.getColumns(), 0);
    jm.addLine(pObserver, ".notify(", elem, ");");
    jm.addEndWhile();

    getFinally(jm, rs, null, null);
    getFinally(jm, stmt, null, null);
View Full Code Here


        schemaName = tableName.substring(0, offset);
        tableName = tableName.substring(offset+1);
      } else {
        schemaName = null;
      }
      Table table;
      try {
        table = sqlFactory.getTable(conn, schemaName, tableName);
        conn.close();
        conn = null;
      } catch (SQLException e) {
        throw new SAXException("Failed to read table " + pTableDetails.getName() + ": " + e.getMessage(), e);
      }
      if (table.getPrimaryKey() == null) {
        throw new IllegalStateException("The table " + table.getQName() + " does not have a primary key.");
      }
      CustomTableData customTableData = new CustomTableData(this, table, pTypeSG, pTableDetails);
      for (Iterator iter = table.getColumns();  iter.hasNext()) {
        Column col = (Column) iter.next();
        Object sg = addColumn(pTypeSG, pType, col);
        CustomColumnData colData = new CustomColumnData(col.getName().getName(), sg);
        col.setCustomData(colData);
      }
View Full Code Here

    protected String getTestLeftOuterJoinResult() {
        return "SELECT OtherTable.MyIndex, RefIndex, Company FROM MySchema.OtherTable, MySchema.MyTable WHERE RefIndex=MyTable.MyIndex(+) AND OtherTable.MyIndex=?";
    }

    public void testConnectByPrior() {
        Table table = getBasicTable();
        OraSelectStatement selectStatement = (OraSelectStatement) table.getSelectStatement();
        SelectTableReference ref = selectStatement.getSelectTableReference();
        CombinedConstraint startWith = selectStatement.getStartWith();
        BooleanConstraint bc = startWith.createEQ();
        bc.addPart(ref.newColumnReference("MyIndex"));
        bc.addPart(1);
View Full Code Here

    public CreateTest(String pName) { super(pName); }
   
    /** <p>Creates a basic table</p>
     */
    protected Table getBasicTable() {
        Table table = schema.newTable("MyTable");
        Column myIndex = table.newColumn("MyIndex", Column.Type.INTEGER);
        assertTrue(!myIndex.isStringColumn());
        assertTrue(!myIndex.isBinaryColumn());
        Column myName = table.newColumn("MyName", Column.Type.VARCHAR);
        assertTrue(myName.isStringColumn()); // myName may be casted to a StringColumn
        assertTrue(!myName.isBinaryColumn());
        ((StringColumn) myName).setLength(60);
        Column myDate = table.newColumn("MyDate", Column.Type.DATE);
        assertTrue(!myDate.isStringColumn());
        assertTrue(!myDate.isBinaryColumn());
        myDate.setNullable(true);
        return table;
    }
View Full Code Here

    }
   
    /** <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 = getSQLGenerator();
        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 = getSQLGenerator();
        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 = getSQLGenerator();
        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 = getSQLGenerator();
        generator.setLineTerminator("\n");
        String s = generator.getQuery(updateStatement);
        assertEquals("UPDATE MySchema.MyTable SET MyName=?, MyDate=? WHERE MyIndex=?", s);
    }
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.