Package org.apache.ws.jaxme.js

Examples of org.apache.ws.jaxme.js.LocalJavaField


      }
      params.add(new Object[]{pValues, "[" + index + "]"});
    }

    JavaQName cacheDataClass = getCacheDataClassName(pMethod.getJavaSource().getQName());
    LocalJavaField jf = pMethod.newJavaField(cacheDataClass);
    jf.addLine("new ", cacheDataClass, "(",

    JavaSource.getQuoted(pTableInfo.getPropertyName()),
                         ", new ", Object[].class, "{", params, "})");
    return jf;
  }
View Full Code Here


    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()");
          }
          getSelectRowsCode(jm, prevTableInfo, fk, connection, map, referencedValues, false);
        }
      }
    }
View Full Code Here

    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();
View Full Code Here

    DirectAccessible conn = jm.addParam(Connection.class, "pConn");
    DirectAccessible row = jm.addParam(resultType, "pRow");

    logEntering(jm, new Object[]{"new ", Object[].class, "{", conn, ", ", row, "}"});

    LocalJavaField map = jm.newJavaField(Map.class, "clonedObjects");
    map.addLine("new ", HashMap.class, "()");

    getSelectRowsCode(jm, headTable, headTable.getTable().getPrimaryKey(),
                      conn, map, row, true);
    return jm;
  }
View Full Code Here

    }

    public void update(JavaMethod pMethod, TableInfo pTableInfo,
                       DirectAccessible pConnection,
                       DirectAccessible pMap, DirectAccessible pRow) {
      LocalJavaField referencedKey = getCacheDataClassInstance(pMethod,
                                                               referencedTable,
                                                               foreignKey, pRow);
      LocalJavaField mappedKey = pMethod.newJavaField(referencedKey.getType());
      mappedKey.addLine("(", referencedKey.getType(), ") ", pMap, ".get(",
                        referencedKey, ")");
      pMethod.addIf(mappedKey, " == null");
      pMethod.addThrowNew(IllegalStateException.class,
                          JavaSource.getQuoted("Unknown reference: "), " + ",
                          referencedKey);
View Full Code Here

      JavaSourceFactory factory = new JavaSourceFactory();
      JavaSource js;
      JavaConstructor jcon;
      JavaMethod jm;
      JavaField jf;
      LocalJavaField lfj;
      if (pProtection == null) {
        js = factory.newJavaSource(JavaQNameImpl.getInstance(PACKAGE_NAME, CLASS_NAME));
        js.newJavaInnerClass("Bof");
        jf = js.newJavaField("someField", int.class);
        jcon = js.newJavaConstructor();
        jm = js.newJavaMethod("test", void.class);
        lfj = jm.newJavaField(String.class, "localTest");
      } else {
        js = factory.newJavaSource(JavaQNameImpl.getInstance(PACKAGE_NAME, CLASS_NAME), pProtection);
        js.newJavaInnerClass("Bof", pProtection);
        jf = js.newJavaField("someField", int.class, pProtection);
        jcon = js.newJavaConstructor(pProtection);
        jm = js.newJavaMethod("test", void.class, pProtection);
        lfj = jm.newJavaField(String.class, "localTest");
      }
      lfj.setFinal(true);
      lfj.addLine(JavaSource.getQuoted("abc"));

      jcon.addLine(jf, " = 0;");
      jm.addThrowNew(NullPointerException.class, JavaSource.getQuoted("Not implemented"));
      return js;
   }
View Full Code Here

      } else if (Column.Type.TINYINT.equals(type)) {
        pMethod.addLine(pStmt, ".setByte(", pParamNum, ", ", pValue, ");");
      }
    } else {
      if (!(pValue instanceof DirectAccessible)) {
         LocalJavaField v = pMethod.newJavaField(pTypeSG.getRuntimeType());
         v.addLine(pValue);
         pValue = v;
      }
      pMethod.addIf(pValue, " == null");
      pMethod.addLine(pStmt, ".setNull(", pParamNum, ", ", Types.class, ".", type, ");");
      pMethod.addElse();
View Full Code Here

      if (pColumn.isStringColumn()) {
        return new Object[]{pRs, ".getString(", pParamNum, ")"};
      } else if (pColumn.isBinaryColumn()) {
        return new Object[]{pRs, ".getBytes(", pParamNum, ")"};
      } else if (Column.Type.DATE.equals(type)) {
        LocalJavaField cal = pMethod.newJavaField(Calendar.class);
        LocalJavaField date = pMethod.newJavaField(Date.class);
        date.addLine(pRs, ".getDate(", pParamNum, ")");
        pMethod.addIf(date, " == null");
        pMethod.addLine(cal, " = null;");
        pMethod.addElse();
        pMethod.addLine(cal, " = ", Calendar.class, ".getInstance();");
        pMethod.addLine(cal, ".setTime(", date, ");");
        pMethod.addLine(cal, ".set(", Calendar.class, ".HOUR, 0);");
        pMethod.addLine(cal, ".set(", Calendar.class, ".MINUTE, 0);");
        pMethod.addLine(cal, ".set(", Calendar.class, ".SECOND, 0);");
        pMethod.addLine(cal, ".set(", Calendar.class, ".MILLISECOND, 0);");
        pMethod.addEndIf();
        return cal;
      } else if (Column.Type.TIME.equals(type)) {
        LocalJavaField cal = pMethod.newJavaField(Calendar.class);
        LocalJavaField date = pMethod.newJavaField(Time.class);
        date.addLine(pRs, ".getTime(", pParamNum, ")");
        pMethod.addIf(date, " == null");
        pMethod.addLine(cal, " = null;");
        pMethod.addElse();
        pMethod.addLine(cal, " = ", Calendar.class, ".getInstance();");
        pMethod.addLine(cal, ".setTime(", date, ");");
        pMethod.addLine(cal, ".set(", Calendar.class, ".YEAR, 0);");
        pMethod.addLine(cal, ".set(", Calendar.class, ".MONTH, 0);");
        pMethod.addLine(cal, ".set(", Calendar.class, ".DAY_OF_MONTH, 0);");
        pMethod.addEndIf();
        return cal;
      } else if (Column.Type.TIMESTAMP.equals(type)) {
        LocalJavaField cal = pMethod.newJavaField(Calendar.class);
        LocalJavaField date = pMethod.newJavaField(Timestamp.class);
        date.addLine(pRs, ".getTimestamp(", pParamNum, ")");
        pMethod.addIf(date, " == null");
        pMethod.addLine(cal, " = null;");
        pMethod.addElse();
        pMethod.addLine(cal, " = ", Calendar.class, ".getInstance();");
        pMethod.addLine(cal, ".setTime(", date, ");");
        pMethod.addEndIf();
        return cal;
      } else if (Column.Type.BIT.equals(type)) {
        LocalJavaField b = pMethod.newJavaField(boolean.class);
        b.addLine(pRs, ".getBoolean(", pParamNum, ")");
        return new Object[]{"(", pRs, ".wasNull() ? null : ",
                               b, " ? ", Boolean.class, ".TRUE : ", Boolean.class, ".FALSE)"};
      } else if (Column.Type.BIGINT.equals(type)) {
        LocalJavaField l = pMethod.newJavaField(long.class);
        l.addLine(pRs, ".getLong(", pParamNum, ")");
        return new Object[]{"(", pRs, ".wasNull() ? null : new Long(", l, ")"};
      } else if (Column.Type.DOUBLE.equals(type)) {
        LocalJavaField d = pMethod.newJavaField(double.class);
        d.addLine(pRs, ".getDouble(", pParamNum, ")");
        return new Object[]{"(", pRs, ".wasNull() ? null : new Double(", d, ")"};
      } else if (Column.Type.FLOAT.equals(type)) {
        LocalJavaField f = pMethod.newJavaField(float.class);
        f.addLine(pRs, ".getFloat(", pParamNum, ")");
        return new Object[]{"(", pRs, ".wasNull() ? null : new Float(", f, ")"};
      } else if (Column.Type.INTEGER.equals(type)) {
        LocalJavaField i = pMethod.newJavaField(int.class);
        i.addLine(pRs, ".getInt(", pParamNum, ")");
        return new Object[]{"(", pRs, ".wasNull() ? null : new Integer(", i, ")"};
      } else if (Column.Type.SMALLINT.equals(type)) {
        LocalJavaField s = pMethod.newJavaField(short.class);
        s.addLine(pRs, ".getShort(", pParamNum, ")");
        return new Object[]{"(", pRs, ".wasNull() ? null : new Short(", s, ")"};
      } else if (Column.Type.TINYINT.equals(type)) {
        LocalJavaField b = pMethod.newJavaField(byte.class);
        b.addLine(pRs, ".getByte(", pParamNum, ")");
        return new Object[]{"(", pRs, ".wasNull() ? null : new Byte(", b, ")"};
      } else {
        throw new IllegalStateException("Unknown column type: " + type);
      }
    }
View Full Code Here

    Parameter pElement = jm.addParam(Element.class, "pElement");
    jm.addThrows(PMException.class);
    Table table = pData.getTable();

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

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

    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.getColumns(), 0);
    jm.addLine(stmt, ".executeUpdate();");
    getFinally(jm, stmt, null, null);
    getFinally(jm, connection, new Object[]{JavaSource.getQuoted("Failed to execute query "),
View Full Code Here

    Parameter pElement = jm.addParam(Element.class, "pElement");
    jm.addThrows(PMException.class);
    Table table = pData.getTable();

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

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

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

    List nonKeyColumns = new ArrayList();
    for (Iterator iter = table.getColumns();  iter.hasNext()) {
      Column col = (Column) iter.next();
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.js.LocalJavaField

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.