List of usage examples for java.sql Types SMALLINT
int SMALLINT
To view the source code for java.sql Types SMALLINT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type SMALLINT
.
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * Return a SQL string to act as a placeholder for the given column. *//*from ww w.ja v a 2s . c om*/ public String getPlaceholderValueString(Column col) { switch (col.getType()) { case Types.BIGINT: case Types.BIT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.TINYINT: return "0"; case Types.CHAR: return (storeCharsAsNumbers) ? "0" : "' '"; case Types.CLOB: case Types.LONGVARCHAR: case Types.VARCHAR: return "''"; case Types.DATE: return ZERO_DATE_STR; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: return "0.0"; case Types.TIME: return ZERO_TIME_STR; case Types.TIMESTAMP: return ZERO_TIMESTAMP_STR; default: return "NULL"; } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMySql.CFAccMySqlAccountEntryTable.java
public void updateAccountEntry(CFAccAuthorization Authorization, CFAccAccountEntryBuff Buff) { final String S_ProcName = "updateAccountEntry"; ResultSet resultSet = null;/* ww w .j a va 2 s . co m*/ try { long TenantId = Buff.getRequiredTenantId(); long AccountId = Buff.getRequiredAccountId(); UUID EntryId = Buff.getRequiredEntryId(); UUID SplitEntryId = Buff.getOptionalSplitEntryId(); Calendar EntryStamp = Buff.getRequiredEntryStamp(); String Description = Buff.getRequiredDescription(); Long TransferTenantId = Buff.getOptionalTransferTenantId(); Long TransferAccountId = Buff.getOptionalTransferAccountId(); Short DebitCurrencyId = Buff.getOptionalDebitCurrencyId(); BigDecimal Debit = Buff.getOptionalDebit(); Short CreditCurrencyId = Buff.getOptionalCreditCurrencyId(); BigDecimal Credit = Buff.getOptionalCredit(); short ConvertedCurrencyId = Buff.getRequiredConvertedCurrencyId(); BigDecimal ConvertedAmount = Buff.getRequiredConvertedAmount(); short BalanceCurrencyId = Buff.getRequiredBalanceCurrencyId(); BigDecimal Balance = Buff.getRequiredBalance(); int Revision = Buff.getRequiredRevision(); Connection cnx = schema.getCnx(); String sql = "call " + schema.getLowerSchemaDbName() + ".sp_update_ac_entry( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "timestamp( ? )" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtUpdateByPKey == null) { stmtUpdateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtUpdateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtUpdateByPKey.setString(argIdx++, "ACNY"); stmtUpdateByPKey.setLong(argIdx++, TenantId); stmtUpdateByPKey.setLong(argIdx++, AccountId); stmtUpdateByPKey.setString(argIdx++, EntryId.toString()); if (SplitEntryId != null) { stmtUpdateByPKey.setString(argIdx++, SplitEntryId.toString()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtUpdateByPKey.setString(argIdx++, CFAccMySqlSchema.getTimestampString(EntryStamp)); stmtUpdateByPKey.setString(argIdx++, Description); if (TransferTenantId != null) { stmtUpdateByPKey.setLong(argIdx++, TransferTenantId.longValue()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.BIGINT); } if (TransferAccountId != null) { stmtUpdateByPKey.setLong(argIdx++, TransferAccountId.longValue()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.BIGINT); } if (DebitCurrencyId != null) { stmtUpdateByPKey.setShort(argIdx++, DebitCurrencyId.shortValue()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.SMALLINT); } if (Debit != null) { stmtUpdateByPKey.setBigDecimal(argIdx++, Debit); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.NUMERIC); } if (CreditCurrencyId != null) { stmtUpdateByPKey.setShort(argIdx++, CreditCurrencyId.shortValue()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.SMALLINT); } if (Credit != null) { stmtUpdateByPKey.setBigDecimal(argIdx++, Credit); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.NUMERIC); } stmtUpdateByPKey.setShort(argIdx++, ConvertedCurrencyId); stmtUpdateByPKey.setBigDecimal(argIdx++, ConvertedAmount); stmtUpdateByPKey.setShort(argIdx++, BalanceCurrencyId); stmtUpdateByPKey.setBigDecimal(argIdx++, Balance); stmtUpdateByPKey.setInt(argIdx++, Revision); try { resultSet = stmtUpdateByPKey.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFAccAccountEntryBuff updatedBuff = unpackAccountEntryResultSetToBuff(resultSet); if ((resultSet != null) && resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setOptionalSplitEntryId(updatedBuff.getOptionalSplitEntryId()); Buff.setRequiredEntryStamp(updatedBuff.getRequiredEntryStamp()); Buff.setRequiredDescription(updatedBuff.getRequiredDescription()); Buff.setOptionalTransferTenantId(updatedBuff.getOptionalTransferTenantId()); Buff.setOptionalTransferAccountId(updatedBuff.getOptionalTransferAccountId()); Buff.setOptionalDebitCurrencyId(updatedBuff.getOptionalDebitCurrencyId()); Buff.setOptionalDebit(updatedBuff.getOptionalDebit()); Buff.setOptionalCreditCurrencyId(updatedBuff.getOptionalCreditCurrencyId()); Buff.setOptionalCredit(updatedBuff.getOptionalCredit()); Buff.setRequiredConvertedCurrencyId(updatedBuff.getRequiredConvertedCurrencyId()); Buff.setRequiredConvertedAmount(updatedBuff.getRequiredConvertedAmount()); Buff.setRequiredBalanceCurrencyId(updatedBuff.getRequiredBalanceCurrencyId()); Buff.setRequiredBalance(updatedBuff.getRequiredBalance()); Buff.setRequiredRevision(updatedBuff.getRequiredRevision()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbPgSql.CFGenKbPgSqlNmTokenFormatterTable.java
public void deleteNmTokenFormatterByScopeIdx(CFGenKbAuthorization Authorization, Short argScopeDefId) { final String S_ProcName = "deleteNmTokenFormatterByScopeIdx"; ResultSet resultSet = null;// w w w .j a va2 s. com try { Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerSchemaDbName() + ".sp_delete_kbnmtokenfmt_by_scopeidx( ?, ?, ?, ?, ?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByScopeIdx == null) { stmtDeleteByScopeIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByScopeIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByScopeIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByScopeIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByScopeIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByScopeIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); if (argScopeDefId != null) { stmtDeleteByScopeIdx.setShort(argIdx++, argScopeDefId.shortValue()); } else { stmtDeleteByScopeIdx.setNull(argIdx++, java.sql.Types.SMALLINT); } resultSet = stmtDeleteByScopeIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an unique index. *//*ww w.ja v a 2s. c om*/ public void testSingleUniqueIndex() throws Exception { Database model = readModel("<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='TableWithIndex'>\n" + " <column name='id'\n" + " type='DOUBLE'\n" + " primaryKey='true'\n" + " required='true'/>\n" + " <column name='value'\n" + " type='SMALLINT'\n" + " default='1'/>\n" + " <unique>\n" + " <unique-column name='value'/>\n" + " </unique>\n" + " </table>\n" + "</database>"); assertEquals("test", model.getName()); assertEquals(1, model.getTableCount()); Table table = model.getTable(0); assertEquals("TableWithIndex", null, 2, 1, 0, 0, 1, table); assertEquals("id", Types.DOUBLE, 0, 0, null, null, null, true, true, false, table.getColumn(0)); assertEquals("value", Types.SMALLINT, 0, 0, "1", null, null, false, false, false, table.getColumn(1)); Index index = table.getIndex(0); assertEquals(null, true, 1, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" + " <table name=\"TableWithIndex\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\" autoIncrement=\"false\" />\n" + " <column name=\"value\" primaryKey=\"false\" required=\"false\" type=\"SMALLINT\" default=\"1\" autoIncrement=\"false\" />\n" + " <unique>\n" + " <unique-column name=\"value\" />\n" + " </unique>\n" + " </table>\n" + "</database>\n", model); }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an unique index with two columns. *///www . ja va 2 s. co m public void testUniqueIndexWithTwoColumns() throws Exception { Database model = readModel("<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='TableWithIndex'>\n" + " <column name='id'\n" + " type='DOUBLE'\n" + " primaryKey='true'\n" + " required='true'/>\n" + " <column name='when'\n" + " type='TIMESTAMP'\n" + " required='true'/>\n" + " <column name='value'\n" + " type='SMALLINT'\n" + " default='1'/>\n" + " <unique>\n" + " <unique-column name='when'/>\n" + " <unique-column name='id'/>\n" + " </unique>\n" + " </table>\n" + "</database>"); assertEquals("test", model.getName()); assertEquals(1, model.getTableCount()); Table table = model.getTable(0); assertEquals("TableWithIndex", null, 3, 1, 0, 0, 1, table); assertEquals("id", Types.DOUBLE, 0, 0, null, null, null, true, true, false, table.getColumn(0)); assertEquals("when", Types.TIMESTAMP, 0, 0, null, null, null, false, true, false, table.getColumn(1)); assertEquals("value", Types.SMALLINT, 0, 0, "1", null, null, false, false, false, table.getColumn(2)); Index index = table.getIndex(0); assertEquals(null, true, 2, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals(table.getColumn(0), null, index.getColumn(1)); assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" + " <table name=\"TableWithIndex\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\" autoIncrement=\"false\" />\n" + " <column name=\"when\" primaryKey=\"false\" required=\"true\" type=\"TIMESTAMP\" autoIncrement=\"false\" />\n" + " <column name=\"value\" primaryKey=\"false\" required=\"false\" type=\"SMALLINT\" default=\"1\" autoIncrement=\"false\" />\n" + " <unique>\n" + " <unique-column name=\"when\" />\n" + " <unique-column name=\"id\" />\n" + " </unique>\n" + " </table>\n" + "</database>\n", model); }
From source file:axiom.objectmodel.db.NodeManager.java
/** * Create a new Node from a ResultSet./*from w w w. j a v a2s .c o m*/ */ public Node createNode(DbMapping dbm, ResultSet rs, DbColumn[] columns, int offset) throws SQLException, IOException, ClassNotFoundException { HashMap propBuffer = new HashMap(); String id = null; String name = null; String protoName = dbm.getTypeName(); DbMapping dbmap = dbm; Node node = new Node(); for (int i = 0; i < columns.length; i++) { // set prototype? if (columns[i].isPrototypeField()) { protoName = rs.getString(i + 1 + offset); if (protoName != null) { dbmap = getDbMapping(protoName); if (dbmap == null) { // invalid prototype name! app.logError(ErrorReporter.errorMsg(this.getClass(), "createNode") + "Invalid prototype name: " + protoName + " - using default"); dbmap = dbm; protoName = dbmap.getTypeName(); } } } // set id? if (columns[i].isIdField()) { id = rs.getString(i + 1 + offset); // if id == null, the object doesn't actually exist - return null if (id == null) { return null; } } // set name? if (columns[i].isNameField()) { name = rs.getString(i + 1 + offset); } Property newprop = new Property(node); switch (columns[i].getType()) { case Types.BIT: newprop.setBooleanValue(rs.getBoolean(i + 1 + offset)); break; case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: newprop.setIntegerValue(rs.getLong(i + 1 + offset)); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: newprop.setFloatValue(rs.getDouble(i + 1 + offset)); break; case Types.DECIMAL: case Types.NUMERIC: BigDecimal num = rs.getBigDecimal(i + 1 + offset); if (num == null) { break; } if (num.scale() > 0) { newprop.setFloatValue(num.doubleValue()); } else { newprop.setIntegerValue(num.longValue()); } break; case Types.VARBINARY: case Types.BINARY: // newprop.setStringValue(rs.getString(i+1+offset)); newprop.setJavaObjectValue(rs.getBytes(i + 1 + offset)); break; case Types.LONGVARBINARY: { InputStream in = rs.getBinaryStream(i + 1 + offset); if (in == null) { break; } ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buffer = new byte[2048]; int read; while ((read = in.read(buffer)) > -1) { bout.write(buffer, 0, read); } newprop.setJavaObjectValue(bout.toByteArray()); } break; case Types.LONGVARCHAR: try { newprop.setStringValue(rs.getString(i + 1 + offset)); } catch (SQLException x) { Reader in = rs.getCharacterStream(i + 1 + offset); char[] buffer = new char[2048]; int read = 0; int r; while ((r = in.read(buffer, read, buffer.length - read)) > -1) { read += r; if (read == buffer.length) { // grow input buffer char[] newBuffer = new char[buffer.length * 2]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); buffer = newBuffer; } } newprop.setStringValue(new String(buffer, 0, read)); } break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: newprop.setStringValue(rs.getString(i + 1 + offset)); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: newprop.setDateValue(rs.getTimestamp(i + 1 + offset)); break; case Types.NULL: newprop.setStringValue(null); break; case Types.CLOB: Clob cl = rs.getClob(i + 1 + offset); if (cl == null) { newprop.setStringValue(null); break; } char[] c = new char[(int) cl.length()]; Reader isr = cl.getCharacterStream(); isr.read(c); newprop.setStringValue(String.copyValueOf(c)); break; default: newprop.setStringValue(rs.getString(i + 1 + offset)); break; } if (rs.wasNull()) { newprop.setStringValue(null); } propBuffer.put(columns[i].getName(), newprop); // mark property as clean, since it's fresh from the db newprop.dirty = false; } if (id == null) { return null; } Hashtable propMap = new Hashtable(); DbColumn[] columns2 = dbmap.getColumns(); for (int i = 0; i < columns2.length; i++) { Relation rel = columns2[i].getRelation(); if (rel != null && (rel.reftype == Relation.PRIMITIVE || rel.reftype == Relation.REFERENCE)) { Property prop = (Property) propBuffer.get(columns2[i].getName()); if (prop == null) { continue; } prop.setName(rel.propName); // if the property is a pointer to another node, change the property type to NODE if ((rel.reftype == Relation.REFERENCE) && rel.usesPrimaryKey()) { // FIXME: References to anything other than the primary key are not supported prop.convertToNodeReference(rel.otherType, this.app.getCurrentRequestEvaluator().getLayer()); } propMap.put(rel.propName.toLowerCase(), prop); } } node.init(dbmap, id, name, protoName, propMap, safe); return node; }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbPgSql.CFGenKbPgSqlNmTokenFormatterTable.java
public void deleteNmTokenFormatterByAltIdx(CFGenKbAuthorization Authorization, String argName, short argToolSetId, Short argScopeDefId, short argGenDefId) { final String S_ProcName = "deleteNmTokenFormatterByAltIdx"; ResultSet resultSet = null;/* w w w . j av a2s .c om*/ try { Connection cnx = schema.getCnx(); String sql = "SELECT " + schema.getLowerSchemaDbName() + ".sp_delete_kbnmtokenfmt_by_altidx( ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " ) as DeletedFlag"; if (stmtDeleteByAltIdx == null) { stmtDeleteByAltIdx = cnx.prepareStatement(sql); } int argIdx = 1; stmtDeleteByAltIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByAltIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtDeleteByAltIdx.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtDeleteByAltIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtDeleteByAltIdx.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtDeleteByAltIdx.setString(argIdx++, argName); stmtDeleteByAltIdx.setShort(argIdx++, argToolSetId); if (argScopeDefId != null) { stmtDeleteByAltIdx.setShort(argIdx++, argScopeDefId.shortValue()); } else { stmtDeleteByAltIdx.setNull(argIdx++, java.sql.Types.SMALLINT); } stmtDeleteByAltIdx.setShort(argIdx++, argGenDefId); resultSet = stmtDeleteByAltIdx.executeQuery(); if (resultSet.next()) { boolean deleteFlag = resultSet.getBoolean(1); if (resultSet.next()) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response"); } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 record result set to be returned by delete, not 0 rows"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an unique index with a name. *///from ww w .j a v a2 s . c o m public void testUniqueIndexWithName() throws Exception { Database model = readModel("<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='TableWithIndex'>\n" + " <column name='id'\n" + " type='DOUBLE'\n" + " primaryKey='true'\n" + " required='true'/>\n" + " <column name='value'\n" + " type='SMALLINT'\n" + " default='1'/>\n" + " <unique name='The Index'>\n" + " <unique-column name='value'/>\n" + " </unique>\n" + " </table>\n" + "</database>"); assertEquals("test", model.getName()); assertEquals(1, model.getTableCount()); Table table = model.getTable(0); assertEquals("TableWithIndex", null, 2, 1, 0, 0, 1, table); assertEquals("id", Types.DOUBLE, 0, 0, null, null, null, true, true, false, table.getColumn(0)); assertEquals("value", Types.SMALLINT, 0, 0, "1", null, null, false, false, false, table.getColumn(1)); Index index = table.getIndex(0); assertEquals("The Index", true, 1, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" + " <table name=\"TableWithIndex\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\" autoIncrement=\"false\" />\n" + " <column name=\"value\" primaryKey=\"false\" required=\"false\" type=\"SMALLINT\" default=\"1\" autoIncrement=\"false\" />\n" + " <unique name=\"The Index\">\n" + " <unique-column name=\"value\" />\n" + " </unique>\n" + " </table>\n" + "</database>\n", model); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccOracle.CFAccOracleAccountEntryTable.java
public void updateAccountEntry(CFAccAuthorization Authorization, CFAccAccountEntryBuff Buff) { final String S_ProcName = "updateAccountEntry"; ResultSet resultSet = null;//from w w w.j a v a 2 s . c o m Connection cnx = schema.getCnx(); CallableStatement stmtUpdateByPKey = null; List<CFAccAccountEntryBuff> buffList = new LinkedList<CFAccAccountEntryBuff>(); try { long TenantId = Buff.getRequiredTenantId(); long AccountId = Buff.getRequiredAccountId(); UUID EntryId = Buff.getRequiredEntryId(); UUID SplitEntryId = Buff.getOptionalSplitEntryId(); Calendar EntryStamp = Buff.getRequiredEntryStamp(); String Description = Buff.getRequiredDescription(); Long TransferTenantId = Buff.getOptionalTransferTenantId(); Long TransferAccountId = Buff.getOptionalTransferAccountId(); Short DebitCurrencyId = Buff.getOptionalDebitCurrencyId(); BigDecimal Debit = Buff.getOptionalDebit(); Short CreditCurrencyId = Buff.getOptionalCreditCurrencyId(); BigDecimal Credit = Buff.getOptionalCredit(); short ConvertedCurrencyId = Buff.getRequiredConvertedCurrencyId(); BigDecimal ConvertedAmount = Buff.getRequiredConvertedAmount(); short BalanceCurrencyId = Buff.getRequiredBalanceCurrencyId(); BigDecimal Balance = Buff.getRequiredBalance(); int Revision = Buff.getRequiredRevision(); stmtUpdateByPKey = cnx.prepareCall("begin " + schema.getLowerSchemaDbName() + ".upd_ac_entry( ?, ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "to_timestamp( ?, 'YYYY-MM-DD HH24:MI:SS' )" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "? ); end;"); int argIdx = 1; stmtUpdateByPKey.registerOutParameter(argIdx++, OracleTypes.CURSOR); stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtUpdateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtUpdateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtUpdateByPKey.setString(argIdx++, "ACNY"); stmtUpdateByPKey.setLong(argIdx++, TenantId); stmtUpdateByPKey.setLong(argIdx++, AccountId); stmtUpdateByPKey.setString(argIdx++, EntryId.toString()); if (SplitEntryId != null) { stmtUpdateByPKey.setString(argIdx++, SplitEntryId.toString()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.VARCHAR); } stmtUpdateByPKey.setString(argIdx++, CFAccOracleSchema.getTimestampString(EntryStamp)); stmtUpdateByPKey.setString(argIdx++, Description); if (TransferTenantId != null) { stmtUpdateByPKey.setLong(argIdx++, TransferTenantId.longValue()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.BIGINT); } if (TransferAccountId != null) { stmtUpdateByPKey.setLong(argIdx++, TransferAccountId.longValue()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.BIGINT); } if (DebitCurrencyId != null) { stmtUpdateByPKey.setShort(argIdx++, DebitCurrencyId.shortValue()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.SMALLINT); } if (Debit != null) { stmtUpdateByPKey.setBigDecimal(argIdx++, Debit); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.NUMERIC); } if (CreditCurrencyId != null) { stmtUpdateByPKey.setShort(argIdx++, CreditCurrencyId.shortValue()); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.SMALLINT); } if (Credit != null) { stmtUpdateByPKey.setBigDecimal(argIdx++, Credit); } else { stmtUpdateByPKey.setNull(argIdx++, java.sql.Types.NUMERIC); } stmtUpdateByPKey.setShort(argIdx++, ConvertedCurrencyId); stmtUpdateByPKey.setBigDecimal(argIdx++, ConvertedAmount); stmtUpdateByPKey.setShort(argIdx++, BalanceCurrencyId); stmtUpdateByPKey.setBigDecimal(argIdx++, Balance); stmtUpdateByPKey.setInt(argIdx++, Revision); stmtUpdateByPKey.execute(); resultSet = (ResultSet) stmtUpdateByPKey.getObject(1); if (resultSet != null) { try { if (resultSet.next()) { CFAccAccountEntryBuff updatedBuff = unpackAccountEntryResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setOptionalSplitEntryId(updatedBuff.getOptionalSplitEntryId()); Buff.setRequiredEntryStamp(updatedBuff.getRequiredEntryStamp()); Buff.setRequiredDescription(updatedBuff.getRequiredDescription()); Buff.setOptionalTransferTenantId(updatedBuff.getOptionalTransferTenantId()); Buff.setOptionalTransferAccountId(updatedBuff.getOptionalTransferAccountId()); Buff.setOptionalDebitCurrencyId(updatedBuff.getOptionalDebitCurrencyId()); Buff.setOptionalDebit(updatedBuff.getOptionalDebit()); Buff.setOptionalCreditCurrencyId(updatedBuff.getOptionalCreditCurrencyId()); Buff.setOptionalCredit(updatedBuff.getOptionalCredit()); Buff.setRequiredConvertedCurrencyId(updatedBuff.getRequiredConvertedCurrencyId()); Buff.setRequiredConvertedAmount(updatedBuff.getRequiredConvertedAmount()); Buff.setRequiredBalanceCurrencyId(updatedBuff.getRequiredBalanceCurrencyId()); Buff.setRequiredBalance(updatedBuff.getRequiredBalance()); Buff.setRequiredRevision(updatedBuff.getRequiredRevision()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "upd_ac_entry() did not return a valid result cursor"); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "upd_ac_entry() did not return a result cursor"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } if (stmtUpdateByPKey != null) { try { stmtUpdateByPKey.close(); } catch (SQLException e) { } stmtUpdateByPKey = null; } } }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with indices, both uniques and non-uniques. *//*from ww w . ja v a 2 s. co m*/ public void testMixedIndexes() throws Exception { Database model = readModel("<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='TableWithIndexes'>\n" + " <column name='id'\n" + " type='SMALLINT'\n" + " primaryKey='false'\n" + " required='true'\n" + " autoIncrement='true'/>\n" + " <column name='when'\n" + " type='DATE'/>\n" + " <unique name='important column'>\n" + " <unique-column name='id'/>\n" + " </unique>\n" + " <index>\n" + " <index-column name='when'/>\n" + " </index>\n" + " </table>\n" + "</database>"); assertEquals("test", model.getName()); assertEquals(1, model.getTableCount()); Table table = model.getTable(0); assertEquals("TableWithIndexes", null, 2, 0, 1, 0, 2, table); assertEquals("id", Types.SMALLINT, 0, 0, null, null, null, false, true, true, table.getColumn(0)); assertEquals("when", Types.DATE, 0, 0, null, null, null, false, false, false, table.getColumn(1)); assertEquals(table.getColumn(0), table.getAutoIncrementColumns()[0]); Index index = table.getIndex(0); assertEquals("important column", true, 1, index); assertEquals(table.getColumn(0), null, index.getColumn(0)); index = table.getIndex(1); assertEquals(null, false, 1, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" + " <table name=\"TableWithIndexes\">\n" + " <column name=\"id\" primaryKey=\"false\" required=\"true\" type=\"SMALLINT\" autoIncrement=\"true\" />\n" + " <column name=\"when\" primaryKey=\"false\" required=\"false\" type=\"DATE\" autoIncrement=\"false\" />\n" + " <unique name=\"important column\">\n" + " <unique-column name=\"id\" />\n" + " </unique>\n" + " <index>\n" + " <index-column name=\"when\" />\n" + " </index>\n" + " </table>\n" + "</database>\n", model); }