Package org.apache.ws.jaxme.sqls

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


    return factory;
  }

  protected Table getMainTable() {
     if (mainTable == null) {
        Table mt = getSchema().newTable("MAIN");
        Column mtId = mt.newColumn("ID", Column.Type.BIGINT);
        Column mtVer = mt.newColumn("VER", Column.Type.INTEGER);
        StringColumn mtName = (StringColumn) mt.newColumn("NAME", Column.Type.VARCHAR);
        mtName.setLength(60);
        BinaryColumn mtSig = (BinaryColumn) mt.newColumn("SIG", Column.Type.BINARY);
        mtSig.setLength(16);
        mt.newColumn("DATE", Column.Type.DATE);

        Index primaryKey = mt.newPrimaryKey();
        primaryKey.addColumn(mtId);
        primaryKey.addColumn(mtVer);
        mainTable = mt;
     }
     return mainTable;
View Full Code Here


     return mainTable;
  }

  protected Table getSubTable() {
    if (subTable == null) {
      Table st = getSchema().newTable("SUB");
      StringColumn stId = (StringColumn) st.newColumn("ID", Column.Type.VARCHAR);
      stId.setLength(32);

      Column stMtId = st.newColumn("MTID", Column.Type.BIGINT);
      Column stMtVer = st.newColumn("MTVER", Column.Type.INTEGER);
      StringColumn stAddress = (StringColumn) st.newColumn("ADDRESS", Column.Type.VARCHAR);
      stAddress.setLength(60);
      StringColumn stEmail = (StringColumn) st.newColumn("EMAIL", Column.Type.VARCHAR);
      stEmail.setLength(60);
      stEmail.setNullable(true);

      Index primaryKey = st.newPrimaryKey();
      primaryKey.addColumn(stId);

      ForeignKey foreignKey = st.newForeignKey(getMainTable());
      foreignKey.addColumnLink(stMtId, getMainTable().getColumn("ID"));
      foreignKey.addColumnLink(stMtVer, getMainTable().getColumn("VER"));

      subTable = st;
    }
View Full Code Here

    return subTable;
  }

  protected Table getSubSubTable() {
     if (subsubTable == null) {
        Table sst = getSchema().newTable("SUBSUB");
        StringColumn sstId = (StringColumn) sst.newColumn("ID", Column.Type.VARCHAR);
        sstId.setLength(32);

        Column sstMtId = sst.newColumn("MTID", Column.Type.BIGINT);
        Column sstMtVer = sst.newColumn("MTVER", Column.Type.INTEGER);
        ForeignKey foreignKeySt = sst.newForeignKey(getMainTable());
        foreignKeySt.addColumnLink(sstMtId, getMainTable().getColumn("ID"));
        foreignKeySt.addColumnLink(sstMtVer, getMainTable().getColumn("VER"));

        StringColumn sstStId = (StringColumn) sst.newColumn("SSTID", Column.Type.VARCHAR);
        sstStId.setLength(32);
        ForeignKey foreignKeySst = sst.newForeignKey(getSubTable());
        foreignKeySst.addColumnLink(sstStId, getSubTable().getColumn("ID"));

        sst.newColumn("MTTS", Column.Type.TIMESTAMP);
     }
     return subsubTable;
  }
View Full Code Here

      tableInfo.add(pUpdater);
    }

    for (Iterator iter = pTable.getForeignKeys();  iter.hasNext()) {
      ForeignKey foreignKey = (ForeignKey) iter.next();
      Table referencedTable = foreignKey.getReferencedTable();
      for (Iterator iter2 = tablesByOrder.iterator();  iter2.hasNext()) {
        TableInfo referencedTableInfo = (TableInfo) iter2.next();
        if (referencedTableInfo.getTable().equals(referencedTable)) {
          ColumnUpdater columnUpdater = new ForeignKeyUpdater(foreignKey, referencedTableInfo);
          tableInfo.add(columnUpdater);
          if (!referencedTableInfo.hasPrimaryKey()) {
             throw new IllegalStateException("The table " + pTable.getQName() +
                                             " is referencing table " + referencedTable.getQName() +
                                             ", which doesn't have a primary key.");
          }
          referencedTableInfo.setReferenced(true);
        }
      }
View Full Code Here

                                   ColumnSet pColumnSet,
                                   DirectAccessible pConn,
                                   DirectAccessible pMap,
                                   DirectAccessible pValues,
                                   boolean pReturnValue) {
    Table table = pTableInfo.getTable();
    SelectStatement statement = table.getSelectStatement();
    statement.getWhere().addColumnSetQuery(pColumnSet, statement.getTableReference());
    String s = table.getSchema().getSQLFactory().newSQLGenerator().getQuery(statement);
    Object query = JavaSource.getQuoted(s);
    if (isGeneratingLogging()) {
      LocalJavaField q = pMethod.newJavaField(String.class);
      q.addLine(query);
      query = q;
      logFinest(pMethod, query, pValues);
    }

    LocalJavaField stmt = pMethod.newJavaField(PreparedStatement.class);
    stmt.addLine(pConn, ".prepareStatement(", JavaSource.getQuoted(s), ");");
    LocalJavaField isStmtClosed = pMethod.newJavaField(boolean.class);
    isStmtClosed.addLine("false");
    pMethod.addTry();

    int paramNum = 0;
    for (Iterator iter = pColumnSet.getColumns();  iter.hasNext()) {
       Object v = new Object[]{pValues, "[", Integer.toString(paramNum), "]"};
       Column column = (Column) iter.next();
       setPreparedStatementValue(pMethod, column, stmt, Integer.toString(++paramNum), v);
    }
    LocalJavaField rs = pMethod.newJavaField(ResultSet.class, "rs");
    rs.addLine(stmt, ".executeQuery()");
    LocalJavaField isRsClosed = pMethod.newJavaField(boolean.class);
    isRsClosed.addLine("false");
    LocalJavaField result;
    if (pReturnValue) {
      result = pMethod.newJavaField(Object[].class, "result");
      result.addLine("null");
    } else {
      result = null;
    }
    pMethod.addTry();

    pMethod.addWhile(rs, ".next()");
    if (result != null) {
      pMethod.addIf(result, " != null");
      pMethod.addThrowNew(IllegalStateException.class,
                          JavaSource.getQuoted("Expected a single row only."));
      pMethod.addEndIf();
    }

    int resultColumnSize = 0;
    for (Iterator iter = table.getColumns();  iter.hasNext();  iter.next()) {
       ++resultColumnSize;
    }
    LocalJavaField row = pMethod.newJavaField(Object[].class, "row");
    row.addLine("new ", Object.class, "[" + resultColumnSize + "];");

    int resultColumnNum = 0;
    for (Iterator iter = table.getColumns();  iter.hasNext()) {
       Column column = (Column) iter.next();
       setResultSetValue(pMethod, column, rs, resultColumnNum++, row);
    }

    pMethod.addLine(((result == null) ? "" : "result = "),
View Full Code Here

   */
  protected LocalJavaField getCacheDataClassInstance(JavaMethod pMethod,
                                                     TableInfo pTableInfo,
                                                     ColumnSet pColumnSet,
                                                     DirectAccessible pValues) {
    Table table = pColumnSet.getTable();
    List params = new ArrayList();
    for (Iterator iter = pColumnSet.getColumns();  iter.hasNext()) {
      Column primaryKeyColumn = (Column) iter.next();
      int index = -1;
      int i = 0;
      for (Iterator iter2 = table.getColumns();  iter2.hasNext();  ++i) {
        Column tableColumn = (Column) iter2.next();
        if (tableColumn.equals(primaryKeyColumn)) {
          index = i;
          break;
        }
View Full Code Here

  protected void getApplyCacheData(JavaMethod pMethod,
                                   TableInfo pTableInfo,
                                   ColumnSet pColumnSet,
                                   DirectAccessible pRow,
                                   DirectAccessible pData) {
    Table table = pTableInfo.getTable();
    for (Iterator iter = pColumnSet.getColumns();  iter.hasNext()) {
      Column primaryKeyColumn = (Column) iter.next();
      int index = -1;
      int i = 0;
      for (Iterator iter2 = table.getColumns();  iter2.hasNext();  ++i) {
        Column tableColumn = (Column) iter2.next();
        if (tableColumn.equals(primaryKeyColumn)) {
          index = i;
          break;
        }
View Full Code Here

  }

  /** <p>Creates a method for cloning one row from the given table.</p>
   */
  protected JavaMethod getInsertRowMethod(JavaSource pSource, TableInfo pTableInfo) {
    Table table = pTableInfo.getTable();
    JavaMethod jm = pSource.newJavaMethod(getInsertRowMethodName(pTableInfo),
                                          Object[].class, JavaSource.PRIVATE);
    jm.addThrows(SQLException.class);
    DirectAccessible connection = jm.addParam(Connection.class, "pConn");
    DirectAccessible map = jm.addParam(Map.class, "pMap");
    DirectAccessible values = jm.addParam(Object[].class, "pValue");

    logFinestEntering(jm, values);

    LocalJavaField baseKey = null;
    if (table.getPrimaryKey() != null) {
       baseKey = getCacheDataClassInstance(jm, pTableInfo,
                                                       table.getPrimaryKey(), values);
    jm.addIf(map, ".containsKey(", baseKey, ")");
    logFinestExiting(jm, JavaSource.getQuoted("null (Already cloned)"));
    jm.addLine("return null;");
    jm.addEndIf();
    }

    for (Iterator iter = pTableInfo.getColumnUpdaters();  iter.hasNext()) {
       ((ColumnUpdater) iter.next()).update(jm, pTableInfo, connection, map, values);
    }

    jm.addLine(jm.getName(), "(", connection, ", ", values, ");");

    if (baseKey != null) {
    LocalJavaField clonedKey = getCacheDataClassInstance(jm, pTableInfo,
                                                         table.getPrimaryKey(),
                                                         values);
    jm.addLine(map, ".put(", baseKey, ", ", clonedKey, ");");
    }


    // Clone objects referencing this object
    LocalJavaField referencedValues = null;
    for (Iterator referencingIter = tablesByOrder.iterator();  referencingIter.hasNext()) {
      TableInfo prevTableInfo = (TableInfo) referencingIter.next();
      Table prevTable = prevTableInfo.getTable();
      for (Iterator fkIter = prevTable.getForeignKeys();  fkIter.hasNext()) {
        ForeignKey fk = (ForeignKey) fkIter.next();
        if (fk.getReferencedTable().equals(table)) {
          if (referencedValues == null) {
            referencedValues = jm.newJavaField(Object[].class);
            referencedValues.addLine(baseKey, ".getValues()");
View Full Code Here

  }

  /** <p>Creates a method for cloning one row from the given table.</p>
   */
  protected JavaMethod getInnerInsertRowMethod(JavaSource pSource, TableInfo pTableInfo) {
    Table table = pTableInfo.getTable();
    JavaMethod jm = pSource.newJavaMethod(getInsertRowMethodName(pTableInfo),
                                          JavaQNameImpl.VOID, JavaSource.PRIVATE);
    jm.addThrows(SQLException.class);
    DirectAccessible connection = jm.addParam(Connection.class, "pConn");
    DirectAccessible values = jm.addParam(Object[].class, "pValue");

    logFinestEntering(jm, null);

    InsertStatement insertStatement = table.getInsertStatement();
    String s = table.getSchema().getSQLFactory().newSQLGenerator().getQuery(insertStatement);
    Object query = JavaSource.getQuoted(s);
    if (isGeneratingLogging()) {
      LocalJavaField q = jm.newJavaField(String.class);
      q.addLine(query);
      query = q;
      logFinest(jm, query, values);
    }
    LocalJavaField stmt = jm.newJavaField(PreparedStatement.class, "stmt");
    stmt.setFinal(true);
    stmt.addLine(connection, ".prepareStatement(", JavaSource.getQuoted(s), ");");
    LocalJavaField isStmtClosed = jm.newJavaField(boolean.class, "isStmtClosed");
    isStmtClosed.addLine("false");
    jm.addTry();

    int paramNum = 0;
    for (Iterator iter = table.getColumns();  iter.hasNext()) {
       Column column = (Column) iter.next();
       Object v = new Object[]{ values, "[", Integer.toString(paramNum), "]" };
       setPreparedStatementValue(jm, column, stmt, Integer.toString(++paramNum), v);
    }

View Full Code Here

  protected JavaMethod getPMClassDeleteMethod(TypeSG pController, JavaSource pSource, CustomTableData pData)
      throws SAXException {
    JavaMethod jm = pSource.newJavaMethod("delete", JavaQNameImpl.VOID, JavaSource.PUBLIC);
    Parameter pElement = jm.addParam(Element.class, "pElement");
    jm.addThrows(PMException.class);
    Table table = pData.getTable();

    JavaQName qName = pController.getComplexTypeSG().getClassContext().getXMLInterfaceName();
    LocalJavaField elem = jm.newJavaField(qName);
    elem.addLine("(", qName, ") ", pElement);

    String q = table.getSchema().getSQLFactory().newSQLGenerator().getQuery(table.getDeleteStatement());   
    LocalJavaField query = jm.newJavaField(String.class);
    query.setFinal(true);
    query.addLine(JavaSource.getQuoted(q));

    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();
    getPreparedStatementParameters(jm, stmt, elem, table.getPrimaryKey().getColumns(), 0);
    jm.addLine(stmt, ".executeUpdate();");

    getFinally(jm, stmt, null, null);
    getFinally(jm, connection, new Object[]{JavaSource.getQuoted("Failed to execute query "),
                                            " + ", query}, null);
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.