Package java.util

Examples of java.util.ListIterator


  public String getColumnsStr() throws IllegalStateException {

    if (null==oColumns)
      throw new IllegalStateException("Table columns list has not been initialized");

    ListIterator oColIterator = oColumns.listIterator();
    String sGetAllCols = new String("");

    while (oColIterator.hasNext())
      sGetAllCols += ((DBColumn) oColIterator.next()).getName() + ",";

    return sGetAllCols.substring(0, sGetAllCols.length()-1);

  } // getColumnsStr
View Full Code Here


  public DBColumn getColumnByName (String sColumnName) throws IllegalStateException {

    if (null==oColumns)
      throw new IllegalStateException("Table columns list not initialized");

    ListIterator oColIterator = oColumns.listIterator();
    DBColumn oCol = null;

    while (oColIterator.hasNext()) {
      oCol = (DBColumn) oColIterator.next();
      if (oCol.getName().equalsIgnoreCase(sColumnName)) {
        break;
      }
      oCol = null;
    } // wend
View Full Code Here

   * @param sColumnName Column Name
   * @return Column Index[1..columnsCount()] or -1 if no column with such name was found.
   */

  public int getColumnIndex (String sColumnName) {
    ListIterator oColIterator = oColumns.listIterator();
    DBColumn oCol = null;

    while (oColIterator.hasNext()) {
      oCol = (DBColumn) oColIterator.next();
      if (oCol.getName().equalsIgnoreCase(sColumnName)) {
        return oCol.getPosition();
      }
      oCol = null;
    } // wend
View Full Code Here

      ResultSet oRSet;
      ResultSetMetaData oRData;
      DBColumn oCol;
      String sCol;
      int iCols;
      ListIterator oColIterator;

      String sColName;
      short iSQLType;
      String sTypeName;
      int iPrecision;
      int iDigits;
      int iNullable;
      int iColPos;

      int iDBMS;

      String sGetAllCols = "";
      String sSetPKCols = "";
      String sSetAllCols = "";
      String sSetNoPKCols = "";

      oColumns = new LinkedList<DBColumn>();
    oIndexes = new LinkedList<DBIndex>();
      oPrimaryKeys = new LinkedList<String>();

      if (DebugFile.trace)
        {
        DebugFile.writeln("Begin DBTable.readColumns([DatabaseMetaData])" );
        DebugFile.incIdent();

        DebugFile.writeln("DatabaseMetaData.getColumns(" + sCatalog + "," + sSchema + "," + sName + ",%)");
        }

      if (oConn.getMetaData().getDatabaseProductName().equals("PostgreSQL"))
        iDBMS = JDCConnection.DBMS_POSTGRESQL;
      else if (oConn.getMetaData().getDatabaseProductName().equals("Oracle"))
        iDBMS = JDCConnection.DBMS_ORACLE;
      else if (oConn.getMetaData().getDatabaseProductName().equals("MySQL"))
        iDBMS = JDCConnection.DBMS_MYSQL;
      else if (oConn.getMetaData().getDatabaseProductName().equals("ACCESS"))
        iDBMS = JDCConnection.DBMS_ACCESS;
      else if (oConn.getMetaData().getDatabaseProductName().equals("Microsoft SQL Server"))
        iDBMS = JDCConnection.DBMS_MSSQL;
      else if (oConn.getMetaData().getDatabaseProductName().equals("SQLite"))
        iDBMS = JDCConnection.DBMS_SQLITE;
      else
        iDBMS = 0;

      oStmt = oConn.createStatement();

      try {
        if (DebugFile.trace) DebugFile.writeln("Statement.executeQuery(SELECT * FROM " + sName + " WHERE 1=0)");

        oRSet = oStmt.executeQuery("SELECT * FROM " + sName + " WHERE 1=0");
        iErrCode = 0;
      }
      catch (SQLException sqle) {
        // Patch for Oracle. DatabaseMetadata.getTables() returns table names
        // that later cannot be SELECTed, so this catch ignore these system tables

        oStmt.close();
        oRSet = null;

        if (DebugFile.trace) DebugFile.writeln("SQLException " + sName + " " + sqle.getMessage());

        iErrCode = sqle.getErrorCode();
        if (iErrCode==0) iErrCode=-1;
        if (!sqle.getSQLState().equals("42000"))
          throw new SQLException(sqle.getMessage(), sqle.getSQLState(), sqle.getErrorCode());
      }

      if (0==iErrCode) {
        if (DebugFile.trace) DebugFile.writeln("ResultSet.getMetaData()");

        oRData= oRSet.getMetaData();

        iCols = oRData.getColumnCount();

        if (DebugFile.trace) DebugFile.writeln("table has " + String.valueOf(iCols) + " columns");

        for (int c=1; c<=iCols; c++) {
          sColName = oRData.getColumnName(c).toLowerCase();
          sTypeName = oRData.getColumnTypeName(c);
          iSQLType = (short) oRData.getColumnType(c);

          if (iDBMS==JDCConnection.DBMS_POSTGRESQL)
            switch (iSQLType) {
              case Types.CHAR:
              case Types.VARCHAR:
                iPrecision = oRData.getColumnDisplaySize(c);
                break;
              default:
                iPrecision = oRData.getPrecision(c);
            }
          else {
            // New for v2.0, solves bug SF887614
            if (iSQLType==Types.BLOB || iSQLType==Types.CLOB)
              iPrecision = 2147483647;
            // end v2.0
            else
              iPrecision = oRData.getPrecision(c);
          }

          iDigits = oRData.getScale(c);
          iNullable = oRData.isNullable(c);
          iColPos = c;

          if (5==iDBMS && iSQLType==Types.NUMERIC && iPrecision<=6 && iDigits==0) {
            // Workaround for an Oracle 9i bug witch is unable to convert from Short to NUMERIC but does understand SMALLINT
            oCol = new DBColumn (sName,sColName,(short) Types.SMALLINT, sTypeName, iPrecision, iDigits, iNullable,iColPos);
          }
          else {
            oCol = new DBColumn (sName,sColName,iSQLType,sTypeName,iPrecision,iDigits,iNullable,iColPos);
          }

          // Establecer el comportamiento de no tocar en ningún caso los campos dt_created
          // quitar este if si se desea asignarlos manualmente al insertar cada registro
          if (!sColName.equals(DB.dt_created))
            oColumns.add(oCol);
        } // next

        if (DebugFile.trace) DebugFile.writeln("ResultSet.close()");

        oRSet.close();
        oRSet = null;
        oStmt.close();
        oStmt = null;

        if (5==iDBMS) /* Oracle */ {

          /* getPrimaryKeys() not working properly on some Oracle versions,
             use non portable implementation instead. Sergio 12-01-2004.

          Code until v1.1.4:

          if (DebugFile.trace)
            DebugFile.writeln("DatabaseMetaData.getPrimaryKeys(null, " + sSchema.toUpperCase() + ", " + sName.toUpperCase() + ")");

          oRSet = oMData.getPrimaryKeys(sCatalog, sSchema.toUpperCase(), sName.toUpperCase());
          */

          oStmt = oConn.createStatement();

          if (DebugFile.trace) {
            if (null==sSchema)
              DebugFile.writeln("Statement.executeQuery(SELECT NULL AS TABLE_CAT, COLS.OWNER AS TABLE_SCHEM, COLS.TABLE_NAME, COLS.COLUMN_NAME, COLS.POSITION AS KEY_SEQ, COLS.CONSTRAINT_NAME AS PK_NAME FROM USER_CONS_COLUMNS COLS, USER_CONSTRAINTS CONS WHERE CONS.OWNER=COLS.OWNER AND CONS.CONSTRAINT_NAME=COLS.CONSTRAINT_NAME AND CONS.CONSTRAINT_TYPE='P' AND CONS.TABLE_NAME='" + sName.toUpperCase()+ "')");
            else
              DebugFile.writeln("Statement.executeQuery(SELECT NULL AS TABLE_CAT, COLS.OWNER AS TABLE_SCHEM, COLS.TABLE_NAME, COLS.COLUMN_NAME, COLS.POSITION AS KEY_SEQ, COLS.CONSTRAINT_NAME AS PK_NAME FROM USER_CONS_COLUMNS COLS, USER_CONSTRAINTS CONS WHERE CONS.OWNER=COLS.OWNER AND CONS.CONSTRAINT_NAME=COLS.CONSTRAINT_NAME AND CONS.CONSTRAINT_TYPE='P' AND CONS.OWNER='" + sSchema.toUpperCase() + "' AND CONS.TABLE_NAME='" + sName.toUpperCase()+ "')");
          }

          if (null==sSchema)
            oRSet = oStmt.executeQuery("SELECT NULL AS TABLE_CAT, COLS.OWNER AS TABLE_SCHEM, COLS.TABLE_NAME, COLS.COLUMN_NAME, COLS.POSITION AS KEY_SEQ, COLS.CONSTRAINT_NAME AS PK_NAME FROM USER_CONS_COLUMNS COLS, USER_CONSTRAINTS CONS WHERE CONS.OWNER=COLS.OWNER AND CONS.CONSTRAINT_NAME=COLS.CONSTRAINT_NAME AND CONS.CONSTRAINT_TYPE='P' AND CONS.TABLE_NAME='" + sName.toUpperCase()+ "'");
          else
            oRSet = oStmt.executeQuery("SELECT NULL AS TABLE_CAT, COLS.OWNER AS TABLE_SCHEM, COLS.TABLE_NAME, COLS.COLUMN_NAME, COLS.POSITION AS KEY_SEQ, COLS.CONSTRAINT_NAME AS PK_NAME FROM USER_CONS_COLUMNS COLS, USER_CONSTRAINTS CONS WHERE CONS.OWNER=COLS.OWNER AND CONS.CONSTRAINT_NAME=COLS.CONSTRAINT_NAME AND CONS.CONSTRAINT_TYPE='P' AND CONS.OWNER='" + sSchema.toUpperCase() + "' AND CONS.TABLE_NAME='" + sName.toUpperCase()+ "'");

          // End new code v1.2.0
          }
          else if (10==iDBMS) { // Microsoft Access
            oRSet=null;
          }
          else {
            if (DebugFile.trace)
              DebugFile.writeln("DatabaseMetaData.getPrimaryKeys(" + sCatalog + "," + sSchema + "," + sName + ")");

            oRSet = oMData.getPrimaryKeys(sCatalog, sSchema, sName);
          } // fi (iDBMS)

        if (oRSet!=null) {
          while (oRSet.next()) {
            oPrimaryKeys.add(oRSet.getString(4).toLowerCase());
            sSetPKCols += oRSet.getString(4) + "=? AND ";
          } // wend

          if (DebugFile.trace) DebugFile.writeln("pk cols " + sSetPKCols);

          if (sSetPKCols.length()>7)
            sSetPKCols = sSetPKCols.substring(0, sSetPKCols.length()-5);

          if (DebugFile.trace) DebugFile.writeln("ResultSet.close()");

          oRSet.close();
          oRSet = null;
        } // fi (oRSet)

      if (null!=oStmt) { oStmt.close(); oStmt = null; }

      oColIterator = oColumns.listIterator();

      while (oColIterator.hasNext()) {
        sCol = ((DBColumn) oColIterator.next()).getName();

        sGetAllCols += sCol + ",";
        sSetAllCols += "?,";

        if (!oPrimaryKeys.contains(sCol) && !sCol.equalsIgnoreCase(DB.dt_created))
View Full Code Here

   * @return <b>true</b> if a callback with such name was found and unregistered,
   * <b>false</b> otherwise
   */
  public boolean unregisterCallback(String sCallbackName) {
    WorkerThreadCallback oCallback;
    ListIterator oIter = oCallbacks.listIterator();

    while (oIter.hasNext()) {
      oCallback = (WorkerThreadCallback) oIter.next();

      if (oCallback.name().equals(sCallbackName)) {
        oIter.remove();
        iCallbacks--;
        return true;
      } // fi
    } // wend

View Full Code Here

      DebugFile.writeln("Begin Quotation.createOrder([Connection])");
      DebugFile.incIdent();
    }
    String sSQL;
    Order oOrder = new Order();
    ListIterator oIter = oOrder.getTable(oConn).getColumns().listIterator();
    while (oIter.hasNext()) {
      String sKey = ((DBColumn) oIter.next()).getName();
      if (!isNull(sKey)) {
        if (DebugFile.trace) DebugFile.writeln("Order.put("+sKey+","+get(sKey)+")");
        oOrder.put(sKey, get(sKey));
      }
    } // wend
View Full Code Here

  // ---------------------------------------------------------------------------

  private void callBack (int iOpCode, String sMessage, Exception oXcpt, Object oParam) {

    WorkerThreadCallback oCallback;
    ListIterator oIter = oCallbacks.listIterator();

    while (oIter.hasNext()) {
      oCallback = (WorkerThreadCallback) oIter.next();
      oCallback.call(getName(), iOpCode, sMessage, oXcpt, oParam);
    } // wend

  } // callBack
View Full Code Here

  public DBMatch[] toArray() {
  DBMatch[] aMatches = null;
  Collections.sort(oSortedList, DBMatch.COMPARATOR);
  if (count()>0) {
    aMatches = new DBMatch[count()];
    ListIterator oIter = iterator();
    int m = 0;
    while (oIter.hasNext()) aMatches[m++] = (DBMatch) oIter.next();
  } // fi
  return aMatches;
  } // toArray
View Full Code Here

  }
   
  public String toXML() {
  Collections.sort(oSortedList, DBMatch.COMPARATOR);
    StringBuffer oBuff = new StringBuffer(200*count()+1);
    ListIterator oIter = iterator();
    oBuff.append("<DBMatchSet>\n");
  while (oIter.hasNext()) {
    DBMatch oMatch = (DBMatch) oIter.next();
      oBuff.append("  <DBMatch>\n");
    oBuff.append("    <guid>"+oMatch.guid()+"</guid>\n");
    oBuff.append("    <index>"+String.valueOf(oMatch.index())+"</index>\n");
    oBuff.append("    <grade>"+String.valueOf(oMatch.grade())+"</grade>\n");
    oBuff.append("    <value><![CDATA["+oMatch.matchingValue()+"]]></value>\n");
View Full Code Here

        } // fi
      } // next (r)

      StringBuffer oTermsBuff = new StringBuffer();
   
      ListIterator oIter = oTerms.listIterator();
      while (oIter.hasNext()) {
        Term oChld = (Term) oIter.next();

        oTermsBuff.append("<OPTION VALUE=\"" + oChld.getString(DB.gu_term) + "\">");
        for (int s=1; s<oChld.level(); s++)
          oTermsBuff.append(" ");
        oTermsBuff.append(oChld.getString(DB.tx_term));
View Full Code Here

TOP

Related Classes of java.util.ListIterator

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.