Example usage for java.sql Types NUMERIC

List of usage examples for java.sql Types NUMERIC

Introduction

In this page you can find the example usage for java.sql Types NUMERIC.

Prototype

int NUMERIC

To view the source code for java.sql Types NUMERIC.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NUMERIC.

Usage

From source file:org.jumpmind.db.platform.AbstractDdlBuilder.java

/**
 * Generates the string representation of the given value.
 *
 * @param column/* w  w w  .j  a  v a2s.c  om*/
 *            The column
 * @param value
 *            The value
 * @return The string representation
 */
protected String getValueAsString(Column column, Object value) {
    if (value == null) {
        return "NULL";
    }

    StringBuffer result = new StringBuffer();

    // TODO: Handle binary types (BINARY, VARBINARY, LONGVARBINARY, BLOB)
    switch (column.getMappedTypeCode()) {
    case Types.DATE:
        result.append(databaseInfo.getValueQuoteToken());
        if (!(value instanceof String) && (getValueDateFormat() != null)) {
            // TODO: Can the format method handle java.sql.Date properly
            // ?
            result.append(getValueDateFormat().format(value));
        } else {
            result.append(value.toString());
        }
        result.append(databaseInfo.getValueQuoteToken());
        break;
    case Types.TIME:
        result.append(databaseInfo.getValueQuoteToken());
        if (!(value instanceof String) && (getValueTimeFormat() != null)) {
            // TODO: Can the format method handle java.sql.Date properly
            // ?
            result.append(getValueTimeFormat().format(value));
        } else {
            result.append(value.toString());
        }
        result.append(databaseInfo.getValueQuoteToken());
        break;
    case Types.TIMESTAMP:
        result.append(databaseInfo.getValueQuoteToken());
        // TODO: SimpleDateFormat does not support nano seconds so we
        // would
        // need a custom date formatter for timestamps
        result.append(value.toString());
        result.append(databaseInfo.getValueQuoteToken());
        break;
    case Types.REAL:
    case Types.NUMERIC:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.DECIMAL:
        result.append(databaseInfo.getValueQuoteToken());
        if (!(value instanceof String) && (getValueNumberFormat() != null)) {
            result.append(getValueNumberFormat().format(value));
        } else {
            result.append(value.toString());
        }
        result.append(databaseInfo.getValueQuoteToken());
        break;
    default:
        result.append(databaseInfo.getValueQuoteToken());
        result.append(escapeStringValue(value.toString()));
        result.append(databaseInfo.getValueQuoteToken());
        break;
    }
    return result.toString();
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Returns the type name for the specific constant as defined
 * by {@link java.sql.Types}.//from w w  w . java2 s  .  c  om
 *
 * @param type the type
 * @return the name for the type
 */
public String getTypeName(int type) {
    switch (type) {
    case Types.ARRAY:
        return arrayTypeName;
    case Types.BIGINT:
        return bigintTypeName;
    case Types.BINARY:
        return binaryTypeName;
    case Types.BIT:
        return bitTypeName;
    case Types.BLOB:
        return blobTypeName;
    case Types.BOOLEAN:
        return booleanTypeName;
    case Types.CHAR:
        return charTypeName;
    case Types.CLOB:
        return clobTypeName;
    case Types.DATE:
        return dateTypeName;
    case Types.DECIMAL:
        return decimalTypeName;
    case Types.DISTINCT:
        return distinctTypeName;
    case Types.DOUBLE:
        return doubleTypeName;
    case Types.FLOAT:
        return floatTypeName;
    case Types.INTEGER:
        return integerTypeName;
    case Types.JAVA_OBJECT:
        return javaObjectTypeName;
    case Types.LONGVARBINARY:
        return longVarbinaryTypeName;
    case Types.LONGVARCHAR:
        return longVarcharTypeName;
    case Types.NULL:
        return nullTypeName;
    case Types.NUMERIC:
        return numericTypeName;
    case Types.OTHER:
        return otherTypeName;
    case Types.REAL:
        return realTypeName;
    case Types.REF:
        return refTypeName;
    case Types.SMALLINT:
        return smallintTypeName;
    case Types.STRUCT:
        return structTypeName;
    case Types.TIME:
        return timeTypeName;
    case Types.TIMESTAMP:
        return timestampTypeName;
    case Types.TINYINT:
        return tinyintTypeName;
    case Types.VARBINARY:
        return varbinaryTypeName;
    case Types.VARCHAR:
        return varcharTypeName;
    default:
        return otherTypeName;
    }
}

From source file:org.jumpmind.symmetric.service.impl.DataService.java

public void insertDataGap(ISqlTransaction transaction, DataGap gap) {
    transaction.prepareAndExecute(getSql("insertDataGapSql"),
            new Object[] { DataGap.Status.GP.name(), AppUtils.getHostName(), gap.getStartId(), gap.getEndId() },
            new int[] { Types.VARCHAR, Types.VARCHAR, Types.NUMERIC, Types.NUMERIC });
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccDb2LUW.CFAccDb2LUWAccountEntryTable.java

public void updateAccountEntry(CFAccAuthorization Authorization, CFAccAccountEntryBuff Buff) {
    final String S_ProcName = "updateAccountEntry";
    if ("ACNY".equals(Buff.getClassCode())
            && (!schema.isTenantUser(Authorization, Buff.getRequiredTenantId(), "UpdateAccountEntry"))) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Permission denied -- User not part of TSecGroup UpdateAccountEntry");
    }//from  w  w w  .j a  v a 2 s  .c  om
    ResultSet resultSet = null;
    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();
        final String sql = "CALL sp_update_ac_entry( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?"
                + ", " + "?" + ", " + "TIMESTAMP_FORMAT( ?, 'YYYY-MM-DD-HH24.MI.SS' )" + ", " + "?" + ", " + "?"
                + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"
                + ", " + "?" + ", " + "?" + ", " + "?" + " )";
        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++, CFAccDb2LUWSchema.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);
        resultSet = stmtUpdateByPKey.executeQuery();
        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().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlAccountEntryTable.java

public void updateAccountEntry(CFAccAuthorization Authorization, CFAccAccountEntryBuff Buff) {
    final String S_ProcName = "updateAccountEntry";
    ResultSet resultSet = null;//  w  w w .  jav  a 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 = "select * from " + schema.getLowerSchemaDbName() + ".sp_update_ac_entry( ?, ?, ?, ?, ?, ?"
                + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", "
                + "cast( to_timestamp( ?, 'YYYY-MM-DD HH24:MI:SS' ) as 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++, CFAccPgSqlSchema.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);
        resultSet = stmtUpdateByPKey.executeQuery();
        if (resultSet.next()) {
            CFAccAccountEntryBuff updatedBuff = unpackAccountEntryResultSetToBuff(resultSet);
            if (resultSet.next()) {
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-record response");
            }
            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:ua.utility.kfsdbupgrade.App.java

/**
 * @param type/*from   w  ww. j  a  va  2  s.  c  o  m*/
 *            <code>int</code> of a {@link Types} value
 * @return <code>true</code> if <code>type</code> is one of the following:
 *         <ul>
 *         <li>{@link Types#BIGINT}</li>
 *         <li>{@link Types#BINARY}</li>
 *         <li>{@link Types#DECIMAL}</li>
 *         <li>{@link Types#DOUBLE}</li>
 *         <li>{@link Types#FLOAT}</li>
 *         <li>{@link Types#INTEGER}</li>
 *         <li>{@link Types#NUMERIC}</li>
 *         <li>{@link Types#REAL}</li>
 *         <li>{@link Types#SMALLINT}</li>
 *         <li>{@link Types#TINYINT}</li>
 *         </ul>
 *         <p>
 *         , <code>false</code> otherwise.
 */
private boolean isNumericJavaType(int type) {
    return ((type == java.sql.Types.BIGINT) || (type == java.sql.Types.BINARY)
            || (type == java.sql.Types.DECIMAL) || (type == java.sql.Types.DOUBLE)
            || (type == java.sql.Types.FLOAT) || (type == java.sql.Types.INTEGER)
            || (type == java.sql.Types.NUMERIC) || (type == java.sql.Types.REAL)
            || (type == java.sql.Types.SMALLINT) || (type == java.sql.Types.TINYINT));
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlAccountEntryTable.java

public void updateAccountEntry(CFAccAuthorization Authorization, CFAccAccountEntryBuff Buff) {
    final String S_ProcName = "updateAccountEntry";
    ResultSet resultSet = null;/*from   w  w w.jav a 2s.c  o  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 = "exec sp_update_ac_entry ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", "
                + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?"
                + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?";
        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++, CFAccMSSqlSchema.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();
        boolean moreResults = true;
        resultSet = null;
        while (resultSet == null) {
            try {
                moreResults = stmtUpdateByPKey.getMoreResults();
            } catch (SQLException e) {
                throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
            }
            if (moreResults) {
                try {
                    resultSet = stmtUpdateByPKey.getResultSet();
                } catch (SQLException e) {
                }
            } else if (-1 == stmtUpdateByPKey.getUpdateCount()) {
                break;
            }
        }
        if (resultSet == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "resultSet");
        }
        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().newDbException(getClass(), S_ProcName, e);
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            }
            resultSet = null;
        }
    }
}

From source file:org.nuclos.server.masterdata.ejb3.MetaDataFacadeBean.java

private String getBestJavaType(int colType) {
    String sType = "java.lang.String";
    switch (colType) {
    case Types.VARCHAR:
        return sType;
    case Types.CHAR:
        return sType;
    case Types.NCHAR:
        return sType;
    case Types.NVARCHAR:
        return sType;
    case Types.LONGNVARCHAR:
        return sType;
    case Types.LONGVARCHAR:
        return sType;
    case Types.LONGVARBINARY:
        return sType;
    case Types.NUMERIC:
        return "java.lang.Integer";
    case Types.DECIMAL:
        return "java.lang.Double";
    case Types.BOOLEAN:
        return "java.lang.Integer";
    case Types.DATE:
        return "java.util.Date";
    case Types.TIME:
        return "java.util.Date";
    case Types.TIMESTAMP:
        return "java.util.Date";

    default:/*from  w  w w  .  j ava 2 s .  c  o m*/

        return sType;
    }
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}//  ww w  .  j  a v a2s .  co  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void removeTreeNode(int category, long nodeId, long mandatorId)
        throws FxNoAccessException, FxNotFoundException {
    checkMandatorAccess(mandatorId, FxContext.getUserTicket());
    Connection con = null;
    PreparedStatement ps = null, psUpdate = null;
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        ps = con.prepareStatement("SELECT PARENTID, PARENTMANDATOR FROM " + TBL_PHRASE_TREE
                + " WHERE ID=? AND MANDATOR=? AND CAT=?");
        ps.setLong(1, nodeId);
        ps.setLong(2, mandatorId);
        ps.setInt(3, category);
        ResultSet rs = ps.executeQuery();
        if (rs == null || !rs.next())
            throw new FxNotFoundException("ex.phrases.node.notFound.id", nodeId, mandatorId);
        long parentId = rs.getLong(1);
        if (rs.wasNull())
            parentId = -1L;
        long parentMandatorId = rs.getLong(2);
        if (rs.wasNull())
            parentMandatorId = -1L;
        rs.close();
        ps.close();
        psUpdate = con.prepareStatement("UPDATE " + TBL_PHRASE_TREE
                + " SET PARENTID=?, PARENTMANDATOR=?, POS=? WHERE ID=? AND MANDATOR=? AND CAT=?");
        psUpdate.setInt(6, category);
        long currPos = getNextNodePos(con, category, parentId, parentMandatorId, mandatorId);
        ps = con.prepareStatement("SELECT ID, MANDATOR FROM " + TBL_PHRASE_TREE
                + " WHERE PARENTID=? AND PARENTMANDATOR=? AND CAT=? ORDER BY POS");
        ps.setLong(1, nodeId);
        ps.setLong(2, mandatorId);
        ps.setInt(3, category);
        rs = ps.executeQuery();
        while (rs != null && rs.next()) {
            if (parentId != -1L) {
                psUpdate.setLong(1, parentId);
                psUpdate.setLong(2, parentMandatorId);
            } else {
                psUpdate.setNull(1, Types.NUMERIC);
                psUpdate.setNull(2, Types.NUMERIC);
            }
            psUpdate.setLong(3, currPos++);
            psUpdate.setLong(4, rs.getLong(1));
            psUpdate.setLong(5, rs.getLong(2));
            psUpdate.executeUpdate();
        }
        if (rs != null)
            rs.close();
        ps.close();

        ps = con.prepareStatement(
                "DELETE FROM " + TBL_PHRASE_MAP + " WHERE NODEID=? AND NODEMANDATOR=? AND CAT=?");
        ps.setLong(1, nodeId);
        ps.setLong(2, mandatorId);
        ps.setInt(3, category);
        ps.executeUpdate();
        ps.close();
        ps = con.prepareStatement("DELETE FROM " + TBL_PHRASE_TREE + " WHERE ID=? AND MANDATOR=? AND CAT=?");
        ps.setLong(1, nodeId);
        ps.setLong(2, mandatorId);
        ps.setInt(3, category);
        ps.executeUpdate();
        rebuildPhraseChildMapping(con, mandatorId, category, -1, -1);
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, psUpdate);
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Return a SQL string to act as a placeholder for the given column.
 *//*  w  w w. ja va  2  s.  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";
    }
}