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