db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r409797 [3/4] - in /db/derby/code/trunk/java/drda/org/apache/derby/impl/drda: DDMWriter.java DRDAConnThread.java EXTDTAInputStream.java
Date Sat, 27 May 2006 02:20:30 GMT
Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=409797&r1=409796&r2=409797&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Fri May 26 19:20:29 2006
@@ -207,57 +207,51 @@
 	    trace("Starting new connection thread");
 
 	Session prevSession;
-	while(!closed())
-	    {
+	while(!closed()) {
 
-		// get a new session
-		prevSession = session;
-		session = server.getNextSession(session);
-		if (session == null)
-		    close();
+	    // get a new session
+	    prevSession = session;
+	    session = server.getNextSession(session);
+	    if (session == null)
+		close();
 
-		if (closed())
-		    break;
-		if (session != prevSession)
-		    {
-			initializeForSession();
-		    }
-		try {
-		    long timeStart = System.currentTimeMillis();
+	    if (closed())
+		break;
+	    if (session != prevSession) {
+		initializeForSession();
+	    }
+	    try {
+		long timeStart = System.currentTimeMillis();
 
-		    switch (session.state)
-			{
-			case Session.INIT:
-			    sessionInitialState();
-			    if (session == null)
-				break;
-			case Session.ATTEXC:
-			    long currentTimeSlice;
-
-			    do {
-				processCommands();
-				currentTimeSlice = getTimeSlice();
-			    } while ((currentTimeSlice == 0)  || 
-				     (System.currentTimeMillis() - timeStart < currentTimeSlice));
-
-			    break;
-			default:
-			    // this is an error
-			    agentError("Session in invalid state:" + session.state);
-			}
-		} catch (Exception e) {
-		    if (e instanceof DRDAProtocolException && 
-			((DRDAProtocolException)e).isDisconnectException())
-			{
-			    // client went away - this is O.K. here
-			    closeSession();
-			}
-		    else
-			{
-			    handleException(e);
-			}
+		switch (session.state) {
+		case Session.INIT:
+		    sessionInitialState();
+		    if (session == null)
+			break;
+		case Session.ATTEXC:
+		    long currentTimeSlice;
+
+		    do {
+			processCommands();
+			currentTimeSlice = getTimeSlice();
+		    } while ((currentTimeSlice == 0)  || 
+			     (System.currentTimeMillis() - timeStart < currentTimeSlice));
+
+		    break;
+		default:
+		    // this is an error
+		    agentError("Session in invalid state:" + session.state);
+		}
+	    } catch (Exception e) {
+		if (e instanceof DRDAProtocolException && 
+		    ((DRDAProtocolException)e).isDisconnectException()) {
+		    // client went away - this is O.K. here
+		    closeSession();
+		} else {
+		    handleException(e);
 		}
 	    }
+	}
 	if (SanityManager.DEBUG)
 	    trace("Ending connection thread");
 	server.getThreadList().removeElement(this);
@@ -268,8 +262,7 @@
      *
      * @return input stream
      */
-    protected InputStream getInputStream()
-    {
+    protected InputStream getInputStream() {
 	return sockis;
     }
 
@@ -278,8 +271,7 @@
      *
      * @return output stream
      */
-    protected OutputStream getOutputStream()
-    {
+    protected OutputStream getOutputStream() {
 	return sockos;
     }
 
@@ -287,8 +279,7 @@
      *  get DDMReader
      * @return DDMReader for this thread
      */
-    protected DDMReader getReader()
-    {
+    protected DDMReader getReader() {
 	return reader;
     }
 	
@@ -296,8 +287,7 @@
      * get  DDMWriter 
      * @return DDMWriter for this thread
      */
-    protected DDMWriter getWriter()
-    {
+    protected DDMWriter getWriter() {
 	return writer;
     }
 
@@ -306,8 +296,7 @@
      *
      * @return correlation id
      */
-    protected int getCorrelationID ()
-    {
+    protected int getCorrelationID () {
 	return correlationID;
     }
 
@@ -316,8 +305,7 @@
      *
      * @return session
      */
-    protected Session getSession()
-    {
+    protected Session getSession() {
 	return session;
     }
 
@@ -326,8 +314,7 @@
      *
      * @return database
      */
-    protected Database getDatabase()
-    {
+    protected Database getDatabase() {
 	return database;
     }
     /**
@@ -335,8 +322,7 @@
      *
      * @return server
      */
-    protected NetworkServerControlImpl getServer()
-    {
+    protected NetworkServerControlImpl getServer() {
 	return server;
     }
     /**
@@ -344,8 +330,7 @@
      *
      * @return crrtkn
      */
-    protected byte[] getCrrtkn()
-    {
+    protected byte[] getCrrtkn() {
 	if (database != null)
 	    return database.crrtkn;
 	return null;
@@ -355,8 +340,7 @@
      *
      * @return database name
      */
-    protected String getDbName()
-    {
+    protected String getDbName() {
 	if (database != null)
 	    return database.dbName;
 	return null;
@@ -364,12 +348,10 @@
     /**
      * Close DRDA  connection thread
      */
-    protected void close()
-    {
-	synchronized (closeSync)
-	    {
-		close = true;
-	    }
+    protected void close() {
+	synchronized (closeSync) {
+	    close = true;
+	}
     }
 
     /**
@@ -377,8 +359,7 @@
      * 
      * @param value value to set for logging connections
      */
-    protected void setLogConnections(boolean value)
-    {
+    protected void setLogConnections(boolean value) {
 	synchronized(logConnectionsSync) {
 	    logConnections = value;
 	}
@@ -388,8 +369,7 @@
      *
      * @param value new value for time slice
      */
-    protected void setTimeSlice(long value)
-    {
+    protected void setTimeSlice(long value) {
 	synchronized(timeSliceSync) {
 	    timeSlice = value;
 	}
@@ -405,8 +385,7 @@
      * @exception DRDAProtocolException  disconnect exception always thrown
      */
     protected void markCommunicationsFailure(String arg1, String arg2, String arg3,
-					     String arg4) throws DRDAProtocolException
-    {
+					     String arg4) throws DRDAProtocolException {
 	Object[] oa = {arg1,arg2,arg3,arg4};
 	throw DRDAProtocolException.newDisconnectException(this,oa);
 
@@ -420,8 +399,7 @@
      */
 
     protected  void throwSyntaxrm(int errcd, int cpArg)
-	throws DRDAProtocolException
-    {
+	throws DRDAProtocolException {
 	throw new
 	    DRDAProtocolException(DRDAProtocolException.DRDA_Proto_SYNTAXRM,
 				  this,
@@ -435,8 +413,7 @@
      *
      * @exception DRDAProtocolException  newAgentError always thrown
      */
-    protected void agentError(String msg) throws DRDAProtocolException
-    {
+    protected void agentError(String msg) throws DRDAProtocolException {
 
 	String dbname = null;
 	if (database != null)
@@ -450,8 +427,7 @@
      * @param codePoint  code point value
      * @exception DRDAProtocolException
      */
-    protected void missingCodePoint(int codePoint) throws DRDAProtocolException
-    {
+    protected void missingCodePoint(int codePoint) throws DRDAProtocolException {
 	throwSyntaxrm(CodePoint.SYNERRCD_REQ_OBJ_NOT_FOUND, codePoint);
     }
     /**
@@ -461,17 +437,15 @@
      * @param drdaID	DRDA identifier
      * @param msg	message
      */
-    protected static void println2Log(String dbname, String drdaID, String msg)
-    {
+    protected static void println2Log(String dbname, String drdaID, String msg) {
 	if (logStream == null)
 	    logStream = Monitor.getStream();
 
-	if (dbname != null)
-	    {
-		int endOfName = dbname.indexOf(';');
-		if (endOfName != -1)
-		    dbname = dbname.substring(0, endOfName);
-	    }
+	if (dbname != null) {
+	    int endOfName = dbname.indexOf(';');
+	    if (endOfName != -1)
+		dbname = dbname.substring(0, endOfName);
+	}
 	logStream.printlnWithHeader("(DATABASE = " + dbname + "), (DRDAID = " + drdaID + "), " + msg);
     }
     /**
@@ -481,8 +455,7 @@
      * @exception DRDAProtocolException
      */
     protected void writeRDBNAM(String rdbnam)
-	throws DRDAProtocolException
-    {
+	throws DRDAProtocolException {
 	int len = rdbnam.length();
 	if (len < CodePoint.RDBNAM_LEN)
 	    len = CodePoint.RDBNAM_LEN;
@@ -490,12 +463,10 @@
 	try {
 	    writer.writeScalarPaddedBytes(rdbnam.getBytes(server.DEFAULT_ENCODING),
 					  len, server.SPACE_CHAR);
+	} catch (UnsupportedEncodingException e) {
+	    agentError("Unsupported coding exception for server encoding "
+		       + server.DEFAULT_ENCODING);
 	}
-	catch (UnsupportedEncodingException e)
-	    {
-		agentError("Unsupported coding exception for server encoding "
-			   + server.DEFAULT_ENCODING);
-	    }
     }
     /***************************************************************************
      *                   Private methods
@@ -504,8 +475,7 @@
     /**
      * Initialize class
      */
-    private void initialize()
-    {
+    private void initialize() {
 	// set input and output sockets
 	// this needs to be done before creating reader
 	sockis = session.sessionInput;
@@ -518,8 +488,7 @@
     /**
      * Initialize for a new session
      */
-    private void initializeForSession()
-    {
+    private void initializeForSession() {
 	// set input and output sockets
 	sockis = session.sessionInput;
 	sockos = session.sessionOutput;
@@ -547,33 +516,28 @@
      * state.
      */
     private void sessionInitialState()
-	throws Exception
-    {
+	throws Exception {
 	// process NetworkServerControl commands - if it is not either valid protocol  let the 
 	// DRDA error handling handle it
-	if (reader.isCmd())
-	    {
-		try {
-		    server.processCommands(reader, writer, session);
-		    // reset reader and writer
-		    reader.initialize(this, null);
-		    writer.reset(null);
-		    closeSession();
-		} catch (Throwable t) {
-		    if (t instanceof InterruptedException)
-			throw (InterruptedException)t;
-		    else
-			{
-			    server.consoleExceptionPrintTrace(t);
-			}
+	if (reader.isCmd()) {
+	    try {
+		server.processCommands(reader, writer, session);
+		// reset reader and writer
+		reader.initialize(this, null);
+		writer.reset(null);
+		closeSession();
+	    } catch (Throwable t) {
+		if (t instanceof InterruptedException)
+		    throw (InterruptedException)t;
+		else {
+		    server.consoleExceptionPrintTrace(t);
 		}
-
-	    }
-	else
-	    {
-		// exchange attributes with application requester
-		exchangeServerAttributes();
 	    }
+
+	} else {
+	    // exchange attributes with application requester
+	    exchangeServerAttributes();
+	}
     }
 
     /**
@@ -590,8 +554,7 @@
     private void cleanUpAndCloseResultSet(DRDAStatement stmt,
                                           SQLException sqle,
                                           int writerMark)
-        throws DRDAProtocolException
-    {
+        throws DRDAProtocolException {
         if (stmt != null) {
             writer.clearDSSesBackToMark(writerMark);
             if (!stmt.rsIsClosed()) {
@@ -617,329 +580,302 @@
      *
      * @exception DRDAProtocolException
      */
-    private void processCommands() throws DRDAProtocolException
-    {
+    private void processCommands() throws DRDAProtocolException {
 	DRDAStatement stmt = null;
 	int updateCount = 0;
 	boolean PRPSQLSTTfailed = false;
 	boolean checkSecurityCodepoint = session.requiresSecurityCodepoint();
-	do
-	    {
-		correlationID = reader.readDssHeader();
-		int codePoint = reader.readLengthAndCodePoint();
-		int writerMark = writer.markDSSClearPoint();
+	do {
+	    correlationID = reader.readDssHeader();
+	    int codePoint = reader.readLengthAndCodePoint();
+	    int writerMark = writer.markDSSClearPoint();
 			
-		if (checkSecurityCodepoint)
-		    verifyInOrderACCSEC_SECCHK(codePoint,session.getRequiredSecurityCodepoint());
+	    if (checkSecurityCodepoint)
+		verifyInOrderACCSEC_SECCHK(codePoint,session.getRequiredSecurityCodepoint());
 
-		switch(codePoint)
-		    {
-		    case CodePoint.CNTQRY:
-			try{
-			    stmt = parseCNTQRY();
-			    if (stmt != null)
-				{
-				    writeQRYDTA(stmt);
-				    if (stmt.rsIsClosed())
-					{
-					    writeENDQRYRM(CodePoint.SVRCOD_WARNING);
-					    writeNullSQLCARDobject();
-					}
-				    // Send any warnings if JCC can handle them
-				    checkWarning(null, null, stmt.getResultSet(), 0, false, sendWarningsOnCNTQRY);
-				}
+	    switch(codePoint) {
+	    case CodePoint.CNTQRY:
+		try{
+		    stmt = parseCNTQRY();
+		    if (stmt != null) {
+			writeQRYDTA(stmt);
+			if (stmt.rsIsClosed()) {
+			    writeENDQRYRM(CodePoint.SVRCOD_WARNING);
+			    writeNullSQLCARDobject();
 			}
-			catch(SQLException e)
-			    {
-				// if we got a SQLException we need to clean up and
-				// close the result set Beetle 4758
-				cleanUpAndCloseResultSet(stmt, e, writerMark);
-			    }
-			break;
-		    case CodePoint.EXCSQLIMM:
-			try {
-			    updateCount = parseEXCSQLIMM();
-			    // RESOLVE: checking updateCount is not sufficient
-			    // since it will be 0 for creates, we need to know when
-			    // any logged changes are made to the database
-			    // Not getting this right for JCC is probably O.K., this
-			    // will probably be a problem for ODBC and XA
-			    // The problem is that JDBC doesn't provide this information
-			    // so we would have to expand the JDBC API or call a
-			    // builtin method to check(expensive)
-			    // For now we will assume that every execute immediate
-			    // does an update (that is the most conservative thing)
-			    if (database.RDBUPDRM_sent == false)
-				{
-				    writeRDBUPDRM();
-				}
+			// Send any warnings if JCC can handle them
+			checkWarning(null, null, stmt.getResultSet(), 0, false, sendWarningsOnCNTQRY);
+		    }
+		}
+		catch(SQLException e) {
+		    // if we got a SQLException we need to clean up and
+		    // close the result set Beetle 4758
+		    cleanUpAndCloseResultSet(stmt, e, writerMark);
+		}
+		break;
+	    case CodePoint.EXCSQLIMM:
+		try {
+		    updateCount = parseEXCSQLIMM();
+		    // RESOLVE: checking updateCount is not sufficient
+		    // since it will be 0 for creates, we need to know when
+		    // any logged changes are made to the database
+		    // Not getting this right for JCC is probably O.K., this
+		    // will probably be a problem for ODBC and XA
+		    // The problem is that JDBC doesn't provide this information
+		    // so we would have to expand the JDBC API or call a
+		    // builtin method to check(expensive)
+		    // For now we will assume that every execute immediate
+		    // does an update (that is the most conservative thing)
+		    if (database.RDBUPDRM_sent == false) {
+			writeRDBUPDRM();
+		    }
+
+		    // we need to set update count in SQLCARD
+		    checkWarning(null, database.getDefaultStatement().getStatement(),
+				 null, updateCount, true, true);
+		} catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    writeSQLCARDs(e, 0);
+		    errorInChain(e);
+		}
+		break;
 
-			    // we need to set update count in SQLCARD
-			    checkWarning(null, database.getDefaultStatement().getStatement(),
-					 null, updateCount, true, true);
-			} catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				writeSQLCARDs(e, 0);
-				errorInChain(e);
-			    }
-			break;
+	    case CodePoint.EXCSQLSET:
+		try {
+		    if (parseEXCSQLSET())
+			// all went well.
+			writeSQLCARDs(null,0);
+		} catch (SQLWarning w) {
+		    writeSQLCARD(w, CodePoint.SVRCOD_WARNING, 0, 0);
+		} catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    writeSQLCARDs(e, 0);
+		    errorInChain(e);
+		}
+		break;
+					
+	    case CodePoint.PRPSQLSTT:
+		int sqldaType;
+		PRPSQLSTTfailed = false;
+		try {
+		    database.getConnection().clearWarnings();
+		    sqldaType = parsePRPSQLSTT();
+		    if (sqldaType > 0)		// do write SQLDARD
+			writeSQLDARD(database.getCurrentStatement(),
+				     (sqldaType ==  CodePoint.TYPSQLDA_LIGHT_OUTPUT),
+				     database.getConnection().getWarnings());
+		    else
+			checkWarning(database.getConnection(), null, null, 0, true, true);
 
-		    case CodePoint.EXCSQLSET:
-			try {
-			    if (parseEXCSQLSET())
-				// all went well.
-				writeSQLCARDs(null,0);
+		} catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    writeSQLCARDs(e, 0, true);
+		    PRPSQLSTTfailed = true;
+		    errorInChain(e);
+		}
+		break;
+	    case CodePoint.OPNQRY:
+		PreparedStatement ps = null;
+		try {
+		    if (PRPSQLSTTfailed) {
+			// read the command objects
+			// for ps with parameter
+			// Skip objects/parameters
+			skipRemainder(true);
+
+			// If we failed to prepare, then we fail
+			// to open, which  means OPNQFLRM.
+			writeOPNQFLRM(null);
+			break;
+		    }
+		    Pkgnamcsn pkgnamcsn = parseOPNQRY();
+		    if (pkgnamcsn != null) {
+			stmt = database.getDRDAStatement(pkgnamcsn);
+			ps = stmt.getPreparedStatement();
+			ps.clearWarnings();
+			if (pendingStatementTimeout >= 0) {
+			    ps.setQueryTimeout(pendingStatementTimeout);
+			    pendingStatementTimeout = -1;
 			}
-			catch (SQLWarning w)
-			    {
-				writeSQLCARD(w, CodePoint.SVRCOD_WARNING, 0, 0);
-			    }
-			catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				writeSQLCARDs(e, 0);
-				errorInChain(e);
-			    }
-			break;
-					
-		    case CodePoint.PRPSQLSTT:
-			int sqldaType;
-			PRPSQLSTTfailed = false;
-			try {
-			    database.getConnection().clearWarnings();
-			    sqldaType = parsePRPSQLSTT();
-			    if (sqldaType > 0)		// do write SQLDARD
-				writeSQLDARD(database.getCurrentStatement(),
-					     (sqldaType ==  CodePoint.TYPSQLDA_LIGHT_OUTPUT),
-					     database.getConnection().getWarnings());
-			    else
-				checkWarning(database.getConnection(), null, null, 0, true, true);
-
-			} catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				writeSQLCARDs(e, 0, true);
-				PRPSQLSTTfailed = true;
-				errorInChain(e);
-			    }
-			break;
-		    case CodePoint.OPNQRY:
-			PreparedStatement ps = null;
-			try {
-			    if (PRPSQLSTTfailed) {
-				// read the command objects
-				// for ps with parameter
-				// Skip objects/parameters
-				skipRemainder(true);
-
-				// If we failed to prepare, then we fail
-				// to open, which  means OPNQFLRM.
-				writeOPNQFLRM(null);
-				break;
-			    }
-			    Pkgnamcsn pkgnamcsn = parseOPNQRY();
-			    if (pkgnamcsn != null)
-				{
-				    stmt = database.getDRDAStatement(pkgnamcsn);
-				    ps = stmt.getPreparedStatement();
-				    ps.clearWarnings();
-				    if (pendingStatementTimeout >= 0) {
-					ps.setQueryTimeout(pendingStatementTimeout);
-					pendingStatementTimeout = -1;
-				    }
-				    stmt.execute();
-				    writeOPNQRYRM(false, stmt);
-				    checkWarning(null, ps, null, 0, false, true);
-
-				    writeQRYDSC(stmt, false);
-
-				    stmt.rsSuspend();
-
-				    if (stmt.getQryprctyp() == CodePoint.LMTBLKPRC) {
-					// The DRDA spec allows us to send
-					// QRYDTA here if there are no LOB
-					// columns.
-					DRDAResultSet drdars =
-					    stmt.getCurrentDrdaResultSet();
-					try {
-					    if (drdars != null &&
-						!drdars.hasLobColumns()) {
-						writeQRYDTA(stmt);
-					    }
-					} catch (SQLException sqle) {
-					    cleanUpAndCloseResultSet(stmt, sqle,
-								     writerMark);
-					}
-				    }
+			stmt.execute();
+			writeOPNQRYRM(false, stmt);
+			checkWarning(null, ps, null, 0, false, true);
+
+			writeQRYDSC(stmt, false);
+
+			stmt.rsSuspend();
+
+			if (stmt.getQryprctyp() == CodePoint.LMTBLKPRC) {
+			    // The DRDA spec allows us to send
+			    // QRYDTA here if there are no LOB
+			    // columns.
+			    DRDAResultSet drdars =
+				stmt.getCurrentDrdaResultSet();
+			    try {
+				if (drdars != null &&
+				    !drdars.hasLobColumns()) {
+				    writeQRYDTA(stmt);
 				}
-			}
-			catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				// The fix for DERBY-1196 removed code 
-				// here to close the prepared statement 
-				// if OPNQRY failed.
-				writeOPNQFLRM(e);
-			    }
-			break;
-		    case CodePoint.RDBCMM:
-			try
-			    {
-				if (SanityManager.DEBUG)
-				    trace("Received commit");
-				if (!database.getConnection().getAutoCommit())
-				    {
-					database.getConnection().clearWarnings();
-					database.commit();
-					writeENDUOWRM(COMMIT);
-					checkWarning(database.getConnection(), null, null, 0, true, true);
-				    }
-				// we only want to write one of these per transaction
-				// so set to false in preparation for next command
-				database.RDBUPDRM_sent = false;
-			    }
-			catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				// Even in case of error, we have to write the ENDUOWRM.
-				writeENDUOWRM(COMMIT);
-				writeSQLCARDs(e, 0);
-				errorInChain(e);
-			    }
-			break;
-		    case CodePoint.RDBRLLBCK:
-			try
-			    {
-				if (SanityManager.DEBUG)
-				    trace("Received rollback");
-				database.getConnection().clearWarnings();
-				database.rollback();
-				writeENDUOWRM(ROLLBACK);
-				checkWarning(database.getConnection(), null, null, 0, true, true);
-				// we only want to write one of these per transaction
-				// so set to false in preparation for next command
-				database.RDBUPDRM_sent = false;
-			    }
-			catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				// Even in case of error, we have to write the ENDUOWRM.
-				writeENDUOWRM(ROLLBACK);
-				writeSQLCARDs(e, 0);
-				errorInChain(e);
+			    } catch (SQLException sqle) {
+				cleanUpAndCloseResultSet(stmt, sqle,
+							 writerMark);
 			    }
-			break;
-		    case CodePoint.CLSQRY:
-			try{
-			    stmt = parseCLSQRY();
-			    stmt.rsClose();
-			    writeSQLCARDs(null, 0);
-			}
-			catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				writeSQLCARDs(e, 0);
-				errorInChain(e);
-			    }
-			break;
-		    case CodePoint.EXCSAT:
-			parseEXCSAT();
-			writeEXCSATRD();
-			break;
-		    case CodePoint.ACCSEC:
-			int securityCheckCode = parseACCSEC();
-			writeACCSECRD(securityCheckCode); 
-			checkSecurityCodepoint = true;
-			break;
-		    case CodePoint.SECCHK:
-			if(parseDRDAConnection())
-			    // security all checked and connection ok
-			    checkSecurityCodepoint = false;
-			break;
-			/* since we don't support sqlj, we won't get bind commands from jcc, we
-			 * might get it from ccc; just skip them.
-			 */
-		    case CodePoint.BGNBND:
-			reader.skipBytes();
-			writeSQLCARDs(null, 0);
-			break;
-		    case CodePoint.BNDSQLSTT:
-			reader.skipBytes();
-			parseSQLSTTDss();
-			writeSQLCARDs(null, 0);
-			break;
-		    case CodePoint.SQLSTTVRB:
-			// optional
-			reader.skipBytes();
-			break;
-		    case CodePoint.ENDBND:
-			reader.skipBytes();
-			writeSQLCARDs(null, 0);
-			break;
-		    case CodePoint.DSCSQLSTT:
-			if (PRPSQLSTTfailed) {
-			    reader.skipBytes();
-			    writeSQLCARDs(null, 0);
-			    break;
 			}
-			try {
-			    boolean rtnOutput = parseDSCSQLSTT();
-			    writeSQLDARD(database.getCurrentStatement(), rtnOutput,
-					 null);
+		    }
+		}
+		catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    // The fix for DERBY-1196 removed code 
+		    // here to close the prepared statement 
+		    // if OPNQRY failed.
+		    writeOPNQFLRM(e);
+		}
+		break;
+	    case CodePoint.RDBCMM:
+		try {
+		    if (SanityManager.DEBUG)
+			trace("Received commit");
+		    if (!database.getConnection().getAutoCommit()) {
+			database.getConnection().clearWarnings();
+			database.commit();
+			writeENDUOWRM(COMMIT);
+			checkWarning(database.getConnection(), null, null, 0, true, true);
+		    }
+		    // we only want to write one of these per transaction
+		    // so set to false in preparation for next command
+		    database.RDBUPDRM_sent = false;
+		} catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    // Even in case of error, we have to write the ENDUOWRM.
+		    writeENDUOWRM(COMMIT);
+		    writeSQLCARDs(e, 0);
+		    errorInChain(e);
+		}
+		break;
+	    case CodePoint.RDBRLLBCK:
+		try {
+		    if (SanityManager.DEBUG)
+			trace("Received rollback");
+		    database.getConnection().clearWarnings();
+		    database.rollback();
+		    writeENDUOWRM(ROLLBACK);
+		    checkWarning(database.getConnection(), null, null, 0, true, true);
+		    // we only want to write one of these per transaction
+		    // so set to false in preparation for next command
+		    database.RDBUPDRM_sent = false;
+		} catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    // Even in case of error, we have to write the ENDUOWRM.
+		    writeENDUOWRM(ROLLBACK);
+		    writeSQLCARDs(e, 0);
+		    errorInChain(e);
+		}
+		break;
+	    case CodePoint.CLSQRY:
+		try{
+		    stmt = parseCLSQRY();
+		    stmt.rsClose();
+		    writeSQLCARDs(null, 0);
+		} catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    writeSQLCARDs(e, 0);
+		    errorInChain(e);
+		}
+		break;
+	    case CodePoint.EXCSAT:
+		parseEXCSAT();
+		writeEXCSATRD();
+		break;
+	    case CodePoint.ACCSEC:
+		int securityCheckCode = parseACCSEC();
+		writeACCSECRD(securityCheckCode); 
+		checkSecurityCodepoint = true;
+		break;
+	    case CodePoint.SECCHK:
+		if(parseDRDAConnection())
+		    // security all checked and connection ok
+		    checkSecurityCodepoint = false;
+		break;
+		/* since we don't support sqlj, we won't get bind commands from jcc, we
+		 * might get it from ccc; just skip them.
+		 */
+	    case CodePoint.BGNBND:
+		reader.skipBytes();
+		writeSQLCARDs(null, 0);
+		break;
+	    case CodePoint.BNDSQLSTT:
+		reader.skipBytes();
+		parseSQLSTTDss();
+		writeSQLCARDs(null, 0);
+		break;
+	    case CodePoint.SQLSTTVRB:
+		// optional
+		reader.skipBytes();
+		break;
+	    case CodePoint.ENDBND:
+		reader.skipBytes();
+		writeSQLCARDs(null, 0);
+		break;
+	    case CodePoint.DSCSQLSTT:
+		if (PRPSQLSTTfailed) {
+		    reader.skipBytes();
+		    writeSQLCARDs(null, 0);
+		    break;
+		}
+		try {
+		    boolean rtnOutput = parseDSCSQLSTT();
+		    writeSQLDARD(database.getCurrentStatement(), rtnOutput,
+				 null);
 						
-			} catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				server.consoleExceptionPrint(e);
-				try {
-				    writeSQLDARD(database.getCurrentStatement(), true, e);
-				} catch (SQLException e2) {	// should not get here since doing nothing with ps
-				    agentError("Why am I getting another SQLException?");
-				}
-				errorInChain(e);
-			    }
-			break;
-		    case CodePoint.EXCSQLSTT:
-			if (PRPSQLSTTfailed) {
-			    // Skip parameters too if they are chained Beetle 4867
-			    skipRemainder(true);
-			    writeSQLCARDs(null, 0);
-			    break;
-			}
-			try {
-			    parseEXCSQLSTT();
+		} catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    server.consoleExceptionPrint(e);
+		    try {
+			writeSQLDARD(database.getCurrentStatement(), true, e);
+		    } catch (SQLException e2) {	// should not get here since doing nothing with ps
+			agentError("Why am I getting another SQLException?");
+		    }
+		    errorInChain(e);
+		}
+		break;
+	    case CodePoint.EXCSQLSTT:
+		if (PRPSQLSTTfailed) {
+		    // Skip parameters too if they are chained Beetle 4867
+		    skipRemainder(true);
+		    writeSQLCARDs(null, 0);
+		    break;
+		}
+		try {
+		    parseEXCSQLSTT();
 
-			    DRDAStatement curStmt = database.getCurrentStatement();
-			    if (curStmt != null)
-				curStmt.rsSuspend();
-			} catch (SQLException e)
-			    {
-				writer.clearDSSesBackToMark(writerMark);
-				if (SanityManager.DEBUG) 
-				    {
-					server.consoleExceptionPrint(e);
-				    }
-				writeSQLCARDs(e, 0);
-				errorInChain(e);
-			    }
-			break;
-		    case CodePoint.SYNCCTL:
-			if (xaProto == null)
-			    xaProto = new DRDAXAProtocol(this);
-			xaProto.parseSYNCCTL();
-			break;
-		    default:
-			codePointNotSupported(codePoint);
+		    DRDAStatement curStmt = database.getCurrentStatement();
+		    if (curStmt != null)
+			curStmt.rsSuspend();
+		} catch (SQLException e) {
+		    writer.clearDSSesBackToMark(writerMark);
+		    if (SanityManager.DEBUG)  {
+			server.consoleExceptionPrint(e);
 		    }
+		    writeSQLCARDs(e, 0);
+		    errorInChain(e);
+		}
+		break;
+	    case CodePoint.SYNCCTL:
+		if (xaProto == null)
+		    xaProto = new DRDAXAProtocol(this);
+		xaProto.parseSYNCCTL();
+		break;
+	    default:
+		codePointNotSupported(codePoint);
+	    }
 
-		// Set the correct chaining bits for whatever
-		// reply DSS(es) we just wrote.  If we've reached
-		// the end of the chain, this method will send
-		// the DSS(es) across.
-		finalizeChain();
+	    // Set the correct chaining bits for whatever
+	    // reply DSS(es) we just wrote.  If we've reached
+	    // the end of the chain, this method will send
+	    // the DSS(es) across.
+	    finalizeChain();
 
-	    }
+	}
 	while (reader.isChainedWithSameID() || reader.isChainedWithDiffID());
     }
 
@@ -958,13 +894,11 @@
      * @param e		the SQLException raised
      * @exception	DRDAProtocolException
      */
-    private void errorInChain(SQLException e) throws DRDAProtocolException
-    {
-	if (reader.terminateChainOnErr() && (getExceptionSeverity(e) > CodePoint.SVRCOD_ERROR))
-	    {
-		if (SanityManager.DEBUG)  trace("terminating the chain on error...");
-		skipRemainder(false);
-	    }
+    private void errorInChain(SQLException e) throws DRDAProtocolException {
+	if (reader.terminateChainOnErr() && (getExceptionSeverity(e) > CodePoint.SVRCOD_ERROR)) {
+	    if (SanityManager.DEBUG)  trace("terminating the chain on error...");
+	    skipRemainder(false);
+	}
     }
 
     /**
@@ -973,29 +907,26 @@
      * @exception DRDAProtocolException
      */
     private void exchangeServerAttributes()
-	throws  DRDAProtocolException
-    {
+	throws  DRDAProtocolException {
 	int codePoint;
 	correlationID = reader.readDssHeader();
 	if (SanityManager.DEBUG) {
-	    if (correlationID == 0)
-		{
-		    SanityManager.THROWASSERT(
-					      "Unexpected value for correlationId = " + correlationID);
-		}
+	    if (correlationID == 0) {
+		SanityManager.THROWASSERT(
+					  "Unexpected value for correlationId = " + correlationID);
+	    }
 	}
 
 	codePoint = reader.readLengthAndCodePoint();
 
 	// The first code point in the exchange of attributes must be EXCSAT
-	if (codePoint != CodePoint.EXCSAT)
-	    {
-		//Throw PRCCNVRM 
-		throw
-		    new DRDAProtocolException(DRDAProtocolException.DRDA_Proto_PRCCNVRM,
-					      this, codePoint,
-					      CodePoint.PRCCNVCD_EXCSAT_FIRST_AFTER_CONN);
-	    }
+	if (codePoint != CodePoint.EXCSAT) {
+	    //Throw PRCCNVRM 
+	    throw
+		new DRDAProtocolException(DRDAProtocolException.DRDA_Proto_PRCCNVRM,
+					  this, codePoint,
+					  CodePoint.PRCCNVCD_EXCSAT_FIRST_AFTER_CONN);
+	}
 
 	parseEXCSAT();
 	writeEXCSATRD();
@@ -1004,8 +935,7 @@
     }
 	
 
-    private boolean parseDRDAConnection() throws DRDAProtocolException
-    {
+    private boolean parseDRDAConnection() throws DRDAProtocolException {
 	int codePoint;
 	boolean sessionOK = true;
 
@@ -1015,10 +945,9 @@
 	    trace("*** SECCHKRM securityCheckCode is: "+securityCheckCode);
 	writeSECCHKRM(securityCheckCode);
 	//at this point if the security check failed, we're done, the session failed
-	if (securityCheckCode != 0)
-	    {
-		return false;
-	    }
+	if (securityCheckCode != 0) {
+	    return false;
+	}
 
 	correlationID = reader.readDssHeader();
 	codePoint = reader.readLengthAndCodePoint();
@@ -1033,27 +962,21 @@
 	}		
 		
 	//if earlier we couldn't access the database
-	if (databaseAccessException != null)
-	    {
+	if (databaseAccessException != null) {
 
-		//if the Database was not found we will try DS
-		int failureType = getRdbAccessErrorCodePoint();
-		if (failureType == CodePoint.RDBNFNRM 
-		    || failureType == CodePoint.RDBATHRM)
-		    {
-			writeRDBfailure(failureType);
-		    }
-		else
-		    {
-			writeRDBfailure(CodePoint.RDBAFLRM);
-		    }
-		return false;
-	    }
-	else if (database.accessCount > 1 )	// already in conversation with database
-	    {
-		writeRDBfailure(CodePoint.RDBACCRM);
-		return false;
+	    //if the Database was not found we will try DS
+	    int failureType = getRdbAccessErrorCodePoint();
+	    if (failureType == CodePoint.RDBNFNRM 
+		|| failureType == CodePoint.RDBATHRM) {
+		writeRDBfailure(failureType);
+	    } else {
+		writeRDBfailure(CodePoint.RDBAFLRM);
 	    }
+	    return false;
+	} else if (database.accessCount > 1 ) { // already in conversation with database 
+	    writeRDBfailure(CodePoint.RDBACCRM);
+	    return false;
+	}
 	else // everything is fine 
 	    writeACCRDBRM(svrcod);
 
@@ -1074,8 +997,7 @@
      *
      * @param	codePoint	codepoint of failure
      */
-    private void writeRDBfailure(int codePoint) throws DRDAProtocolException
-    {
+    private void writeRDBfailure(int codePoint) throws DRDAProtocolException {
 	writer.createDssReply();
 	writer.startDdm(codePoint);
 	writer.writeScalar2Bytes(CodePoint.SVRCOD, CodePoint.SVRCOD_ERROR);
@@ -1114,8 +1036,7 @@
 	           
     */
 
-    private int getRdbAccessErrorCodePoint()
-    {
+    private int getRdbAccessErrorCodePoint() {
 	String sqlState = databaseAccessException.getSQLState();
 	if (sqlState.regionMatches(0,SQLState.DATABASE_NOT_FOUND,0,5) |
 	    sqlState.regionMatches(0,SQLState.NO_SUCH_DATABASE,0,5))
@@ -1138,8 +1059,7 @@
      * @return security check code, 0 is O.K.
      * @exception DRDAProtocolException
      */
-    private int verifyUserIdPassword() throws DRDAProtocolException
-    {
+    private int verifyUserIdPassword() throws DRDAProtocolException {
 	databaseAccessException = null;
 	int retSecChkCode = 0;
 
@@ -1161,8 +1081,7 @@
      * @return security check code, 0 is O.K.
      * @exception DRDAProtocolException
      */
-    private int getConnFromDatabaseName() throws DRDAProtocolException
-    {
+    private int getConnFromDatabaseName() throws DRDAProtocolException {
 	Properties p = new Properties();
 	databaseAccessException = null;
 	//if we haven't got the correlation token yet, use session number for drdaID
@@ -1177,45 +1096,40 @@
 	    // was denied, Cloudscape doesn't say whether the userid or password caused
 	    // the problem, so we will just return userid invalid
 	    databaseAccessException = se;
-	    for (; se != null; se = se.getNextException())
-		{
-		    if (SanityManager.DEBUG)
-			trace(se.getMessage());
-		    println2Log(database.dbName, session.drdaID, se.getMessage());
-		}
+	    for (; se != null; se = se.getNextException()) {
+		if (SanityManager.DEBUG)
+		    trace(se.getMessage());
+		println2Log(database.dbName, session.drdaID, se.getMessage());
+	    }
 
 	    if (sqlState.regionMatches(0,SQLState.LOGIN_FAILED,0,5))
 		return CodePoint.SECCHKCD_USERIDINVALID;
 
 	    return 0;
 			
-	}
-	catch (Exception e)
-	    {
-		// If cloudscape has shut down for some reason,
-		// we will send  an agent error and then try to 
-		// get the driver loaded again.  We have to get
-		// rid of the client first in case they are holding
-		// the DriverManager lock.
-		println2Log(database.dbName, session.drdaID, 
-			    "Driver not loaded"
-			    + e.getMessage());
+	} catch (Exception e) {
+	    // If cloudscape has shut down for some reason,
+	    // we will send  an agent error and then try to 
+	    // get the driver loaded again.  We have to get
+	    // rid of the client first in case they are holding
+	    // the DriverManager lock.
+	    println2Log(database.dbName, session.drdaID, 
+			"Driver not loaded"
+			+ e.getMessage());
+	    try {
+		agentError("Driver not loaded");
+	    } catch (DRDAProtocolException dpe) {
+		// Retry starting the server before rethrowing 
+		// the protocol exception.  Then hopfully all
+		// will be well when they try again.
 		try {
-		    agentError("Driver not loaded");
+		    server.startNetworkServer();
+		} catch (Exception re) {
+		    println2Log(database.dbName, session.drdaID, "Failed attempt to reload driver " +re.getMessage()  );
 		}
-		catch (DRDAProtocolException dpe)
-		    {
-			// Retry starting the server before rethrowing 
-			// the protocol exception.  Then hopfully all
-			// will be well when they try again.
-			try {
-			    server.startNetworkServer();
-			} catch (Exception re) {
-			    println2Log(database.dbName, session.drdaID, "Failed attempt to reload driver " +re.getMessage()  );
-			}
-			throw dpe;
-		    }
+		throw dpe;
 	    }
+	}
 		
 	
 	// Everything worked so log connection to the database.
@@ -1239,8 +1153,7 @@
      *
      * @exception DRDAProtocolException
      */
-    private void parseEXCSAT() throws DRDAProtocolException
-    {
+    private void parseEXCSAT() throws DRDAProtocolException {
 	int codePoint;
 	String strVal;
 
@@ -1259,11 +1172,10 @@
 
 	// If we have already exchanged attributes once just 
 	// process any new manager levels and return (case 2 and 3 above)
-	if (appRequester != null)
-	    {
-		parseEXCSAT2();
-		return;
-	    }
+	if (appRequester != null) {
+	    parseEXCSAT2();
+	    return;
+	}
 
 	// set up a new Application Requester to store information about the
 	// application requester for this session
@@ -1273,59 +1185,57 @@
 	reader.markCollection();
 
 	codePoint = reader.getCodePoint();
-	while (codePoint != -1)
-	    {
-		switch (codePoint)
-		    {
-			// optional
-		    case CodePoint.EXTNAM:
-			appRequester.extnam = reader.readString();
-			if (SanityManager.DEBUG)
-			    trace("extName = " + appRequester.extnam);
-			if (appRequester.extnam.length() > CodePoint.MAX_NAME)
-			    tooBig(CodePoint.EXTNAM);
-			break;
-			// optional
-		    case CodePoint.MGRLVLLS:
-			parseMGRLVLLS(1);
-			break;
-			// optional 
-		    case CodePoint.SPVNAM:
-			appRequester.spvnam = reader.readString();
-			// This is specified as a null parameter so length should
-			// be zero
-			if (appRequester.spvnam != null)
-			    badObjectLength(CodePoint.SPVNAM);
-			break;
-			// optional
-		    case CodePoint.SRVNAM:
-			appRequester.srvnam = reader.readString();
-			if (SanityManager.DEBUG)
-			    trace("serverName = " +  appRequester.srvnam);
-			if (appRequester.srvnam.length() > CodePoint.MAX_NAME)
-			    tooBig(CodePoint.SRVNAM);
-			break;
-			// optional
-		    case CodePoint.SRVRLSLV:
-			appRequester.srvrlslv = reader.readString();
-			if (SanityManager.DEBUG)
-			    trace("serverlslv = " + appRequester.srvrlslv);
-			if (appRequester.srvrlslv.length() > CodePoint.MAX_NAME)
-			    tooBig(CodePoint.SRVRLSLV);
-			break;
-			// optional
-		    case CodePoint.SRVCLSNM:
-			appRequester.srvclsnm = reader.readString();
-			if (SanityManager.DEBUG)
-			    trace("serverClassName = " + appRequester.srvclsnm);
-			if (appRequester.srvclsnm.length() > CodePoint.MAX_NAME)
-			    tooBig(CodePoint.SRVCLSNM);
-			break;
-		    default:
-			invalidCodePoint(codePoint);
-		    }
-		codePoint = reader.getCodePoint();
+	while (codePoint != -1) {
+	    switch (codePoint) {
+		// optional
+	    case CodePoint.EXTNAM:
+		appRequester.extnam = reader.readString();
+		if (SanityManager.DEBUG)
+		    trace("extName = " + appRequester.extnam);
+		if (appRequester.extnam.length() > CodePoint.MAX_NAME)
+		    tooBig(CodePoint.EXTNAM);
+		break;
+		// optional
+	    case CodePoint.MGRLVLLS:
+		parseMGRLVLLS(1);
+		break;
+		// optional 
+	    case CodePoint.SPVNAM:
+		appRequester.spvnam = reader.readString();
+		// This is specified as a null parameter so length should
+		// be zero
+		if (appRequester.spvnam != null)
+		    badObjectLength(CodePoint.SPVNAM);
+		break;
+		// optional
+	    case CodePoint.SRVNAM:
+		appRequester.srvnam = reader.readString();
+		if (SanityManager.DEBUG)
+		    trace("serverName = " +  appRequester.srvnam);
+		if (appRequester.srvnam.length() > CodePoint.MAX_NAME)
+		    tooBig(CodePoint.SRVNAM);
+		break;
+		// optional
+	    case CodePoint.SRVRLSLV:
+		appRequester.srvrlslv = reader.readString();
+		if (SanityManager.DEBUG)
+		    trace("serverlslv = " + appRequester.srvrlslv);
+		if (appRequester.srvrlslv.length() > CodePoint.MAX_NAME)
+		    tooBig(CodePoint.SRVRLSLV);
+		break;
+		// optional
+	    case CodePoint.SRVCLSNM:
+		appRequester.srvclsnm = reader.readString();
+		if (SanityManager.DEBUG)
+		    trace("serverClassName = " + appRequester.srvclsnm);
+		if (appRequester.srvclsnm.length() > CodePoint.MAX_NAME)
+		    tooBig(CodePoint.SRVCLSNM);
+		break;
+	    default:
+		invalidCodePoint(codePoint);
 	    }
+	    codePoint = reader.getCodePoint();
+	}
     }
 
     /**
@@ -1345,33 +1255,30 @@
      * I am also going to ignore spvnam since it should be null anyway.
      * Only new managers can be added.
      */
-    private void parseEXCSAT2() throws DRDAProtocolException
-    {
+    private void parseEXCSAT2() throws DRDAProtocolException {
 	int codePoint;
 	reader.markCollection();
 
 	codePoint = reader.getCodePoint();
-	while (codePoint != -1)
-	    {
-		switch (codePoint)
-		    {
-			// optional
-		    case CodePoint.EXTNAM:
-		    case CodePoint.SRVNAM:
-		    case CodePoint.SRVRLSLV:
-		    case CodePoint.SRVCLSNM:
-		    case CodePoint.SPVNAM:
-			reader.skipBytes();
-			break;
-			// optional
-		    case CodePoint.MGRLVLLS:
-			parseMGRLVLLS(2);
-			break;
-		    default:
-			invalidCodePoint(codePoint);
-		    }
-		codePoint = reader.getCodePoint();
+	while (codePoint != -1) {
+	    switch (codePoint) {
+		// optional
+	    case CodePoint.EXTNAM:
+	    case CodePoint.SRVNAM:
+	    case CodePoint.SRVRLSLV:
+	    case CodePoint.SRVCLSNM:
+	    case CodePoint.SPVNAM:
+		reader.skipBytes();
+		break;
+		// optional
+	    case CodePoint.MGRLVLLS:
+		parseMGRLVLLS(2);
+		break;
+	    default:
+		invalidCodePoint(codePoint);
 	    }
+	    codePoint = reader.getCodePoint();
+	}
     }
 
     /**
@@ -1398,8 +1305,7 @@
      * @exception DRDAProtocolException
      * 
      */
-    private void parseMGRLVLLS(int time) throws DRDAProtocolException
-    {
+    private void parseMGRLVLLS(int time) throws DRDAProtocolException {
 	int manager, managerLevel;
 	int currentLevel;
 	// set up vectors to keep track of manager information
@@ -1410,50 +1316,44 @@
 	if (SanityManager.DEBUG)
 	    trace("Manager Levels");
 
-	while (reader.moreDdmData())
-	    {
-		manager = reader.readNetworkShort();
-		managerLevel = reader.readNetworkShort();
-		if (CodePoint.isKnownManager(manager))
-		    {
-			knownManagers.addElement(new Integer(manager));
-			//if the manager level hasn't been set, set it
-			currentLevel = appRequester.getManagerLevel(manager);
-			if (currentLevel == appRequester.MGR_LEVEL_UNKNOWN)
-			    appRequester.setManagerLevel(manager, managerLevel);
-			else
-			    {
-				//if the level is still the same we'll ignore it
-				if (currentLevel != managerLevel)
-				    {
-					//keep a list of conflicting managers
-					errorManagers.addElement(new Integer(manager));
-					errorManagersLevel.addElement(new Integer (managerLevel));
-				    }
-			    }
-
+	while (reader.moreDdmData()) {
+	    manager = reader.readNetworkShort();
+	    managerLevel = reader.readNetworkShort();
+	    if (CodePoint.isKnownManager(manager)) {
+		knownManagers.addElement(new Integer(manager));
+		//if the manager level hasn't been set, set it
+		currentLevel = appRequester.getManagerLevel(manager);
+		if (currentLevel == appRequester.MGR_LEVEL_UNKNOWN)
+		    appRequester.setManagerLevel(manager, managerLevel);
+		else {
+		    //if the level is still the same we'll ignore it
+		    if (currentLevel != managerLevel) {
+			//keep a list of conflicting managers
+			errorManagers.addElement(new Integer(manager));
+			errorManagersLevel.addElement(new Integer (managerLevel));
 		    }
-		else
-		    unknownManagers.addElement(new Integer(manager));
-		if (SanityManager.DEBUG)
-		    trace("Manager = " + java.lang.Integer.toHexString(manager) + 
-			  " ManagerLevel " + managerLevel);
+		}
+
 	    }
+	    else
+		unknownManagers.addElement(new Integer(manager));
+	    if (SanityManager.DEBUG)
+		trace("Manager = " + java.lang.Integer.toHexString(manager) + 
+		      " ManagerLevel " + managerLevel);
+	}
 	sqlamLevel = appRequester.getManagerLevel(CodePoint.SQLAM);
 	// did we have any errors
-	if (errorManagers.size() > 0)
-	    {
-		Object [] oa = new Object[errorManagers.size()*2];
-		int j = 0;
-		for (int i = 0; i < errorManagers.size(); i++)
-		    {
-			oa[j++] = errorManagers.elementAt(i);
-			oa[j++] = errorManagersLevel.elementAt(i);
-		    }
-		throw new DRDAProtocolException(DRDAProtocolException.DRDA_Proto_MGRLVLRM,
-						this, 0,
-						0, oa);
-	    }
+	if (errorManagers.size() > 0) {
+	    Object [] oa = new Object[errorManagers.size()*2];
+	    int j = 0;
+	    for (int i = 0; i < errorManagers.size(); i++) {
+		oa[j++] = errorManagers.elementAt(i);
+		oa[j++] = errorManagersLevel.elementAt(i);
+	    }
+	    throw new DRDAProtocolException(DRDAProtocolException.DRDA_Proto_MGRLVLRM,
+					    this, 0,
+					    0, oa);
+	}
     }
     /**
      * Write reply to EXCSAT command
@@ -1466,8 +1366,7 @@
      *
      * @exception DRDAProtocolException
      */
-    private void writeEXCSATRD() throws DRDAProtocolException
-    {
+    private void writeEXCSATRD() throws DRDAProtocolException {
 	writer.createDssReply();
 	writer.startDdm(CodePoint.EXCSATRD);
 	writer.writeScalarString(CodePoint.EXTNAM, server.att_extnam);
@@ -1521,36 +1420,30 @@
      *			XAMGR - XA manager 
      *		  VALUE
      */
-    private void writeMGRLEVELS() throws DRDAProtocolException
-    {
+    private void writeMGRLEVELS() throws DRDAProtocolException {
 	int manager;
 	int appLevel;
 	int serverLevel;
 	writer.startDdm(CodePoint.MGRLVLLS);
-	for (int i = 0; i < knownManagers.size(); i++)
-	    {
-		manager = ((Integer)knownManagers.elementAt(i)).intValue();
-		appLevel = appRequester.getManagerLevel(manager);
-		serverLevel = server.getManagerLevel(manager);
-		if (serverLevel >= appLevel)
-		    {
-			//Note appLevel has already been set to 0 if we can't support
-			//the original app Level
-			writer.writeCodePoint4Bytes(manager, appLevel);
-		    }
-		else
-		    {
-			writer.writeCodePoint4Bytes(manager, serverLevel);
-			// reset application manager level to server level
-			appRequester.setManagerLevel(manager, serverLevel);
-		    }
+	for (int i = 0; i < knownManagers.size(); i++) {
+	    manager = ((Integer)knownManagers.elementAt(i)).intValue();
+	    appLevel = appRequester.getManagerLevel(manager);
+	    serverLevel = server.getManagerLevel(manager);
+	    if (serverLevel >= appLevel) {
+		//Note appLevel has already been set to 0 if we can't support
+		//the original app Level
+		writer.writeCodePoint4Bytes(manager, appLevel);
+	    } else {
+		writer.writeCodePoint4Bytes(manager, serverLevel);
+		// reset application manager level to server level
+		appRequester.setManagerLevel(manager, serverLevel);
 	    }
+	}
 	// write 0 for all unknown managers
-	for (int i = 0; i < unknownManagers.size(); i++)
-	    {
-		manager = ((Integer)unknownManagers.elementAt(i)).intValue();
-		writer.writeCodePoint4Bytes(manager, 0);
-	    }
+	for (int i = 0; i < unknownManagers.size(); i++) {
+	    manager = ((Integer)unknownManagers.elementAt(i)).intValue();
+	    writer.writeCodePoint4Bytes(manager, 0);
+	}
 	writer.endDdm();
     }
     /**
@@ -1573,92 +1466,85 @@
      *
      *  @return security check code - 0 if everything O.K.
      */
-    private int parseACCSEC() throws  DRDAProtocolException
-    {
+    private int parseACCSEC() throws  DRDAProtocolException {
 	int securityCheckCode = 0;
 	int securityMechanism = 0;
 	byte [] publicKeyIn = null;
 
 	reader.markCollection();
 	int codePoint = reader.getCodePoint();
-	while (codePoint != -1)
-	    {
-		switch(codePoint)
-		    {
-			//optional
-		    case CodePoint.SECMGRNM:
-			// this is defined to be 0 length
-			if (reader.getDdmLength() != 0)
-			    badObjectLength(CodePoint.SECMGRNM);
-			break;
-			//required
-		    case CodePoint.SECMEC:
-			checkLength(CodePoint.SECMEC, 2);
-			securityMechanism = reader.readNetworkShort();
-			if (SanityManager.DEBUG)
-			    trace("Security mechanism = " + securityMechanism);
+	while (codePoint != -1) {
+	    switch(codePoint) {
+		//optional
+	    case CodePoint.SECMGRNM:
+		// this is defined to be 0 length
+		if (reader.getDdmLength() != 0)
+		    badObjectLength(CodePoint.SECMGRNM);
+		break;
+		//required
+	    case CodePoint.SECMEC:
+		checkLength(CodePoint.SECMEC, 2);
+		securityMechanism = reader.readNetworkShort();
+		if (SanityManager.DEBUG)
+		    trace("Security mechanism = " + securityMechanism);
                     
-			// if Property.DRDA_PROP_SECURITYMECHANISM has been set, then
-			// network server only accepts connections which use that
-			// security mechanism. No other types of connections 
-			// are accepted.
-			// Make check to see if this property has been set.
-			// if set, and if the client requested security mechanism 
-			// is not the same, then return a security check code 
-			// that the server does not support/allow this security 
-			// mechanism
-			if ( (server.getSecurityMechanism() != 
-			      NetworkServerControlImpl.INVALID_OR_NOTSET_SECURITYMECHANISM)
-			     && securityMechanism != server.getSecurityMechanism())
+		// if Property.DRDA_PROP_SECURITYMECHANISM has been set, then
+		// network server only accepts connections which use that
+		// security mechanism. No other types of connections 
+		// are accepted.
+		// Make check to see if this property has been set.
+		// if set, and if the client requested security mechanism 
+		// is not the same, then return a security check code 
+		// that the server does not support/allow this security 
+		// mechanism
+		if ( (server.getSecurityMechanism() != 
+		      NetworkServerControlImpl.INVALID_OR_NOTSET_SECURITYMECHANISM)
+		     && securityMechanism != server.getSecurityMechanism())
+		    securityCheckCode = CodePoint.SECCHKCD_NOTSUPPORTED;
+		else {
+		    // for plain text userid,password USRIDPWD, and USRIDONL
+		    // no need of decryptionManager
+		    if (securityMechanism != CodePoint.SECMEC_USRIDPWD &&
+			securityMechanism != CodePoint.SECMEC_USRIDONL) {
+			//this is the only other one we understand
+			if (securityMechanism != CodePoint.SECMEC_EUSRIDPWD) 
 			    securityCheckCode = CodePoint.SECCHKCD_NOTSUPPORTED;
-			else
-			    {
-				// for plain text userid,password USRIDPWD, and USRIDONL
-				// no need of decryptionManager
-				if (securityMechanism != CodePoint.SECMEC_USRIDPWD &&
-				    securityMechanism != CodePoint.SECMEC_USRIDONL)
-				    {
-					//this is the only other one we understand
-					if (securityMechanism != CodePoint.SECMEC_EUSRIDPWD) 
-					    securityCheckCode = CodePoint.SECCHKCD_NOTSUPPORTED;
-					else
-					    {
-						try {
-						    if (decryptionManager == null)
-							decryptionManager = new DecryptionManager();
-						    myPublicKey = decryptionManager.obtainPublicKey();
-						} catch (SQLException e) {
-						    println2Log(null, session.drdaID, e.getMessage());
-						    // Local security service non-retryable error.
-						    securityCheckCode = CodePoint.SECCHKCD_0A;
-						}
-					    }
-				    }
+			else {
+			    try {
+				if (decryptionManager == null)
+				    decryptionManager = new DecryptionManager();
+				myPublicKey = decryptionManager.obtainPublicKey();
+			    } catch (SQLException e) {
+				println2Log(null, session.drdaID, e.getMessage());
+				// Local security service non-retryable error.
+				securityCheckCode = CodePoint.SECCHKCD_0A;
 			    }
-			break;
-			//optional (currently required for Cloudscape - may need to revisit)
-		    case CodePoint.RDBNAM:
-			String dbname = parseRDBNAM();
-			Database d = session.getDatabase(dbname);
-			if (d == null)
-			    addDatabase(dbname);
-			else
-			    {
-                        
-				// reset database for connection re-use 
-				d.reset();
-				database = d;
-			    }
-			break;
-			//optional - depending on security Mechanism 
-		    case CodePoint.SECTKN:
-			publicKeyIn = reader.readBytes();
-			break;
-		    default:
-			invalidCodePoint(codePoint);
+			}
 		    }
-		codePoint = reader.getCodePoint();
+		}
+		break;
+		//optional (currently required for Cloudscape - may need to revisit)
+	    case CodePoint.RDBNAM:
+		String dbname = parseRDBNAM();
+		Database d = session.getDatabase(dbname);
+		if (d == null)
+		    addDatabase(dbname);
+		else {
+                        
+		    // reset database for connection re-use 
+		    d.reset();
+		    database = d;
+		}
+		break;
+		//optional - depending on security Mechanism 
+	    case CodePoint.SECTKN:
+		publicKeyIn = reader.readBytes();
+		break;
+	    default:
+		invalidCodePoint(codePoint);
 	    }
+	    codePoint = reader.getCodePoint();
+	}
 	// check for required CodePoint's
 	if (securityMechanism == 0)
 	    missingCodePoint(CodePoint.SECMEC);
@@ -1716,8 +1602,7 @@
      * @return RDB Package Name, Consistency Token, and Section Number
      * @exception DRDAProtocolException
      */
-    private Pkgnamcsn parseOPNQRY() throws DRDAProtocolException, SQLException
-    {
+    private Pkgnamcsn parseOPNQRY() throws DRDAProtocolException, SQLException {
 	Pkgnamcsn pkgnamcsn = null;
 	boolean gotQryblksz = false;
 	int blksize = 0;
@@ -1728,66 +1613,64 @@
 	int outovropt = CodePoint.OUTOVRFRS;
 	reader.markCollection();
 	int codePoint = reader.getCodePoint();
-	while (codePoint != -1)
-	    {
-		switch(codePoint)
-		    {
-			//optional
-		    case CodePoint.RDBNAM:
-			setDatabase(CodePoint.OPNQRY);
-			break;
-			//required
-		    case CodePoint.PKGNAMCSN:
-			pkgnamcsn = parsePKGNAMCSN();
-			break;
-			//required
-		    case CodePoint.QRYBLKSZ:
-			blksize = parseQRYBLKSZ();
-			gotQryblksz = true;
-			break;
-			//optional
-		    case CodePoint.QRYBLKCTL:
-			qryblkctl = reader.readNetworkShort();
-			//The only type of query block control we can specify here
-			//is forced fixed row
-			if (qryblkctl != CodePoint.FRCFIXROW)
-			    invalidCodePoint(qryblkctl);
-			if (SanityManager.DEBUG)
-			    trace("!!qryblkctl = "+Integer.toHexString(qryblkctl));
-			gotQryblksz = true;
-			break;
-			//optional
-		    case CodePoint.MAXBLKEXT:
-			maxblkext = reader.readSignedNetworkShort();
-			if (SanityManager.DEBUG)
-			    trace("maxblkext = "+maxblkext);
-			break;
-			// optional
-		    case CodePoint.OUTOVROPT:
-			outovropt = parseOUTOVROPT();
-			break;
-			//optional
-		    case CodePoint.QRYROWSET:
-			//Note minimum for OPNQRY is 0
-			qryrowset = parseQRYROWSET(0);
-			break;
-		    case CodePoint.QRYCLSIMP:
-			// Implicitly close non-scrollable cursor
-			qryclsimp = parseQRYCLSIMP();
-			break;
-		    case CodePoint.QRYCLSRLS:
-			// Ignore release of read locks.  Nothing we can do here
-			parseQRYCLSRLS();
-			break;
-			// optional
-		    case CodePoint.MONITOR:
-			parseMONITOR();
-			break;
-		    default:
-			invalidCodePoint(codePoint);
-		    }
-		codePoint = reader.getCodePoint();
+	while (codePoint != -1) {
+	    switch(codePoint) {
+		//optional
+	    case CodePoint.RDBNAM:
+		setDatabase(CodePoint.OPNQRY);
+		break;
+		//required
+	    case CodePoint.PKGNAMCSN:
+		pkgnamcsn = parsePKGNAMCSN();
+		break;
+		//required
+	    case CodePoint.QRYBLKSZ:
+		blksize = parseQRYBLKSZ();
+		gotQryblksz = true;
+		break;
+		//optional
+	    case CodePoint.QRYBLKCTL:
+		qryblkctl = reader.readNetworkShort();
+		//The only type of query block control we can specify here
+		//is forced fixed row
+		if (qryblkctl != CodePoint.FRCFIXROW)
+		    invalidCodePoint(qryblkctl);
+		if (SanityManager.DEBUG)
+		    trace("!!qryblkctl = "+Integer.toHexString(qryblkctl));
+		gotQryblksz = true;
+		break;
+		//optional
+	    case CodePoint.MAXBLKEXT:
+		maxblkext = reader.readSignedNetworkShort();
+		if (SanityManager.DEBUG)
+		    trace("maxblkext = "+maxblkext);
+		break;
+		// optional
+	    case CodePoint.OUTOVROPT:
+		outovropt = parseOUTOVROPT();
+		break;
+		//optional
+	    case CodePoint.QRYROWSET:
+		//Note minimum for OPNQRY is 0
+		qryrowset = parseQRYROWSET(0);
+		break;
+	    case CodePoint.QRYCLSIMP:
+		// Implicitly close non-scrollable cursor
+		qryclsimp = parseQRYCLSIMP();
+		break;
+	    case CodePoint.QRYCLSRLS:
+		// Ignore release of read locks.  Nothing we can do here
+		parseQRYCLSRLS();
+		break;
+		// optional
+	    case CodePoint.MONITOR:
+		parseMONITOR();
+		break;
+	    default:
+		invalidCodePoint(codePoint);
 	    }
+	    codePoint = reader.getCodePoint();
+	}
 	// check for required variables
 	if (pkgnamcsn == null)
 	    missingCodePoint(CodePoint.PKGNAMCSN);
@@ -1796,36 +1679,31 @@
 
 	// get the statement we are opening
 	DRDAStatement stmt = database.getDRDAStatement(pkgnamcsn);
-	if (stmt == null)
-	    {
-		//XXX should really throw a SQL Exception here
-		invalidValue(CodePoint.PKGNAMCSN);
-	    }
+	if (stmt == null) {
+	    //XXX should really throw a SQL Exception here
+	    invalidValue(CodePoint.PKGNAMCSN);
+	}
 
 	// check that this statement is not already open
 	// commenting this check out for now
 	// it turns out that JCC doesn't send a close if executeQuery is
 	// done again without closing the previous result set
 	// this check can't be done since the second executeQuery should work
-	//if (stmt.state != DRDAStatement.NOT_OPENED)
-	//{
+	//if (stmt.state != DRDAStatement.NOT_OPENED){
 	//	writeQRYPOPRM();
 	//	pkgnamcsn = null;
-	//}
-	//else
-	//{
+	//} else {
 	stmt.setOPNQRYOptions(blksize,qryblkctl,maxblkext,outovropt,
 			      qryrowset, qryclsimp);
 	//}
 		
 	// read the command objects
 	// for ps with parameter
-	if (reader.isChainedWithSameID())
-	    {
-		if (SanityManager.DEBUG)
-		    trace("&&&&&& parsing SQLDTA");
-		parseOPNQRYobjects(stmt);
-	    }
+	if (reader.isChainedWithSameID()) {
+	    if (SanityManager.DEBUG)
+		trace("&&&&&& parsing SQLDTA");
+	    parseOPNQRYobjects(stmt);
+	}
 	return pkgnamcsn;
     }
     /**
@@ -1845,38 +1723,34 @@
      * @throws SQLException
      */
     private void parseOPNQRYobjects(DRDAStatement stmt) 
-	throws DRDAProtocolException, SQLException
-    {
+	throws DRDAProtocolException, SQLException {
 	int codePoint;
-	do
-	    {
-		correlationID = reader.readDssHeader();
-		while (reader.moreDssData())
-		    {
-			codePoint = reader.readLengthAndCodePoint();
-			switch(codePoint)
-			    {
-				// optional
-			    case CodePoint.TYPDEFNAM:
-				setStmtOrDbByteOrder(false, stmt, parseTYPDEFNAM());
-				break;
-				// optional
-			    case CodePoint.TYPDEFOVR:
-				parseTYPDEFOVR(stmt);
-				break;
-				// optional 
-			    case CodePoint.SQLDTA:
-				parseSQLDTA(stmt);
-				break;
-				// optional
-			    case CodePoint.EXTDTA:	
-				readAndSetAllExtParams(stmt);
-				break;
-			    default:
-				invalidCodePoint(codePoint);
-			    }
-		    }
-	    } while (reader.isChainedWithSameID());
+	do {
+	    correlationID = reader.readDssHeader();
+	    while (reader.moreDssData()) {
+		codePoint = reader.readLengthAndCodePoint();
+		switch(codePoint) {
+		    // optional
+		case CodePoint.TYPDEFNAM:
+		    setStmtOrDbByteOrder(false, stmt, parseTYPDEFNAM());
+		    break;
+		    // optional
+		case CodePoint.TYPDEFOVR:
+		    parseTYPDEFOVR(stmt);
+		    break;
+		    // optional 
+		case CodePoint.SQLDTA:
+		    parseSQLDTA(stmt);
+		    break;
+		    // optional
+		case CodePoint.EXTDTA:	
+		    readAndSetAllExtParams(stmt);
+		    break;
+		default:
+		    invalidCodePoint(codePoint);
+		}
+	    }
+	} while (reader.isChainedWithSameID());
 
     }
     /**
@@ -1886,8 +1760,7 @@
      * @return output override option
      * @exception DRDAProtocolException
      */
-    private int parseOUTOVROPT() throws DRDAProtocolException
-    {
+    private int parseOUTOVROPT() throws DRDAProtocolException {
 	checkLength(CodePoint.OUTOVROPT, 1);
 	int outovropt = reader.readUnsignedByte();
 	if (SanityManager.DEBUG)
@@ -1904,8 +1777,7 @@
      * @return query block size
      * @exception DRDAProtocolException
      */
-    private int parseQRYBLKSZ() throws DRDAProtocolException
-    {
+    private int parseQRYBLKSZ() throws DRDAProtocolException {
 	checkLength(CodePoint.QRYBLKSZ, 4);
 	int blksize = reader.readNetworkInt();
 	if (SanityManager.DEBUG)
@@ -1921,8 +1793,7 @@
      * @return query row set size
      * @exception DRDAProtocolException
      */
-    private int parseQRYROWSET(int minVal) throws DRDAProtocolException
-    {
+    private int parseQRYROWSET(int minVal) throws DRDAProtocolException {
 	checkLength(CodePoint.QRYROWSET, 4);
 	int qryrowset = reader.readNetworkInt();
 	if (SanityManager.DEBUG)
@@ -1936,8 +1807,7 @@
      * after end of data.
      * @return  true to close on end of data 
      */
-    private int  parseQRYCLSIMP() throws DRDAProtocolException
-    {
+    private int  parseQRYCLSIMP() throws DRDAProtocolException {
 	   
 	checkLength(CodePoint.QRYCLSIMP, 1);
 	int qryclsimp = reader.readUnsignedByte();
@@ -1951,8 +1821,7 @@
     }
 
 
-    private int parseQRYCLSRLS() throws DRDAProtocolException
-    {
+    private int parseQRYCLSRLS() throws DRDAProtocolException {
 	reader.skipBytes();
 	return 0;
     }
@@ -1966,8 +1835,7 @@
      * 
      * @exception DRDAProtocolException
      */
-    private void writeQRYPOPRM() throws DRDAProtocolException
-    {
+    private void writeQRYPOPRM() throws DRDAProtocolException {
 	writer.createDssReply();
 	writer.startDdm(CodePoint.QRYPOPRM);
 	writer.writeScalar2Bytes(CodePoint.SVRCOD, CodePoint.SVRCOD_ERROR);
@@ -1985,8 +1853,7 @@
      * @param svrCod	Severity Code
      * @exception DRDAProtocolException
      */
-    private void writeQRYNOPRM(int svrCod) throws DRDAProtocolException
-    {
+    private void writeQRYNOPRM(int svrCod) throws DRDAProtocolException {
 	writer.createDssReply();
 	writer.startDdm(CodePoint.QRYNOPRM);
 	writer.writeScalar2Bytes(CodePoint.SVRCOD, svrCod);
@@ -2004,8 +1871,7 @@
      *
      * @exception DRDAProtocolException
      */
-    private void writeOPNQFLRM(SQLException e) throws DRDAProtocolException
-    {
+    private void writeOPNQFLRM(SQLException e) throws DRDAProtocolException {
 	writer.createDssReply();
 	writer.startDdm(CodePoint.OPNQFLRM);
 	writer.writeScalar2Bytes(CodePoint.SVRCOD, CodePoint.SVRCOD_ERROR);
@@ -2029,41 +1895,37 @@
      *
      * @throws DRDAProtocolException
      */
-    private void writePKGNAMCSN(byte[] pkgcnstkn) throws DRDAProtocolException
-    {
+    private void writePKGNAMCSN(byte[] pkgcnstkn) throws DRDAProtocolException {
 	writer.startDdm(CodePoint.PKGNAMCSN);
 	if (rdbnam.length() <= CodePoint.RDBNAM_LEN &&
 	    rdbcolid.length() <= CodePoint.RDBCOLID_LEN &&
-	    pkgid.length() <= CodePoint.PKGID_LEN)
-	    {	// if none of RDBNAM, RDBCOLID and PKGID have a length of
-		// more than 18, use fixed format
-		writer.writeScalarPaddedString(rdbnam, CodePoint.RDBNAM_LEN);
-		writer.writeScalarPaddedString(rdbcolid, CodePoint.RDBCOLID_LEN);
-		writer.writeScalarPaddedString(pkgid, CodePoint.PKGID_LEN);
-		writer.writeScalarPaddedBytes(pkgcnstkn,
-					      CodePoint.PKGCNSTKN_LEN, (byte) 0);
-		writer.writeShort(pkgsn);
-	    }
-	else	// extended format
-	    {
-		int len = Math.max(CodePoint.RDBNAM_LEN, rdbnam.length());
-		writer.writeShort(len);
-		writer.writeScalarPaddedString(rdbnam, len);
-		len = Math.max(CodePoint.RDBCOLID_LEN, rdbcolid.length());
-		writer.writeShort(len);
-		writer.writeScalarPaddedString(rdbcolid, len);
-		len = Math.max(CodePoint.PKGID_LEN, pkgid.length());
-		writer.writeShort(len);
-		writer.writeScalarPaddedString(pkgid, len);
-		writer.writeScalarPaddedBytes(pkgcnstkn,
-					      CodePoint.PKGCNSTKN_LEN, (byte) 0);
-		writer.writeShort(pkgsn);
-	    }
+	    pkgid.length() <= CodePoint.PKGID_LEN) {	
+	    // if none of RDBNAM, RDBCOLID and PKGID have a length of
+	    // more than 18, use fixed format
+	    writer.writeScalarPaddedString(rdbnam, CodePoint.RDBNAM_LEN);
+	    writer.writeScalarPaddedString(rdbcolid, CodePoint.RDBCOLID_LEN);
+	    writer.writeScalarPaddedString(pkgid, CodePoint.PKGID_LEN);
+	    writer.writeScalarPaddedBytes(pkgcnstkn,
+					  CodePoint.PKGCNSTKN_LEN, (byte) 0);
+	    writer.writeShort(pkgsn);
+	} else { 	// extended format 
+	    int len = Math.max(CodePoint.RDBNAM_LEN, rdbnam.length());
+	    writer.writeShort(len);
+	    writer.writeScalarPaddedString(rdbnam, len);
+	    len = Math.max(CodePoint.RDBCOLID_LEN, rdbcolid.length());
+	    writer.writeShort(len);
+	    writer.writeScalarPaddedString(rdbcolid, len);
+	    len = Math.max(CodePoint.PKGID_LEN, pkgid.length());
+	    writer.writeShort(len);
+	    writer.writeScalarPaddedString(pkgid, len);
+	    writer.writeScalarPaddedBytes(pkgcnstkn,
+					  CodePoint.PKGCNSTKN_LEN, (byte) 0);
+	    writer.writeShort(pkgsn);
+	}
 	writer.endDdm();
     }
 
-    private void writePKGNAMCSN() throws DRDAProtocolException
-    {
+    private void writePKGNAMCSN() throws DRDAProtocolException {
 	writePKGNAMCSN(pkgcnstkn.getBytes());
     }
 
@@ -2090,8 +1952,7 @@
      * @throws DRDAProtocolException
      * @throws SQLException
      */
-    private DRDAStatement parseCNTQRY() throws DRDAProtocolException, SQLException
-    {
+    private DRDAStatement parseCNTQRY() throws DRDAProtocolException, SQLException {
 	byte val;
 	Pkgnamcsn pkgnamcsn = null;
 	boolean gotQryblksz = false;
@@ -2112,128 +1973,125 @@
 	int rtnextdta = CodePoint.RTNEXTROW;
 	reader.markCollection();
 	int codePoint = reader.getCodePoint();
-	while (codePoint != -1)
-	    {
-		switch(codePoint)
-		    {
-			//optional
-		    case CodePoint.RDBNAM:
-			setDatabase(CodePoint.CNTQRY);
-			break;
-			//required
-		    case CodePoint.PKGNAMCSN:
-			pkgnamcsn = parsePKGNAMCSN();
-			break;
-			//required
-		    case CodePoint.QRYBLKSZ:
-			blksize = parseQRYBLKSZ();
-			gotQryblksz = true;
-			break;
-			//optional
-		    case CodePoint.QRYRELSCR:
-			qryrelscr = readBoolean(CodePoint.QRYRELSCR);
-			if (SanityManager.DEBUG)
-			    trace("qryrelscr = "+qryrelscr);
-			break;
-			//optional
-		    case CodePoint.QRYSCRORN:
-			checkLength(CodePoint.QRYSCRORN, 1);
-			qryscrorn = reader.readUnsignedByte();
-			if (SanityManager.DEBUG)
-			    trace("qryscrorn = "+qryscrorn);
-			switch (qryscrorn)
-			    {
-			    case CodePoint.QRYSCRREL:
-			    case CodePoint.QRYSCRABS:
-			    case CodePoint.QRYSCRAFT:
-			    case CodePoint.QRYSCRBEF:
-				break;
-			    default:
-				invalidValue(CodePoint.QRYSCRORN);
-			    }
-			break;
-			//optional
-		    case CodePoint.QRYROWNBR:
-			checkLength(CodePoint.QRYROWNBR, 8);
-			qryrownbr = reader.readNetworkLong();
-			if (SanityManager.DEBUG)
-			    trace("qryrownbr = "+qryrownbr);
-			break;
-			//optional
-		    case CodePoint.QRYROWSNS:
-			checkLength(CodePoint.QRYROWSNS, 1);
-			qryrowsns = readBoolean(CodePoint.QRYROWSNS);
-			if (SanityManager.DEBUG)
-			    trace("qryrowsns = "+qryrowsns);
-			gotQryrowsns = true;
-			break;
-			//optional
-		    case CodePoint.QRYBLKRST:
-			checkLength(CodePoint.QRYBLKRST, 1);
-			qryblkrst = readBoolean(CodePoint.QRYBLKRST);
-			if (SanityManager.DEBUG)
-			    trace("qryblkrst = "+qryblkrst);
-			break;
-			//optional
-		    case CodePoint.QRYRTNDTA:
-			qryrtndta = readBoolean(CodePoint.QRYRTNDTA);
-			if (SanityManager.DEBUG)
-			    trace("qryrtndta = "+qryrtndta);
-			break;
-			//optional
-		    case CodePoint.QRYROWSET:
-			//Note minimum for CNTQRY is 1
-			qryrowset = parseQRYROWSET(1);
-			if (SanityManager.DEBUG)
-			    trace("qryrowset = "+qryrowset);
-			break;
-			//optional
-		    case CodePoint.QRYRFRTBL:
-			qryrfrtbl = readBoolean(CodePoint.QRYRFRTBL);
-			if (SanityManager.DEBUG)
-			    trace("qryrfrtbl = "+qryrfrtbl);
-			break;
-			//optional
-		    case CodePoint.NBRROW:
-			checkLength(CodePoint.NBRROW, 4);
-			nbrrow = reader.readNetworkInt();
-			if (SanityManager.DEBUG)
-			    trace("nbrrow = "+nbrrow);
-			break;
-			//optional
-		    case CodePoint.MAXBLKEXT:
-			checkLength(CodePoint.MAXBLKEXT, 2);
-			maxblkext = reader.readSignedNetworkShort();
-			if (SanityManager.DEBUG)
-			    trace("maxblkext = "+maxblkext);
-			break;
-			//optional
-		    case CodePoint.RTNEXTDTA:
-			checkLength(CodePoint.RTNEXTDTA, 1);
-			rtnextdta = reader.readUnsignedByte();
-			if (rtnextdta != CodePoint.RTNEXTROW && 
-			    rtnextdta != CodePoint.RTNEXTALL)
-			    invalidValue(CodePoint.RTNEXTDTA);
-			if (SanityManager.DEBUG)
-			    trace("rtnextdta = "+rtnextdta);
-			break;
-			// required for SQLAM >= 7
-		    case CodePoint.QRYINSID:
-			checkLength(CodePoint.QRYINSID, 8);
-			qryinsid = reader.readNetworkLong();
-			gotQryinsid = true;
-			if (SanityManager.DEBUG)
-			    trace("qryinsid = "+qryinsid);
-			break;
-			// optional
-		    case CodePoint.MONITOR:
-			parseMONITOR();
-			break;
-		    default:
-			invalidCodePoint(codePoint);
-		    }
-		codePoint = reader.getCodePoint();
+	while (codePoint != -1) {
+	    switch(codePoint) {
+		//optional
+	    case CodePoint.RDBNAM:
+		setDatabase(CodePoint.CNTQRY);
+		break;
+		//required
+	    case CodePoint.PKGNAMCSN:
+		pkgnamcsn = parsePKGNAMCSN();
+		break;
+		//required
+	    case CodePoint.QRYBLKSZ:
+		blksize = parseQRYBLKSZ();
+		gotQryblksz = true;
+		break;
+		//optional
+	    case CodePoint.QRYRELSCR:
+		qryrelscr = readBoolean(CodePoint.QRYRELSCR);
+		if (SanityManager.DEBUG)
+		    trace("qryrelscr = "+qryrelscr);
+		break;
+		//optional
+	    case CodePoint.QRYSCRORN:
+		checkLength(CodePoint.QRYSCRORN, 1);
+		qryscrorn = reader.readUnsignedByte();
+		if (SanityManager.DEBUG)
+		    trace("qryscrorn = "+qryscrorn);
+		switch (qryscrorn) {
+		case CodePoint.QRYSCRREL:
+		case CodePoint.QRYSCRABS:
+		case CodePoint.QRYSCRAFT:
+		case CodePoint.QRYSCRBEF:
+		    break;
+		default:
+		    invalidValue(CodePoint.QRYSCRORN);
+		}
+		break;
+		//optional
+	    case CodePoint.QRYROWNBR:
+		checkLength(CodePoint.QRYROWNBR, 8);
+		qryrownbr = reader.readNetworkLong();
+		if (SanityManager.DEBUG)
+		    trace("qryrownbr = "+qryrownbr);
+		break;
+		//optional
+	    case CodePoint.QRYROWSNS:
+		checkLength(CodePoint.QRYROWSNS, 1);
+		qryrowsns = readBoolean(CodePoint.QRYROWSNS);
+		if (SanityManager.DEBUG)
+		    trace("qryrowsns = "+qryrowsns);
+		gotQryrowsns = true;
+		break;
+		//optional
+	    case CodePoint.QRYBLKRST:
+		checkLength(CodePoint.QRYBLKRST, 1);
+		qryblkrst = readBoolean(CodePoint.QRYBLKRST);
+		if (SanityManager.DEBUG)
+		    trace("qryblkrst = "+qryblkrst);
+		break;
+		//optional
+	    case CodePoint.QRYRTNDTA:
+		qryrtndta = readBoolean(CodePoint.QRYRTNDTA);
+		if (SanityManager.DEBUG)
+		    trace("qryrtndta = "+qryrtndta);
+		break;
+		//optional
+	    case CodePoint.QRYROWSET:
+		//Note minimum for CNTQRY is 1
+		qryrowset = parseQRYROWSET(1);
+		if (SanityManager.DEBUG)
+		    trace("qryrowset = "+qryrowset);
+		break;
+		//optional
+	    case CodePoint.QRYRFRTBL:
+		qryrfrtbl = readBoolean(CodePoint.QRYRFRTBL);
+		if (SanityManager.DEBUG)
+		    trace("qryrfrtbl = "+qryrfrtbl);
+		break;
+		//optional
+	    case CodePoint.NBRROW:
+		checkLength(CodePoint.NBRROW, 4);
+		nbrrow = reader.readNetworkInt();
+		if (SanityManager.DEBUG)
+		    trace("nbrrow = "+nbrrow);
+		break;
+		//optional
+	    case CodePoint.MAXBLKEXT:
+		checkLength(CodePoint.MAXBLKEXT, 2);
+		maxblkext = reader.readSignedNetworkShort();
+		if (SanityManager.DEBUG)
+		    trace("maxblkext = "+maxblkext);
+		break;
+		//optional
+	    case CodePoint.RTNEXTDTA:
+		checkLength(CodePoint.RTNEXTDTA, 1);
+		rtnextdta = reader.readUnsignedByte();
+		if (rtnextdta != CodePoint.RTNEXTROW && 
+		    rtnextdta != CodePoint.RTNEXTALL)
+		    invalidValue(CodePoint.RTNEXTDTA);
+		if (SanityManager.DEBUG)
+		    trace("rtnextdta = "+rtnextdta);
+		break;
+		// required for SQLAM >= 7
+	    case CodePoint.QRYINSID:
+		checkLength(CodePoint.QRYINSID, 8);
+		qryinsid = reader.readNetworkLong();
+		gotQryinsid = true;
+		if (SanityManager.DEBUG)
+		    trace("qryinsid = "+qryinsid);
+		break;
+		// optional
+	    case CodePoint.MONITOR:
+		parseMONITOR();
+		break;
+	    default:
+		invalidCodePoint(codePoint);
 	    }
+	    codePoint = reader.getCodePoint();
+	}
 	// check for required variables
 	if (pkgnamcsn == null)
 	    missingCodePoint(CodePoint.PKGNAMCSN);
@@ -2244,18 +2102,16 @@
 
 	// get the statement we are continuing
 	DRDAStatement stmt = database.getDRDAStatement(pkgnamcsn);
-	if (stmt == null)
-	    {
-		//XXX should really throw a SQL Exception here
-		invalidValue(CodePoint.CNTQRY);
-	    }
+	if (stmt == null) {
+	    //XXX should really throw a SQL Exception here
+	    invalidValue(CodePoint.CNTQRY);
+	}
 
-	if (stmt.rsIsClosed())
-	    {
-		writeQRYNOPRM(CodePoint.SVRCOD_ERROR);
-		skipRemainder(true);
-		return null;
-	    }
+	if (stmt.rsIsClosed()) {
+	    writeQRYNOPRM(CodePoint.SVRCOD_ERROR);
+	    skipRemainder(true);
+	    return null;
+	}
 	stmt.setQueryOptions(blksize,qryrelscr,qryrownbr,qryrfrtbl,nbrrow,maxblkext,
 			     qryscrorn,qryrowsns,qryblkrst,qryrtndta,qryrowset,
 			     rtnextdta);
@@ -2273,15 +2129,13 @@
      *   chained with same or different ids.
      * @exception DRDAProtocolException
      */
-    private void skipRemainder(boolean onlySkipSameIds) throws DRDAProtocolException
-    {
+    private void skipRemainder(boolean onlySkipSameIds) throws DRDAProtocolException {
 	reader.skipDss();
 	while (reader.isChainedWithSameID() ||
-	       (!onlySkipSameIds && reader.isChainedWithDiffID()))
-	    {
-		reader.readDssHeader();
-		reader.skipDss();
-	    }
+	       (!onlySkipSameIds && reader.isChainedWithDiffID())) {
+	    reader.readDssHeader();
+	    reader.skipDss();
+	}
     }
     /**
      * Parse CNTQRY objects
@@ -2291,26 +2145,22 @@
      * @param stmt DRDA statement we are working on
      * @exception DRDAProtocolException
      */
-    private void parseCNTQRYobjects(DRDAStatement stmt) throws DRDAProtocolException, SQLException
-    {
+    private void parseCNTQRYobjects(DRDAStatement stmt) throws DRDAProtocolException, SQLException {
 	int codePoint;
-	do
-	    {
-		correlationID = reader.readDssHeader();
-		while (reader.moreDssData())
-		    {
-			codePoint = reader.readLengthAndCodePoint();
-			switch(codePoint)
-			    {
-				// optional
-			    case CodePoint.OUTOVR:
-				parseOUTOVR(stmt);
-				break;
-			    default:
-				invalidCodePoint(codePoint);
-			    }
-		    }
-	    } while (reader.isChainedWithSameID());
+	do {
+	    correlationID = reader.readDssHeader();
+	    while (reader.moreDssData()) {
+		codePoint = reader.readLengthAndCodePoint();
+		switch(codePoint) {
+		    // optional
+		case CodePoint.OUTOVR:
+		    parseOUTOVR(stmt);
+		    break;
+		default:
+		    invalidCodePoint(codePoint);
+		}
+	    }
+	} while (reader.isChainedWithSameID());
 
     }
     /**
@@ -2321,8 +2171,7 @@
      * @param stmt	DRDA statement this applies to
      * @exception DRDAProtocolException
      */
-    private void parseOUTOVR(DRDAStatement stmt) throws DRDAProtocolException, SQLException
-    {
+    private void parseOUTOVR(DRDAStatement stmt) throws DRDAProtocolException, SQLException {
 	boolean first = true;
 	int numVars;
 	int dtaGrpLen;
@@ -2330,50 +2179,44 @@
 	int tripId;
 	int precision;
 	int start = 0;
-	while (true)
-	    {
-		dtaGrpLen = reader.readUnsignedByte();
-		tripType = reader.readUnsignedByte();
-		tripId = reader.readUnsignedByte();
-		// check if we have reached the end of the data
-		if (tripType == FdocaConstants.RLO_TRIPLET_TYPE)
-		    {
-			//read last part of footer
-			reader.skipBytes();
-			break;
-		    }
-		numVars = (dtaGrpLen - 3) / 3;
+	while (true) {
+	    dtaGrpLen = reader.readUnsignedByte();
+	    tripType = reader.readUnsignedByte();
+	    tripId = reader.readUnsignedByte();
+	    // check if we have reached the end of the data
+	    if (tripType == FdocaConstants.RLO_TRIPLET_TYPE) {
+		//read last part of footer
+		reader.skipBytes();
+		break;
+	    }
+	    numVars = (dtaGrpLen - 3) / 3;
+	    if (SanityManager.DEBUG)
+		trace("num of vars is: "+numVars);
+	    int[] outovr_drdaType = null;
+	    if (first) {
+		outovr_drdaType = new int[numVars];
+		first = false;
+	    } else {
+		int[] oldoutovr_drdaType = stmt.getOutovr_drdaType();
+		int oldlen = oldoutovr_drdaType.length;
+		// create new array and copy over already read stuff
+		outovr_drdaType = new int[oldlen + numVars];
+		System.arraycopy(oldoutovr_drdaType, 0,
+				 outovr_drdaType,0,
+				 oldlen);
+		start = oldlen;
+	    }
+	    for (int i = start; i < numVars + start; i++) {
+		outovr_drdaType[i] = reader.readUnsignedByte();
 		if (SanityManager.DEBUG)
-		    trace("num of vars is: "+numVars);
-		int[] outovr_drdaType = null;
-		if (first)
-		    {
-			outovr_drdaType = new int[numVars];
-			first = false;
-		    }
-		else
-		    {
-			int[] oldoutovr_drdaType = stmt.getOutovr_drdaType();
-			int oldlen = oldoutovr_drdaType.length;
-			// create new array and copy over already read stuff
-			outovr_drdaType = new int[oldlen + numVars];
-			System.arraycopy(oldoutovr_drdaType, 0,
-					 outovr_drdaType,0,
-					 oldlen);
-			start = oldlen;
-		    }
-		for (int i = start; i < numVars + start; i++)
-		    {
-			outovr_drdaType[i] = reader.readUnsignedByte();
-			if (SanityManager.DEBUG)
-			    trace("drdaType is: "+ outovr_drdaType[i]);
-			precision = reader.readNetworkShort();
-			if (SanityManager.DEBUG)
-			    trace("drdaLength is: "+precision);
-			outovr_drdaType[i] |= (precision << 8);
-		    }
-		stmt.setOutovr_drdaType(outovr_drdaType);
+		    trace("drdaType is: "+ outovr_drdaType[i]);
+		precision = reader.readNetworkShort();
+		if (SanityManager.DEBUG)
+		    trace("drdaLength is: "+precision);
+		outovr_drdaType[i] |= (precision << 8);
 	    }
+	    stmt.setOutovr_drdaType(outovr_drdaType);
+	}
     }
 
     /**
@@ -2394,8 +2237,7 @@
      * @exception DRDAProtocolException
      */
     private void writeOPNQRYRM(boolean isDssObject, DRDAStatement stmt) 
-	throws DRDAProtocolException, SQLException
-    {
+	throws DRDAProtocolException, SQLException {
 	if (SanityManager.DEBUG)
 	    trace("WriteOPNQRYRM");
 
@@ -2420,51 +2262,49 @@
 	//in the stored procedure, not the holdability of the calling statement.
 	if (stmt.getCurrentDrdaResultSet().withHoldCursor == JDBC30Translation.HOLD_CURSORS_OVER_COMMIT)
 	    writer.writeScalar1Byte(CodePoint.SQLCSRHLD, CodePoint.TRUE);
-	if (sqlamLevel >= MGRLVL_7)
-	    {
-		writer.writeScalarHeader(CodePoint.QRYINSID, 8);
-		//This is implementer defined.  DB2 uses this for the nesting level
-		//of the query.  A query from an application would be nesting level 0,
-		//from a stored procedure, nesting level 1, from a recursive call of
-		//a stored procedure, nesting level 2, etc.
-		writer.writeInt(0);     
-		//This is a unique sequence number per session
-		writer.writeInt(session.qryinsid++);
-		//Write the scroll attributes if they are set
-		if (stmt.isScrollable())
-		    {
-			writer.writeScalar1Byte(CodePoint.QRYATTSCR, CodePoint.TRUE);
-			if ((stmt.getConcurType() == ResultSet.CONCUR_UPDATABLE) &&
-			    (stmt.getResultSet().getType() == 
-			     ResultSet.TYPE_SCROLL_INSENSITIVE)) {
-			    writer.writeScalar1Byte(CodePoint.QRYATTSNS, 
-						    CodePoint.QRYSNSSTC);
-			} else {
-			    writer.writeScalar1Byte(CodePoint.QRYATTSNS, 
-						    CodePoint.QRYINS);
-			}
-		    }
-		if (stmt.getConcurType() == ResultSet.CONCUR_UPDATABLE) {
-		    if (stmt.getResultSet() != null) { 
-			// Resultset concurrency can be less than statement
-			// concurreny if the underlying language resultset
-			// is not updatable.
-			if (stmt.getResultSet().getConcurrency() == 
-			    ResultSet.CONCUR_UPDATABLE) {
-			    writer.writeScalar1Byte(CodePoint.QRYATTUPD, 
-						    CodePoint.QRYUPD);
-			} else {
-			    writer.writeScalar1Byte(CodePoint.QRYATTUPD, 
-						    CodePoint.QRYRDO);
-			}
-		    } else {
+	if (sqlamLevel >= MGRLVL_7) {
+	    writer.writeScalarHeader(CodePoint.QRYINSID, 8);
+	    //This is implementer defined.  DB2 uses this for the nesting level
+	    //of the query.  A query from an application would be nesting level 0,
+	    //from a stored procedure, nesting level 1, from a recursive call of
+	    //a stored procedure, nesting level 2, etc.
+	    writer.writeInt(0);     
+	    //This is a unique sequence number per session
+	    writer.writeInt(session.qryinsid++);
+	    //Write the scroll attributes if they are set
+	    if (stmt.isScrollable()) {
+		writer.writeScalar1Byte(CodePoint.QRYATTSCR, CodePoint.TRUE);
+		if ((stmt.getConcurType() == ResultSet.CONCUR_UPDATABLE) &&
+		    (stmt.getResultSet().getType() == 
+		     ResultSet.TYPE_SCROLL_INSENSITIVE)) {
+		    writer.writeScalar1Byte(CodePoint.QRYATTSNS, 
+					    CodePoint.QRYSNSSTC);
+		} else {
+		    writer.writeScalar1Byte(CodePoint.QRYATTSNS, 
+					    CodePoint.QRYINS);
+		}
+	    }
+	    if (stmt.getConcurType() == ResultSet.CONCUR_UPDATABLE) {
+		if (stmt.getResultSet() != null) { 
+		    // Resultset concurrency can be less than statement
+		    // concurreny if the underlying language resultset
+		    // is not updatable.
+		    if (stmt.getResultSet().getConcurrency() == 
+			ResultSet.CONCUR_UPDATABLE) {
 			writer.writeScalar1Byte(CodePoint.QRYATTUPD, 
 						CodePoint.QRYUPD);
+		    } else {
+			writer.writeScalar1Byte(CodePoint.QRYATTUPD, 
+						CodePoint.QRYRDO);
 		    }
 		} else {
-		    writer.writeScalar1Byte(CodePoint.QRYATTUPD, CodePoint.QRYRDO);
+		    writer.writeScalar1Byte(CodePoint.QRYATTUPD, 
+					    CodePoint.QRYUPD);
 		}
+	    } else {
+		writer.writeScalar1Byte(CodePoint.QRYATTUPD, CodePoint.QRYRDO);
 	    }
+	}
 	writer.endDdmAndDss ();
     }
     /**
@@ -2474,8 +2314,7 @@
      * @param svrCod  Severity code - WARNING or ERROR
      * @exception DRDAProtocolException
      */
-    private void writeENDQRYRM(int svrCod) throws DRDAProtocolException
-    {
+    private void writeENDQRYRM(int svrCod) throws DRDAProtocolException {
 	writer.createDssReply();
 	writer.startDdm(CodePoint.ENDQRYRM);
 	writer.writeScalar2Bytes(CodePoint.SVRCOD,svrCod);
@@ -2487,8 +2326,7 @@
      * Severity code is always error
      * 	 * @exception DRDAProtocolException
      */
-    private void writeABNUOWRM() throws DRDAProtocolException
-    {
+    private void writeABNUOWRM() throws DRDAProtocolException {
 	writer.createDssReply();
 	writer.startDdm(CodePoint.ABNUOWRM);
 	writer.writeScalar2Bytes(CodePoint.SVRCOD,CodePoint.SVRCOD_ERROR);
@@ -2502,15 +2340,13 @@
      *
      * @exception DRDAProtocolException
      */
-    private String parseRDBNAM() throws DRDAProtocolException
-    {
+    private String parseRDBNAM() throws DRDAProtocolException {
 	String name;
 	byte [] rdbName = reader.readBytes();
-	if (rdbName.length == 0)
-	    {
-		// throw RDBNFNRM
-		rdbNotFound(null);
-	    }
+	if (rdbName.length == 0) {
+	    // throw RDBNFNRM
+	    rdbNotFound(null);
+	}
 	//SQLAM level 7 allows db name up to 255, level 6 fixed len 18
 	if (rdbName.length < CodePoint.RDBNAM_LEN || rdbName.length > CodePoint.MAX_NAME)
 	    badObjectLength(CodePoint.RDBNAM);
@@ -2538,44 +2374,38 @@
      * @exception DRDAProtocolException
      */
     private void writeACCSECRD(int securityCheckCode)
-	throws DRDAProtocolException
-    {
+	throws DRDAProtocolException {
 	writer.createDssReply();
 	writer.startDdm(CodePoint.ACCSECRD);
 	if (securityCheckCode != CodePoint.SECCHKCD_NOTSUPPORTED)
 	    writer.writeScalar2Bytes(CodePoint.SECMEC, database.securityMechanism);
-	else
-	    { 
-		// if server doesnt recognize or allow the client requested security mechanism,
-		// then need to return the list of security mechanisms supported/allowed by the server
+	else { 
+	    // if server doesnt recognize or allow the client requested security mechanism,
+	    // then need to return the list of security mechanisms supported/allowed by the server
             
-		// check if server is set to accept connections from client at a certain 
-		// security mechanism, if so send only the security mechanism  that the 
-		// server will accept, to the client
-		if ( server.getSecurityMechanism() != NetworkServerControlImpl.INVALID_OR_NOTSET_SECURITYMECHANISM )
-		    writer.writeScalar2Bytes(CodePoint.SECMEC,server.getSecurityMechanism());
-		else
-		    {
-			// note: per the DDM manual , ACCSECRD response is of 
-			// form SECMEC (value{value..})  
-			// Need to fix the below to send a list of supported security 
-			// mechanisms for value of one SECMEC codepoint (JIRA 926)
-			// these are the ones we know about
-			writer.writeScalar2Bytes(CodePoint.SECMEC, CodePoint.SECMEC_USRIDPWD);
-			writer.writeScalar2Bytes(CodePoint.SECMEC, CodePoint.SECMEC_EUSRIDPWD);
-			writer.writeScalar2Bytes(CodePoint.SECMEC, CodePoint.SECMEC_USRIDONL);
-		    }
-	    }
-	if (securityCheckCode != 0)
-	    {
-		writer.writeScalar1Byte(CodePoint.SECCHKCD, securityCheckCode);
-	    }
-	else
-	    {
-		// we need to send back the key if encryption is being used
-		if (database.securityMechanism == CodePoint.SECMEC_EUSRIDPWD)
-		    writer.writeScalarBytes(CodePoint.SECTKN, myPublicKey);
+	    // check if server is set to accept connections from client at a certain 
+	    // security mechanism, if so send only the security mechanism  that the 
+	    // server will accept, to the client
+	    if ( server.getSecurityMechanism() != NetworkServerControlImpl.INVALID_OR_NOTSET_SECURITYMECHANISM )
+		writer.writeScalar2Bytes(CodePoint.SECMEC,server.getSecurityMechanism());
+	    else {
+		// note: per the DDM manual , ACCSECRD response is of 
+		// form SECMEC (value{value..})  
+		// Need to fix the below to send a list of supported security 
+		// mechanisms for value of one SECMEC codepoint (JIRA 926)
+		// these are the ones we know about
+		writer.writeScalar2Bytes(CodePoint.SECMEC, CodePoint.SECMEC_USRIDPWD);
+		writer.writeScalar2Bytes(CodePoint.SECMEC, CodePoint.SECMEC_EUSRIDPWD);
+		writer.writeScalar2Bytes(CodePoint.SECMEC, CodePoint.SECMEC_USRIDONL);
 	    }
+	}
+	if (securityCheckCode != 0) {
+	    writer.writeScalar1Byte(CodePoint.SECCHKCD, securityCheckCode);
+	} else {
+	    // we need to send back the key if encryption is being used
+	    if (database.securityMechanism == CodePoint.SECMEC_EUSRIDPWD)
+		writer.writeScalarBytes(CodePoint.SECTKN, myPublicKey);
+	}
     	writer.endDdmAndDss ();
 
 	if (securityCheckCode != 0) {
@@ -2602,107 +2432,96 @@
      * @return security check code
      * @exception DRDAProtocolException
      */
-    private int parseSECCHK() throws DRDAProtocolException
-    {
+    private int parseSECCHK() throws DRDAProtocolException {
 	int codePoint, securityCheckCode = 0;
 	int securityMechanism = 0;
 	databaseAccessException = null;
 	reader.markCollection();
 	codePoint = reader.getCodePoint();
-	while (codePoint != -1)
-	    {
-		switch (codePoint)
-		    {
-			//optional, ignorable
-		    case CodePoint.SECMGRNM:
-			reader.skipBytes();
-			break;
-			//required
-		    case CodePoint.SECMEC:
-			checkLength(CodePoint.SECMEC, 2);
-			securityMechanism = reader.readNetworkShort();
-			if (SanityManager.DEBUG) 
-			    trace("Security mechanism = " + securityMechanism);
-			//RESOLVE - spec is not clear on what should happen
-			//in this case
-			if (securityMechanism != database.securityMechanism)
-			    invalidValue(CodePoint.SECMEC);
-			break;
-			//optional - depending on security Mechanism 
-		    case CodePoint.SECTKN:
-			if (database.securityMechanism != CodePoint.SECMEC_EUSRIDPWD)
-			    {
-				securityCheckCode = CodePoint.SECCHKCD_SECTKNMISSING_OR_INVALID;
-				reader.skipBytes();
-			    }
-			else if (database.decryptedUserId == null) {
-			    try {
-				database.decryptedUserId = reader.readEncryptedString(decryptionManager,
-										      database.securityMechanism, myPublicKey, database.publicKeyIn);
-			    } catch (SQLException se)
-				{
-				    println2Log(database.dbName, session.drdaID, se.getMessage());
-				    if (securityCheckCode == 0)
-					securityCheckCode = CodePoint.SECCHKCD_13;	//userid invalid
-				}
-			    database.userId = database.decryptedUserId;
-			    if (SanityManager.DEBUG) trace("**decrypted userid is: "+database.userId);
-			}
-			else if (database.decryptedPassword == null) {
-			    try {
-				database.decryptedPassword = reader.readEncryptedString(decryptionManager,
-											database.securityMechanism, myPublicKey, database.publicKeyIn);
-			    } catch (SQLException se)
-				{	
-				    println2Log(database.dbName, session.drdaID, se.getMessage());
-				    if (securityCheckCode == 0)
-					securityCheckCode = CodePoint.SECCHKCD_0F;	//password invalid
-				}
-			    database.password = database.decryptedPassword;
-			    if (SanityManager.DEBUG) trace("**decrypted password is: "+database.password);
-			}
-			else
-			    {
-				tooMany(CodePoint.SECTKN);
-			    }
-			break;
-			//optional - depending on security Mechanism
-		    case CodePoint.PASSWORD:
-			database.password = reader.readString();
-			if (SanityManager.DEBUG) trace("PASSWORD " + database.password);
-			break;
-			//optional - depending on security Mechanism
-			//we are not supporting this method so we'll skip bytes
-		    case CodePoint.NEWPASSWORD:
-			reader.skipBytes();
-			break;
-			//optional - depending on security Mechanism
-		    case CodePoint.USRID:
-			database.userId = reader.readString();
-			if (SanityManager.DEBUG) trace("USERID " + database.userId);
-			break;
-			//optional - depending on security Mechanism
-		    case CodePoint.RDBNAM:
-			String dbname = parseRDBNAM();
-			if (database != null) 
-			    {
-				if (!database.dbName.equals(dbname))
-				    rdbnamMismatch(CodePoint.SECCHK);
-			    }
-			else
-			    {
-				// we should already have added the database in ACCSEC
-				// added code here in case we make the SECMEC session rather
-				// than database wide
-				addDatabase(dbname);
-			    }
-			break;
-		    default:

[... 5500 lines stripped ...]


Mime
View raw message