Examples of ListIterator


Examples of java.util.ListIterator

      DebugFile.writeln("Begin TableLoader.store([Connection], "+sWorkArea+","+String.valueOf(iFlags)+")");
      DebugFile.incIdent();
    }

    if (test(iFlags,MODE_UPDATE)) {
      ListIterator oIter = getColumns().listIterator();
      int iPos = 0;
      while (oIter.hasNext()) {
        DBColumn oCol = (DBColumn) oIter.next();
        Integer iUpdtPos = (Integer) oUpdtColPos.get(oCol.getName());
        if (null!=iUpdtPos) {
          jConn.bindParameter(oUpdt, iUpdtPos.intValue(), aValues[iPos], oCol.getSqlType());
        }
        iPos++;
      } // wend
      iAffected = oUpdt.executeUpdate();
    } // fi (MODE_UPDATE)

    if (test(iFlags,MODE_APPEND)) {
      ListIterator oIter = getColumns().listIterator();
      int iPos = 0;
      while (oIter.hasNext()) {
        DBColumn oCol = (DBColumn) oIter.next();
        Integer iInsrPos = (Integer) oInsrColPos.get(oCol.getName());
        if (null!=iInsrPos) {
          jConn.bindParameter(oInsr, iInsrPos.intValue(), aValues[iPos], oCol.getSqlType());
        }
        iPos++;
View Full Code Here

Examples of java.util.ListIterator

    Object[] args = new Object[1];
    args[0] = event;

    // send event to all listeners
    ListIterator iter = listeners.listIterator();
    while (iter.hasNext()) {
      Object client = iter.next();
      try {
        method.invoke(client, args);
      } catch (IllegalAccessException e) {
        logger.error("ListenerManager IllegalAccessException", e);
        iter.remove();
      } catch (IllegalArgumentException e) {
        logger.error("ListenerManager IllegalArgumentException", e);
        iter.remove();
      } catch (InvocationTargetException e) {
        logger.error("ListenerManager InvocationTargetException on " + method+ " threw exception " + e.getTargetException(), e);
        //iter.remove();
        //e.printStackTrace();
      }
View Full Code Here

Examples of java.util.ListIterator

    Object source = event.getSource();
    Object[] args = new Object[1];
    args[0] = event;

    // send event to all listeners except the source
    ListIterator iter = listeners.listIterator();
    while (iter.hasNext()) {
      Object client = iter.next();
      if (client == source)
        continue;

      try {
        method.invoke(client, args);
      } catch (IllegalAccessException e) {
        iter.remove();
        logger.error("ListenerManager IllegalAccessException", e);
      } catch (IllegalArgumentException e) {
        iter.remove();
        logger.error("ListenerManager IllegalArgumentException", e);
      } catch (InvocationTargetException e) {
        iter.remove();
        logger.error("ListenerManager InvocationTargetException on " + method+ " threw exception " + e.getTargetException(), e);
      }
    }
  }
View Full Code Here

Examples of java.util.ListIterator

                                    InetAddress localAddr, int localPort ) {
        SmbTransport conn;

        synchronized( CONNECTIONS ) {
            if( SSN_LIMIT != 1 ) {
                ListIterator iter = CONNECTIONS.listIterator();
                while( iter.hasNext() ) {
                    conn = (SmbTransport)iter.next();
                    if( conn.matches( address, port, localAddr, localPort ) &&
                            ( SSN_LIMIT == 0 || conn.sessions.size() < SSN_LIMIT )) {
                        return conn;
                    }
                }
View Full Code Here

Examples of java.util.ListIterator

        return getSmbSession( new NtlmPasswordAuthentication( null, null, null ));
    }
    synchronized SmbSession getSmbSession( NtlmPasswordAuthentication auth ) {
        SmbSession ssn;

        ListIterator iter = sessions.listIterator();
        while( iter.hasNext() ) {
            ssn = (SmbSession)iter.next();
            if( ssn.matches( auth )) {
                ssn.auth = auth;
                return ssn;
            }
        }
View Full Code Here

Examples of java.util.ListIterator

        if( socket == null ) {
            inError = true;
        }

        ListIterator iter = sessions.listIterator();
        while( iter.hasNext() ) {
            ssn = (SmbSession)iter.next();
            ssn.logoff( inError );
        }
        if( socket != null ) {
            try {
                socket.close();
View Full Code Here

Examples of java.util.ListIterator

                         * with challenge from 'server' to access DFS vol. */
        return dr;
    }
    synchronized DfsReferral lookupReferral( String unc ) {
        DfsReferral dr;
        ListIterator iter = referrals.listIterator();
        int i, len;

        while( iter.hasNext() ) {
            dr = (DfsReferral)iter.next();
            len = dr.path.length();
            for( i = 0; i < len && i < unc.length(); i++ ) {
                if( dr.path.charAt( i ) != unc.charAt( i )) {
                    break;
                }
View Full Code Here

Examples of java.util.ListIterator

    throws SQLException, NullPointerException, IllegalStateException {
    int c;
    boolean bFound;
    Object oVal;
    DBColumn oDBCol;
    ListIterator oColIterator;
    PreparedStatement oStmt = null;
    ResultSet oRSet = null;

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

    if (null==oConn)
      throw new NullPointerException("DBTable.loadRegister() Connection is null");

    if (DebugFile.trace) {
      DebugFile.writeln("Begin DBTable.loadRegister([Connection:"+oConn.pid()+"], Object[], [HashMap])" );
      DebugFile.incIdent();

      boolean bAllNull = true;
      for (int n=0; n<PKValues.length; n++)
        bAllNull &= (PKValues[n]==null);

      if (bAllNull)
        throw new NullPointerException(sName + " cannot retrieve register, value supplied for primary key is NULL.");
    }

    if (sSelect==null) {
      throw new SQLException("Primary key not found", "42S12");
    }

    AllValues.clear();

    bFound = false;

    try {

      if (DebugFile.trace) DebugFile.writeln("  Connection.prepareStatement(" + sSelect + ")");

      // Prepare SELECT sentence for reading
      oStmt = oConn.prepareStatement(sSelect);

      try {
        if (oConn.getDataBaseProduct()!=JDCConnection.DBMS_POSTGRESQL)
          oStmt.setQueryTimeout(10);
      }
      catch (SQLException sqle) {
        if (DebugFile.trace) DebugFile.writeln("Error at PreparedStatement.setQueryTimeout(10)" + sqle.getMessage());
      }


      // Bind primary key values
      for (int p=0; p<oPrimaryKeys.size(); p++) {
        if (DebugFile.trace) DebugFile.writeln("  binding primary key " + PKValues[p] + ".");

        oConn.bindParameter(oStmt, p+1, PKValues[p]);
        //oStmt.setObject(p+1, PKValues[p]);
      } // next

      if (DebugFile.trace) DebugFile.writeln("  Connection.executeQuery()");

      oRSet = oStmt.executeQuery();

      if (oRSet.next()) {
        if (DebugFile.trace) DebugFile.writeln("  ResultSet.next()");

        bFound = true;

        // Iterate throught readed columns
        // and store readed values at AllValues
        oColIterator = oColumns.listIterator();

        c = 1;
        while (oColIterator.hasNext()) {
          oVal = oRSet.getObject(c++);
          oDBCol = (DBColumn) oColIterator.next();
          if (null!=oVal)
            AllValues.put(oDBCol.getName(), oVal);
        }
      }
View Full Code Here

Examples of java.util.ListIterator

    int c;
    boolean bNewRow = false;
    DBColumn oCol;
    String sCol;
    String sSQL = "";
    ListIterator oColIterator;
    int iAffected = 0;
    PreparedStatement oStmt = null;

    if (null==oConn)
      throw new NullPointerException("DBTable.storeRegister() Connection is null");

    if (DebugFile.trace)
      {
      DebugFile.writeln("Begin DBTable.storeRegister([Connection:"+oConn.pid()+"], {" + AllValues.toString() + "})" );
      DebugFile.incIdent();
      }

    try {
      if (null!=sUpdate) {
        if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sUpdate + ")");

        sSQL = sUpdate;

        oStmt = oConn.prepareStatement(sSQL);

        try {
          if (oConn.getDataBaseProduct()!=JDCConnection.DBMS_POSTGRESQL)
          oStmt.setQueryTimeout(10);
        } catch (SQLException sqle) {
          if (DebugFile.trace) DebugFile.writeln("Error at PreparedStatement.setQueryTimeout(10)" + sqle.getMessage());
        }

        c = 1;
        oColIterator = oColumns.listIterator();

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

          if (!oPrimaryKeys.contains(sCol) &&
              (sCol.compareTo(DB.dt_created)!=0)) {

            if (DebugFile.trace) {
              if (oCol.getSqlType()==java.sql.Types.CHAR || oCol.getSqlType()==java.sql.Types.VARCHAR) {

                if (AllValues.get(sCol)!=null) {
                  DebugFile.writeln("Binding " + sCol + "=" + AllValues.get(sCol).toString());

                  if (AllValues.get(sCol).toString().length() > oCol.getPrecision())
                    DebugFile.writeln("ERROR: value for " + oCol.getName() + " exceeds columns precision of " + String.valueOf(oCol.getPrecision()));
                } // fi (AllValues.get(sCol)!=null)
                else
                  DebugFile.writeln("Binding " + sCol + "=NULL");
              }
            } // fi (DebugFile.trace)

            try {
              oConn.bindParameter (oStmt, c, AllValues.get(sCol), oCol.getSqlType());
              c++;
            } catch (ClassCastException e) {
                if (AllValues.get(sCol)!=null)
                  throw new SQLException("ClassCastException at column " + sCol + " Cannot cast Java " + AllValues.get(sCol).getClass().getName() + " to SQL type " + oCol.getSqlTypeName(), "07006");
                else
                  throw new SQLException("ClassCastException at column " + sCol + " Cannot cast NULL to SQL type " + oCol.getSqlTypeName(), "07006");
            }

            } // endif (!oPrimaryKeys.contains(sCol))
          } // wend

        oColIterator = oPrimaryKeys.listIterator();
        while (oColIterator.hasNext()) {
          sCol = (String) oColIterator.next();
          oCol = getColumnByName(sCol);

          if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject (" + String.valueOf(c) + "," + AllValues.get(sCol) + "," + oCol.getSqlTypeName() + ")");

          oConn.bindParameter (oStmt, c, AllValues.get(sCol), oCol.getSqlType());
          c++;
        } // wend

        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate()");

    try {
          iAffected = oStmt.executeUpdate();
    } catch (SQLException sqle) {
          if (DebugFile.trace) {
            DebugFile.writeln("SQLException "+sqle.getMessage());
            DebugFile.decIdent();
          }
      oStmt.close();
      throw new SQLException(sqle.getMessage(), sqle.getSQLState(), sqle.getErrorCode());
    }

        if (DebugFile.trace) DebugFile.writeln(String.valueOf(iAffected) " affected rows");

        oStmt.close();
        oStmt = null;
      } // fi (sUpdate!=null)
      else
        iAffected = 0;

      if (0==iAffected)
          {
          bNewRow = true;

          if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sInsert + ")");

          sSQL = sInsert;

          oStmt = oConn.prepareStatement(sInsert);

          try { if (oConn.getDataBaseProduct()!=JDCConnection.DBMS_POSTGRESQL) oStmt.setQueryTimeout(10); } catch (SQLException sqle) { if (DebugFile.trace) DebugFile.writeln("Error at PreparedStatement.setQueryTimeout(10)" + sqle.getMessage()); }

          c = 1;
          oColIterator = oColumns.listIterator();

          while (oColIterator.hasNext()) {

            oCol  = (DBColumn)oColIterator.next();
            sCol = oCol.getName();

            if (DebugFile.trace) {
              if (null!=AllValues.get(sCol))
                DebugFile.writeln("Binding " + sCol + "=" + AllValues.get(sCol).toString());
View Full Code Here

Examples of java.util.ListIterator

  public boolean storeRegisterLong(JDCConnection oConn, HashMap AllValues, HashMap BinaryLengths) throws IOException, SQLException {
    int c;
    boolean bNewRow = false;
    DBColumn oCol;
    String sCol;
    ListIterator oColIterator;
    PreparedStatement oStmt;
    int iAffected;

    LinkedList oStreams;
    InputStream oStream;
    String sClassName;

    if (null==oConn)
      throw new NullPointerException("DBTable.storeRegisterLong() Connection is null");

    if (DebugFile.trace)
      {
      DebugFile.writeln("Begin DBTable.storeRegisterLong([Connection:"+oConn.pid()+"], {" + AllValues.toString() + "})" );
      DebugFile.incIdent();
      }

    oStreams  = new LinkedList();

    if (null!=sUpdate) {

      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sUpdate + ")");

      oStmt = oConn.prepareStatement(sUpdate);

      try { if (oConn.getDataBaseProduct()!=JDCConnection.DBMS_POSTGRESQL) oStmt.setQueryTimeout(10); } catch (SQLException sqle) { if (DebugFile.trace) DebugFile.writeln("Error at PreparedStatement.setQueryTimeout(10)" + sqle.getMessage()); }

      c = 1;
      oColIterator = oColumns.listIterator();
      while (oColIterator.hasNext()) {
        oCol = (DBColumn) oColIterator.next();
        sCol = oCol.getName().toLowerCase();

        if (!oPrimaryKeys.contains(sCol) &&
            (!sCol.equalsIgnoreCase(DB.dt_created))) {

          if (DebugFile.trace) {
            if (oCol.getSqlType()==java.sql.Types.CHAR || oCol.getSqlType()==java.sql.Types.VARCHAR) {
              if (AllValues.get(sCol) != null) {
                DebugFile.writeln("Binding " + sCol + "=" +
                                  AllValues.get(sCol).toString());
                if (AllValues.get(sCol).toString().length() > oCol.getPrecision())
                  DebugFile.writeln("ERROR: value for " + oCol.getName() +
                                    " exceeds columns precision of " +
                                    String.valueOf(oCol.getPrecision()));
              } // fi (AllValues.get(sCol)!=null)
              else
                DebugFile.writeln("Binding " + sCol + "=NULL");
            }
          } // fi (DebugFile.trace)

          if (oCol.getSqlType()==java.sql.Types.LONGVARCHAR || oCol.getSqlType()==java.sql.Types.CLOB || oCol.getSqlType()==java.sql.Types.LONGVARBINARY || oCol.getSqlType()==java.sql.Types.BLOB) {
            if (BinaryLengths.containsKey(sCol)) {
              if (((Long)BinaryLengths.get(sCol)).intValue()>0) {
                sClassName = AllValues.get(sCol).getClass().getName();
                if (sClassName.equals("java.io.File"))
                  oStream = new FileInputStream((File) AllValues.get(sCol));
                else if (sClassName.equals("[B"))
                  oStream = new ByteArrayInputStream((byte[]) AllValues.get(sCol));
                else if (sClassName.equals("[C"))
                  oStream = new StringBufferInputStream(new String((char[]) AllValues.get(sCol)));
                else {
                  Class[] aInts = AllValues.get(sCol).getClass().getInterfaces();
                  if (aInts==null) {
                    throw new SQLException ("Invalid object binding for column " + sCol);
                  } else {
                    boolean bSerializable = false;
                    for (int i=0; i<aInts.length &!bSerializable; i++)
                      bSerializable |= aInts[i].getName().equals("java.io.Serializable");
                    if (bSerializable) {
                      ByteArrayOutputStream oBOut = new ByteArrayOutputStream();
                      ObjectOutputStream oOOut = new ObjectOutputStream(oBOut);
                      oOOut.writeObject(AllValues.get(sCol));
                      oOOut.close();
                      ByteArrayInputStream oBin = new ByteArrayInputStream(oBOut.toByteArray());
                      oStream = new ObjectInputStream(oBin);                   
                    } else {
                      throw new SQLException ("Invalid object binding for column " + sCol);                     
                    }
                  } // fi
                }
                oStreams.addLast(oStream);
                oStmt.setBinaryStream(c++, oStream, ((Long)BinaryLengths.get(sCol)).intValue());
              }
              else
                oStmt.setObject (c++, null, oCol.getSqlType());
            }
            else
             oStmt.setObject (c++, null, oCol.getSqlType());
          }
          else
            oConn.bindParameter (oStmt, c++, AllValues.get(sCol), oCol.getSqlType());
          } // fi (!oPrimaryKeys.contains(sCol))
        } // wend

      oColIterator = oPrimaryKeys.listIterator();
      while (oColIterator.hasNext()) {
        sCol = (String) oColIterator.next();
        oCol = getColumnByName(sCol);

        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.setObject (" + String.valueOf(c) + "," + AllValues.get(sCol) + "," + oCol.getSqlTypeName() + ")");

        oConn.bindParameter (oStmt, c, AllValues.get(sCol), oCol.getSqlType());
        c++;
      } // wend

      if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate()");

      iAffected = oStmt.executeUpdate();

      if (DebugFile.trace) DebugFile.writeln(String.valueOf(iAffected) " affected rows");

      oStmt.close();

      oColIterator = oStreams.listIterator();

      while (oColIterator.hasNext())
        ((InputStream) oColIterator.next()).close();

      oStreams.clear();

    }
    else
      iAffected = 0;

    if (0==iAffected)
        {
        bNewRow = true;

        if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sInsert + ")");

        oStmt = oConn.prepareStatement(sInsert);

        c = 1;
        oColIterator = oColumns.listIterator();

        while (oColIterator.hasNext()) {

          oCol  = (DBColumn)oColIterator.next();
          sCol = oCol.getName();

          if (DebugFile.trace) {
            if (null!=AllValues.get(sCol))
              DebugFile.writeln("Binding " + sCol + "=" + AllValues.get(sCol).toString());
            else
              DebugFile.writeln("Binding " + sCol + "=NULL");
          }

          if (oCol.getSqlType()==java.sql.Types.LONGVARCHAR || oCol.getSqlType()==java.sql.Types.CLOB || oCol.getSqlType()==java.sql.Types.LONGVARBINARY || oCol.getSqlType()==java.sql.Types.BLOB) {
            if (BinaryLengths.containsKey(sCol)) {
              if ( ( (Long) BinaryLengths.get(sCol)).intValue() > 0) {
                sClassName = AllValues.get(sCol).getClass().getName();
                if (sClassName.equals("java.io.File"))
                  oStream = new FileInputStream((File) AllValues.get(sCol));
                else if (sClassName.equals("[B"))
                  oStream = new ByteArrayInputStream((byte[]) AllValues.get(sCol));
                else if (sClassName.equals("[C"))
                  oStream = new StringBufferInputStream(new String((char[]) AllValues.get(sCol)));
                else {
                  Class[] aInts = AllValues.get(sCol).getClass().getInterfaces();
                  if (aInts==null) {
                    throw new SQLException ("Invalid object binding for column " + sCol);
                  } else {
                    boolean bSerializable = false;
                    for (int i=0; i<aInts.length &!bSerializable; i++)
                      bSerializable |= aInts[i].getName().equals("java.io.Serializable");
                    if (bSerializable) {
                      ByteArrayOutputStream oBOut = new ByteArrayOutputStream();
                      ObjectOutputStream oOOut = new ObjectOutputStream(oBOut);
                      oOOut.writeObject(AllValues.get(sCol));
                      oOOut.close();
                      ByteArrayInputStream oBin = new ByteArrayInputStream(oBOut.toByteArray());
                      oStream = new ObjectInputStream(oBin);                   
                    } else {
                      throw new SQLException ("Invalid object binding for column " + sCol);                     
                    }
                  } // fi
                }
                oStreams.addLast(oStream);
                oStmt.setBinaryStream(c++, oStream, ((Long) BinaryLengths.get(sCol)).intValue());
              }
              else
                oStmt.setObject(c++, null, oCol.getSqlType());
            }
            else
              oStmt.setObject(c++, null, oCol.getSqlType());
          }
          else
            oConn.bindParameter (oStmt, c++, AllValues.get(sCol), oCol.getSqlType());
        } // wend

        if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate()");

        iAffected = oStmt.executeUpdate();

        if (DebugFile.trace) DebugFile.writeln(String.valueOf(iAffected) " affected rows");

        oStmt.close();

        oColIterator = oStreams.listIterator();

        while (oColIterator.hasNext())
          ((InputStream) oColIterator.next()).close();

        oStreams.clear();
    }

    else
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.