Example usage for java.sql Types CLOB

List of usage examples for java.sql Types CLOB

Introduction

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

Prototype

int CLOB

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

Click Source Link

Document

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

Usage

From source file:org.wso2.carbon.dataservices.core.description.query.SQLQuery.java

private DataEntry getDataEntryFromRS(ResultSet rs) throws SQLException {
    DataEntry dataEntry = new DataEntry();
    ResultSetMetaData metaData = rs.getMetaData();
    int columnCount = metaData.getColumnCount();
    int columnType;
    String value;/*from  www. j a  v  a  2s  .com*/
    ParamValue paramValue;
    Time sqlTime;
    Date sqlDate;
    Timestamp sqlTimestamp;
    Blob sqlBlob;
    BigDecimal bigDecimal;
    InputStream binInStream;
    boolean useColumnNumbers = this.isUsingColumnNumbers();
    for (int i = 1; i <= columnCount; i++) {
        /* retrieve values according to the column type */
        columnType = metaData.getColumnType(i);
        switch (columnType) {
        /* handle string types */
        case Types.VARCHAR:
            /* fall through */
        case Types.LONGVARCHAR:
            /* fall through */
        case Types.CHAR:
            /* fall through */
        case Types.CLOB:
            /* fall through */
        case Types.NCHAR:
            /* fall through */
        case Types.NCLOB:
            /* fall through */
        case Types.NVARCHAR:
            /* fall through */
        case Types.LONGNVARCHAR:
            value = rs.getString(i);
            paramValue = new ParamValue(value);
            break;
        /* handle numbers */
        case Types.INTEGER:
            /* fall through */
        case Types.TINYINT:
            /* fall through */
        case Types.SMALLINT:
            value = ConverterUtil.convertToString(rs.getInt(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.DOUBLE:
            value = ConverterUtil.convertToString(rs.getDouble(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.FLOAT:
            value = ConverterUtil.convertToString(rs.getFloat(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.BOOLEAN:
            /* fall through */
        case Types.BIT:
            value = ConverterUtil.convertToString(rs.getBoolean(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;
        case Types.DECIMAL:
            bigDecimal = rs.getBigDecimal(i);
            if (bigDecimal != null) {
                value = ConverterUtil.convertToString(bigDecimal);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handle data/time values */
        case Types.TIME:
            /* handle time data type */
            sqlTime = rs.getTime(i);
            if (sqlTime != null) {
                value = this.convertToTimeString(sqlTime);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.DATE:
            /* handle date data type */
            sqlDate = rs.getDate(i);
            if (sqlDate != null) {
                value = ConverterUtil.convertToString(sqlDate);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.TIMESTAMP:
            sqlTimestamp = rs.getTimestamp(i, calendar);
            if (sqlTimestamp != null) {
                value = this.convertToTimestampString(sqlTimestamp);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handle binary types */
        case Types.BLOB:
            sqlBlob = rs.getBlob(i);
            if (sqlBlob != null) {
                value = this.getBase64StringFromInputStream(sqlBlob.getBinaryStream());
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.BINARY:
            /* fall through */
        case Types.LONGVARBINARY:
            /* fall through */
        case Types.VARBINARY:
            binInStream = rs.getBinaryStream(i);
            if (binInStream != null) {
                value = this.getBase64StringFromInputStream(binInStream);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        /* handling User Defined Types */
        case Types.STRUCT:
            Struct udt = (Struct) rs.getObject(i);
            paramValue = new ParamValue(udt);
            break;
        case Types.ARRAY:
            paramValue = new ParamValue(ParamValue.PARAM_VALUE_ARRAY);
            Array dataArray = (Array) rs.getObject(i);
            if (dataArray == null) {
                break;
            }
            paramValue = this.processSQLArray(dataArray, paramValue);
            break;
        case Types.NUMERIC:
            bigDecimal = rs.getBigDecimal(i);
            if (bigDecimal != null) {
                value = ConverterUtil.convertToString(bigDecimal);
            } else {
                value = null;
            }
            paramValue = new ParamValue(value);
            break;
        case Types.BIGINT:
            value = ConverterUtil.convertToString(rs.getLong(i));
            paramValue = new ParamValue(rs.wasNull() ? null : value);
            break;

        /* handle all other types as strings */
        default:
            value = rs.getString(i);
            paramValue = new ParamValue(value);
            break;
        }
        dataEntry.addValue(useColumnNumbers ? Integer.toString(i) : metaData.getColumnLabel(i), paramValue);
    }
    return dataEntry;
}

From source file:org.dspace.storage.rdbms.DatabaseManager.java

private static void loadParameters(PreparedStatement statement, Collection<ColumnInfo> columns, TableRow row)
        throws SQLException {
    int count = 0;
    for (ColumnInfo info : columns) {
        count++;//  w ww. j a  v  a2s  . c om
        String column = info.getCanonicalizedName();
        int jdbctype = info.getType();

        if (row.isColumnNull(column)) {
            statement.setNull(count, jdbctype);
        } else {
            switch (jdbctype) {
            case Types.BIT:
                statement.setBoolean(count, row.getBooleanColumn(column));
                break;

            case Types.INTEGER:
                if (isOracle) {
                    statement.setLong(count, row.getLongColumn(column));
                } else {
                    statement.setInt(count, row.getIntColumn(column));
                }
                break;

            case Types.NUMERIC:
            case Types.DECIMAL:
                statement.setLong(count, row.getLongColumn(column));
                // FIXME should be BigDecimal if TableRow supported that
                break;

            case Types.BIGINT:
                statement.setLong(count, row.getLongColumn(column));
                break;

            case Types.CLOB:
                if (isOracle) {
                    // Support CLOBs in place of TEXT columns in Oracle
                    statement.setString(count, row.getStringColumn(column));
                } else {
                    throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
                }
                break;

            case Types.VARCHAR:
                statement.setString(count, row.getStringColumn(column));
                break;

            case Types.DATE:
                statement.setDate(count, new java.sql.Date(row.getDateColumn(column).getTime()));
                break;

            case Types.TIME:
                statement.setTime(count, new Time(row.getDateColumn(column).getTime()));
                break;

            case Types.TIMESTAMP:
                statement.setTimestamp(count, new Timestamp(row.getDateColumn(column).getTime()));
                break;

            default:
                throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
            }
        }
    }
}

From source file:org.apache.openjpa.jdbc.meta.ReverseMappingTool.java

/**
 * Map a column to a simple field./*from  www .  ja v  a2 s  .c  o m*/
 */
private void mapColumn(ClassMapping cls, Column col, ForeignKey join, boolean outer) {
    String name = getFieldName(col.getName(), cls);
    Class type = getFieldType(col, false);
    FieldMapping field = newFieldMapping(name, type, col, null, cls);
    field.setSerialized(type == Object.class);
    field.setJoinForeignKey(join);
    field.setJoinOuter(outer);
    addJoinConstraints(field);
    field.setColumns(new Column[] { col });
    addConstraints(field);
    if (col.isPrimaryKey() && cls.getIdentityType() != ClassMapping.ID_DATASTORE)
        field.setPrimaryKey(true);

    FieldStrategy strat;
    if (type.isPrimitive())
        strat = new PrimitiveFieldStrategy();
    else if (col.getType() == Types.CLOB && _conf.getDBDictionaryInstance().maxEmbeddedClobSize != -1)
        strat = new MaxEmbeddedClobFieldStrategy();
    else if (col.isLob() && _conf.getDBDictionaryInstance().maxEmbeddedBlobSize != -1)
        strat = new MaxEmbeddedBlobFieldStrategy();
    else if (type == String.class)
        strat = new StringFieldStrategy();
    else
        strat = new HandlerFieldStrategy();
    field.setStrategy(strat, null);
    if (_custom != null)
        _custom.customize(field);
}

From source file:org.wso2.carbon.dataservices.core.odata.RDBMSDataHandler.java

private ODataDataType getODataDataType(int columnType) {
    ODataDataType dataType;/*  w  w  w.j  a va2s  .c  om*/
    switch (columnType) {
    case Types.INTEGER:
        dataType = ODataDataType.INT32;
        break;
    case Types.TINYINT:
        /* fall through */
    case Types.SMALLINT:
        dataType = ODataDataType.INT16;
        break;
    case Types.DOUBLE:
        dataType = ODataDataType.DOUBLE;
        break;
    case Types.VARCHAR:
        /* fall through */
    case Types.CHAR:
        /* fall through */
    case Types.LONGVARCHAR:
        /* fall through */
    case Types.CLOB:
        /* fall through */
    case Types.LONGNVARCHAR:
        /* fall through */
    case Types.NCHAR:
        /* fall through */
    case Types.NVARCHAR:
        /* fall through */
    case Types.NCLOB:
        /* fall through */
    case Types.SQLXML:
        dataType = ODataDataType.STRING;
        break;
    case Types.BOOLEAN:
        /* fall through */
    case Types.BIT:
        dataType = ODataDataType.BOOLEAN;
        break;
    case Types.BLOB:
        /* fall through */
    case Types.BINARY:
        /* fall through */
    case Types.LONGVARBINARY:
        /* fall through */
    case Types.VARBINARY:
        dataType = ODataDataType.BINARY;
        break;
    case Types.DATE:
        dataType = ODataDataType.DATE;
        break;
    case Types.DECIMAL:
        /* fall through */
    case Types.NUMERIC:
        dataType = ODataDataType.DECIMAL;
        break;
    case Types.FLOAT:
        /* fall through */
    case Types.REAL:
        dataType = ODataDataType.SINGLE;
        break;
    case Types.TIME:
        dataType = ODataDataType.TIMEOFDAY;
        break;
    case Types.BIGINT:
        dataType = ODataDataType.INT64;
        break;
    case Types.TIMESTAMP:
        dataType = ODataDataType.DATE_TIMEOFFSET;
        break;
    default:
        dataType = ODataDataType.STRING;
        break;
    }
    return dataType;
}

From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatUtilities.java

public static String sqlTypeString(int sqlType) {
    switch (sqlType) {
    case Types.BIT:
        return "BIT";
    case Types.TINYINT:
        return "TINYINT";
    case Types.SMALLINT:
        return "SMALLINT";
    case Types.INTEGER:
        return "INTEGER";
    case Types.BIGINT:
        return "BIGINT";
    case Types.FLOAT:
        return "FLOAT";
    case Types.REAL:
        return "REAL";
    case Types.DOUBLE:
        return "DOUBLE";
    case Types.NUMERIC:
        return "NUMERIC";
    case Types.DECIMAL:
        return "DECIMAL";
    case Types.CHAR:
        return "CHAR";
    case Types.VARCHAR:
        return "VARCHAR";
    case Types.LONGVARCHAR:
        return "LONGVARCHAR";
    case Types.DATE:
        return "DATE";
    case Types.TIME:
        return "TIME";
    case Types.TIMESTAMP:
        return "TIMESTAMP";
    case Types.BINARY:
        return "BINARY";
    case Types.VARBINARY:
        return "VARBINARY";
    case Types.LONGVARBINARY:
        return "LONGVARBINARY";
    case Types.NULL:
        return "NULL";
    case Types.OTHER:
        return "OTHER";
    case Types.JAVA_OBJECT:
        return "JAVA_OBJECT";
    case Types.DISTINCT:
        return "DISTINCT";
    case Types.STRUCT:
        return "STRUCT";
    case Types.ARRAY:
        return "ARRAY";
    case Types.BLOB:
        return "BLOB";
    case Types.CLOB:
        return "CLOB";
    case Types.REF:
        return "REF";
    case Types.DATALINK:
        return "DATALINK";
    case Types.BOOLEAN:
        return "BOOLEAN";
    case Types.ROWID:
        return "ROWID";
    case Types.NCHAR:
        return "NCHAR";
    case Types.NVARCHAR:
        return "NVARCHAR";
    case Types.LONGNVARCHAR:
        return "LONGNVARCHAR";
    case Types.NCLOB:
        return "NCLOB";
    case Types.SQLXML:
        return "SQLXML";
    default://from w w  w . j av  a  2 s  .  c  o  m
        return "<UNKNOWN>";
    }
}

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

/**
 * Set a column value into a prepared statement.
 *
 * @param stmnt the prepared statement to parameterize
 * @param idx the index of the parameter in the prepared statement
 * @param val the value of the column// w  w w .j a  va 2s . c om
 * @param col the column being set
 * @param type the field mapping type code for the value
 * @param store the store manager for the current context
 */
public void setTyped(PreparedStatement stmnt, int idx, Object val, Column col, int type, JDBCStore store)
        throws SQLException {
    if (val == null) {
        setNull(stmnt, idx, (col == null) ? Types.OTHER : col.getType(), col);
        return;
    }

    Sized s;
    Calendard c;
    switch (type) {
    case JavaTypes.BOOLEAN:
    case JavaTypes.BOOLEAN_OBJ:
        setBoolean(stmnt, idx, ((Boolean) val).booleanValue(), col);
        break;
    case JavaTypes.BYTE:
    case JavaTypes.BYTE_OBJ:
        setByte(stmnt, idx, ((Number) val).byteValue(), col);
        break;
    case JavaTypes.CHAR:
    case JavaTypes.CHAR_OBJ:
        setChar(stmnt, idx, ((Character) val).charValue(), col);
        break;
    case JavaTypes.DOUBLE:
    case JavaTypes.DOUBLE_OBJ:
        setDouble(stmnt, idx, ((Number) val).doubleValue(), col);
        break;
    case JavaTypes.FLOAT:
    case JavaTypes.FLOAT_OBJ:
        setFloat(stmnt, idx, ((Number) val).floatValue(), col);
        break;
    case JavaTypes.INT:
    case JavaTypes.INT_OBJ:
        setInt(stmnt, idx, ((Number) val).intValue(), col);
        break;
    case JavaTypes.LONG:
    case JavaTypes.LONG_OBJ:
        setLong(stmnt, idx, ((Number) val).longValue(), col);
        break;
    case JavaTypes.SHORT:
    case JavaTypes.SHORT_OBJ:
        setShort(stmnt, idx, ((Number) val).shortValue(), col);
        break;
    case JavaTypes.STRING:
        if (col != null && (col.getType() == Types.CLOB || col.getType() == Types.LONGVARCHAR))
            setClobString(stmnt, idx, (String) val, col);
        else {
            if (val instanceof String)
                setString(stmnt, idx, (String) val, col);
            else
                setString(stmnt, idx, val.toString(), col);
        }
        break;
    case JavaTypes.OBJECT:
        setBlobObject(stmnt, idx, val, col, store);
        break;
    case JavaTypes.DATE:
        setDate(stmnt, idx, (Date) val, col);
        break;
    case JavaTypes.CALENDAR:
        setCalendar(stmnt, idx, (Calendar) val, col);
        break;
    case JavaTypes.BIGDECIMAL:
        setBigDecimal(stmnt, idx, (BigDecimal) val, col);
        break;
    case JavaTypes.BIGINTEGER:
        setBigInteger(stmnt, idx, (BigInteger) val, col);
        break;
    case JavaTypes.NUMBER:
        setNumber(stmnt, idx, (Number) val, col);
        break;
    case JavaTypes.LOCALE:
        setLocale(stmnt, idx, (Locale) val, col);
        break;
    case JavaSQLTypes.SQL_ARRAY:
        setArray(stmnt, idx, (Array) val, col);
        break;
    case JavaSQLTypes.ASCII_STREAM:
        s = (Sized) val;
        setAsciiStream(stmnt, idx, (InputStream) s.value, s.size, col);
        break;
    case JavaSQLTypes.BINARY_STREAM:
        s = (Sized) val;
        setBinaryStream(stmnt, idx, (InputStream) s.value, s.size, col);
        break;
    case JavaSQLTypes.BLOB:
        setBlob(stmnt, idx, (Blob) val, col);
        break;
    case JavaSQLTypes.BYTES:
        setBytes(stmnt, idx, (byte[]) val, col);
        break;
    case JavaSQLTypes.CHAR_STREAM:
        s = (Sized) val;
        setCharacterStream(stmnt, idx, (Reader) s.value, s.size, col);
        break;
    case JavaSQLTypes.CLOB:
        setClob(stmnt, idx, (Clob) val, col);
        break;
    case JavaSQLTypes.SQL_DATE:
        if (val instanceof Calendard) {
            c = (Calendard) val;
            setDate(stmnt, idx, (java.sql.Date) c.value, c.calendar, col);
        } else
            setDate(stmnt, idx, (java.sql.Date) val, null, col);
        break;
    case JavaSQLTypes.REF:
        setRef(stmnt, idx, (Ref) val, col);
        break;
    case JavaSQLTypes.TIME:
        if (val instanceof Calendard) {
            c = (Calendard) val;
            setTime(stmnt, idx, (Time) c.value, c.calendar, col);
        } else
            setTime(stmnt, idx, (Time) val, null, col);
        break;
    case JavaSQLTypes.TIMESTAMP:
        if (val instanceof Calendard) {
            c = (Calendard) val;
            setTimestamp(stmnt, idx, (Timestamp) c.value, c.calendar, col);
        } else
            setTimestamp(stmnt, idx, (Timestamp) val, null, col);
        break;
    default:
        if (col != null && (col.getType() == Types.BLOB || col.getType() == Types.VARBINARY))
            setBlobObject(stmnt, idx, val, col, store);
        else
            setObject(stmnt, idx, val, col.getType(), col);
    }
}

From source file:com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine.java

/**
 * Maps the database type to {@link DbColumnType}. If there's no mapping a {@link DbColumnType#UNMAPPED} is returned.
 *
 * @param type The SQL type from {@link java.sql.Types}.
 * @return The {@link DbColumnType}.//from w ww .ja  va 2s .c o m
 */
protected DbColumnType toPdbType(final int type) {
    switch (type) {
    case Types.ARRAY:
        return DbColumnType.UNMAPPED;
    case Types.BIGINT:
        return DbColumnType.LONG;
    case Types.BINARY:
        return DbColumnType.BLOB;
    case Types.BIT:
        return DbColumnType.BOOLEAN;
    case Types.BLOB:
        return DbColumnType.BLOB;
    case Types.BOOLEAN:
        return DbColumnType.BOOLEAN;
    case Types.CHAR:
        return DbColumnType.STRING;
    case Types.CLOB:
        return DbColumnType.STRING;
    case Types.DATALINK:
        return DbColumnType.UNMAPPED;
    case Types.DATE:
        return DbColumnType.UNMAPPED;
    case Types.DECIMAL:
        return DbColumnType.DOUBLE;
    case Types.DISTINCT:
        return DbColumnType.UNMAPPED;
    case Types.DOUBLE:
        return DbColumnType.DOUBLE;
    case Types.FLOAT:
        return DbColumnType.DOUBLE;
    case Types.INTEGER:
        return DbColumnType.INT;
    case Types.JAVA_OBJECT:
        return DbColumnType.BLOB;
    case Types.LONGNVARCHAR:
        return DbColumnType.STRING;
    case Types.LONGVARBINARY:
        return DbColumnType.BLOB;
    case Types.LONGVARCHAR:
        return DbColumnType.STRING;
    case Types.NCHAR:
        return DbColumnType.STRING;
    case Types.NCLOB:
        return DbColumnType.STRING;
    case Types.NULL:
        return DbColumnType.UNMAPPED;
    case Types.NUMERIC:
        return DbColumnType.DOUBLE;
    case Types.NVARCHAR:
        return DbColumnType.STRING;
    case Types.OTHER:
        return DbColumnType.UNMAPPED;
    case Types.REAL:
        return DbColumnType.DOUBLE;
    case Types.REF:
        return DbColumnType.UNMAPPED;
    case Types.ROWID:
        return DbColumnType.STRING;
    case Types.SMALLINT:
        return DbColumnType.INT;
    case Types.SQLXML:
        return DbColumnType.STRING;
    case Types.STRUCT:
        return DbColumnType.UNMAPPED;
    case Types.TIME:
        return DbColumnType.UNMAPPED;
    case Types.TIMESTAMP:
        return DbColumnType.LONG;
    case Types.TINYINT:
        return DbColumnType.INT;
    case Types.VARBINARY:
        return DbColumnType.BLOB;
    case Types.VARCHAR:
        return DbColumnType.STRING;
    default:
        return DbColumnType.UNMAPPED;
    }
}

From source file:com.flexive.core.storage.genericSQL.GenericHierarchicalStorage.java

/**
 * Create a new main entry//  www .  j a  v a  2  s . co  m
 *
 * @param con     an open and valid connection
 * @param newId   the id to use
 * @param version the version to use
 * @param content content to create
 * @return primary key of the created content
 * @throws FxCreateException on errors
 */
protected FxPK createMainEntry(Connection con, long newId, int version, FxContent content,
        boolean keepCreationLCI) throws FxCreateException {
    PreparedStatement ps = null;
    FxPK pk = new FxPK(newId, version);
    try {
        ps = con.prepareStatement(CONTENT_MAIN_INSERT);
        ps.setLong(1, newId);
        ps.setInt(2, version);
        ps.setLong(3, content.getTypeId());
        ps.setLong(4, content.getAclIds().size() > 1 ? ACL.NULL_ACL_ID : content.getAclIds().get(0));
        ps.setLong(5, content.getStepId());
        ps.setInt(6, 1); //if creating a new version, max_ver will be fixed in a later step
        ps.setInt(7, content.isLiveVersion() ? 1 : 0);
        ps.setBoolean(8, content.isMaxVersion());
        ps.setBoolean(9, content.isLiveVersion());
        ps.setBoolean(10, content.isActive());
        ps.setInt(11, (int) content.getMainLanguage());
        if (content.isRelation()) {
            ps.setLong(12, content.getRelatedSource().getId());
            ps.setInt(13, content.getRelatedSource().getVersion());
            ps.setLong(14, content.getRelatedDestination().getId());
            ps.setInt(15, content.getRelatedDestination().getVersion());
            ps.setLong(16, content.getRelatedSourcePosition());
            ps.setLong(17, content.getRelatedDestinationPosition());
        } else {
            ps.setNull(12, java.sql.Types.NUMERIC);
            ps.setNull(13, java.sql.Types.NUMERIC);
            ps.setNull(14, java.sql.Types.NUMERIC);
            ps.setNull(15, java.sql.Types.NUMERIC);
            ps.setNull(16, java.sql.Types.NUMERIC);
            ps.setNull(17, java.sql.Types.NUMERIC);
        }

        if (!content.isForceLifeCycle()) {
            final long userId = FxContext.getUserTicket().getUserId();
            final long now = System.currentTimeMillis();
            if (keepCreationLCI) {
                // keep created_at of existing content
                ps.setLong(18, content.getValue(FxLargeNumber.class, "/CREATED_BY").getBestTranslation());
                ps.setLong(19,
                        content.getValue(FxDateTime.class, "/CREATED_AT").getBestTranslation().getTime());
            } else {
                ps.setLong(18, userId);
                ps.setLong(19, now);
            }
            ps.setLong(20, userId);
            ps.setLong(21, now);
        } else {
            ps.setLong(18, content.getValue(FxLargeNumber.class, "/CREATED_BY").getBestTranslation());
            ps.setLong(19, content.getValue(FxDateTime.class, "/CREATED_AT").getBestTranslation().getTime());
            ps.setLong(20, content.getValue(FxLargeNumber.class, "/MODIFIED_BY").getBestTranslation());
            ps.setLong(21, content.getValue(FxDateTime.class, "/MODIFIED_AT").getBestTranslation().getTime());
        }
        ps.setLong(22, content.getMandatorId());
        final String groupPositions = getGroupPositions(content);
        if (groupPositions != null) {
            StorageManager.getStorageImpl().setBigString(ps, 23, groupPositions);
        } else {
            ps.setNull(23, Types.CLOB);
        }
        ps.executeUpdate();

        updateACLEntries(con, content, pk, true);

    } catch (SQLException e) {
        throw new FxCreateException(LOG, e, "ex.db.sqlError", e.getMessage());
    } catch (FxUpdateException e) {
        throw new FxCreateException(e);
    } finally {
        Database.closeObjects(GenericHierarchicalStorage.class, ps);
    }
    return pk;
}

From source file:it.greenvulcano.gvesb.datahandling.dbo.DBOCallSP.java

/**
 * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
 *      java.lang.String, java.lang.String)
 */// w  ww .  j  a va 2  s.c o m
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (ROW_NAME.equals(localName)) {
        if (!currCriticalError) {
            executeStatement();
        } else {
            rowDisc++;
            // aggiunta DiscardCause al dhr...
            String msg = currentXSLMessage;

            dhr.addDiscardCause(new DiscardCause(rowCounter, msg));

            resultMessage.append("Data error on row ").append(rowCounter).append(": ").append(msg);
            resultMessage.append("SQL Statement Informations:\n").append(sqlStatementInfo);
            resultMessage.append("Record parameters:\n").append(dumpCurrentRowFields());
            resultStatus = STATUS_PARTIAL;
        }
    } else if (COL_NAME.equals(localName)) {
        CallableStatement cs = (CallableStatement) sqlStatementInfo.getStatement();
        try {
            if (!outOnly) {
                colDataExpecting = false;
                String text = textBuffer.toString();
                if ((currentUUID != null) && (currentUUID.trim().length() > 0) && (text.length() == 0)) {
                    text = uuids.get(currentUUID);
                    if (text == null) {
                        text = currentUUID;
                    }
                }
                if (TIMESTAMP_TYPE.equals(currType) || DATE_TYPE.equals(currType)
                        || TIME_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (TIMESTAMP_TYPE.equals(currType))
                            setNull(cs, Types.TIMESTAMP);
                        else if (DATE_TYPE.equals(currType))
                            setNull(cs, Types.DATE);
                        else
                            setNull(cs, Types.TIME);
                        currentRowFields.add(null);
                    } else {
                        dateFormatter.applyPattern(currDateFormat);
                        Date formattedDate = dateFormatter.parse(text);
                        if (TIMESTAMP_TYPE.equals(currType)) {
                            Timestamp ts = new Timestamp(formattedDate.getTime());
                            setTimestamp(cs, ts);
                            currentRowFields.add(ts);
                        } else if (DATE_TYPE.equals(currType)) {
                            java.sql.Date d = new java.sql.Date(formattedDate.getTime());
                            setDate(cs, d);
                            currentRowFields.add(d);
                        } else {
                            java.sql.Time t = new java.sql.Time(formattedDate.getTime());
                            setTime(cs, t);
                            currentRowFields.add(t);
                        }
                    }
                } else if (INTEGER_TYPE.equals(currType) || SMALLINT_TYPE.equals(currType)
                        || BIGINT_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (INTEGER_TYPE.equals(currType))
                            setNull(cs, Types.INTEGER);
                        else if (SMALLINT_TYPE.equals(currType))
                            setNull(cs, Types.SMALLINT);
                        else
                            setNull(cs, Types.BIGINT);
                        currentRowFields.add(null);
                    } else {
                        if (INTEGER_TYPE.equals(currType))
                            setInt(cs, Integer.parseInt(text, 10));
                        else if (SMALLINT_TYPE.equals(currType))
                            setShort(cs, Short.parseShort(text, 10));
                        else
                            setLong(cs, Long.parseLong(text, 10));
                        currentRowFields.add(text);
                    }
                } else if (FLOAT_TYPE.equals(currType) || DOUBLE_TYPE.equals(currType)
                        || DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType))
                            setNull(cs, Types.NUMERIC);
                        else if (FLOAT_TYPE.equals(currType))
                            setNull(cs, Types.FLOAT);
                        else
                            setNull(cs, Types.DOUBLE);
                        currentRowFields.add(null);
                    } else {
                        DecimalFormatSymbols dfs = numberFormatter.getDecimalFormatSymbols();
                        dfs.setDecimalSeparator(currDecSeparator.charAt(0));
                        dfs.setGroupingSeparator(currGroupSeparator.charAt(0));
                        numberFormatter.setDecimalFormatSymbols(dfs);
                        numberFormatter.applyPattern(currNumberFormat);
                        boolean isBigDecimal = numberFormatter.isParseBigDecimal();
                        try {
                            numberFormatter.setParseBigDecimal(true);
                            BigDecimal formattedNumber = (BigDecimal) numberFormatter.parse(text);
                            if (DECIMAL_TYPE.equals(currType) || NUMERIC_TYPE.equals(currType)) {
                                setBigDecimal(cs, formattedNumber);
                                currentRowFields.add(formattedNumber);
                            } else if (FLOAT_TYPE.equals(currType)) {
                                setFloat(cs, formattedNumber.floatValue());
                                currentRowFields.add(formattedNumber.floatValue());
                            } else {
                                setDouble(cs, formattedNumber.doubleValue());
                                currentRowFields.add(formattedNumber.doubleValue());
                            }
                        } finally {
                            numberFormatter.setParseBigDecimal(isBigDecimal);
                        }
                    }
                } else if (LONG_STRING_TYPE.equals(currType) || LONG_NSTRING_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        if (LONG_STRING_TYPE.equals(currType))
                            setNull(cs, Types.CLOB);
                        else
                            setNull(cs, Types.NCLOB);
                        currentRowFields.add(null);
                    } else {
                        if (LONG_STRING_TYPE.equals(currType)) {
                            setCharacterStream(cs, new StringReader(text));
                            currentRowFields.add(text);
                        } else {
                            setNCharacterStream(cs, new StringReader(text));
                            currentRowFields.add(text);
                        }
                    }
                } else if (BASE64_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BLOB);
                        currentRowFields.add(null);
                    } else {
                        byte[] data = text.getBytes();
                        data = Base64.getDecoder().decode(data);
                        ByteArrayInputStream bais = new ByteArrayInputStream(data);
                        setBinaryStream(cs, bais, data.length);
                        currentRowFields.add(text);
                    }
                } else if (BINARY_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BLOB);
                        currentRowFields.add(null);
                    } else {
                        byte[] data = text.getBytes();
                        ByteArrayInputStream bais = new ByteArrayInputStream(data);
                        setBinaryStream(cs, bais, data.length);
                        currentRowFields.add(text);
                    }
                } else if (BOOLEAN_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.BOOLEAN);
                        currentRowFields.add(null);
                    } else {
                        setBoolean(cs, TextUtils.parseBoolean(text));
                        currentRowFields.add(text);
                    }
                } else if (XML_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.SQLXML);
                        currentRowFields.add(null);
                    } else {
                        SQLXML xml = cs.getConnection().createSQLXML();
                        xml.setString(text);
                        setSQLXML(cs, xml);
                        currentRowFields.add(text);
                    }
                } else if (NSTRING_TYPE.equals(currType)) {
                    if (text.equals("")) {
                        setNull(cs, Types.NVARCHAR);
                        currentRowFields.add(null);
                    } else {
                        setNString(cs, text);
                        currentRowFields.add(text);
                    }
                } else {
                    if (text.equals("")) {
                        setNull(cs, Types.VARCHAR);
                        currentRowFields.add(null);
                    } else {
                        setString(cs, text);
                        currentRowFields.add(text);
                    }
                }
            } else {
                currentRowFields.add(currentUUID);
            }
        } catch (ParseException exc) {
            throw new SAXException(exc);
        } catch (SQLException exc) {
            OracleExceptionHandler.handleSQLException(exc);
            throw new SAXException(exc);
        }
    }
}

From source file:org.dspace.storage.rdbms.MockDatabaseManager.java

@Mock
private static void loadParameters(PreparedStatement statement, Collection<ColumnInfo> columns, TableRow row)
        throws SQLException {
    int count = 0;
    for (ColumnInfo info : columns) {
        count++;//from   w ww  .j a  v  a  2  s. c o  m
        String column = info.getName();
        int jdbctype = info.getType();

        if (row.isColumnNull(column)) {
            statement.setNull(count, jdbctype);
        } else {
            switch (jdbctype) {
            case Types.BIT:
            case Types.BOOLEAN:
                statement.setBoolean(count, row.getBooleanColumn(column));
                break;

            case Types.INTEGER:
                if (isOracle) {
                    statement.setLong(count, row.getLongColumn(column));
                } else {
                    statement.setInt(count, row.getIntColumn(column));
                }
                break;

            case Types.NUMERIC:
            case Types.DECIMAL:
                statement.setLong(count, row.getLongColumn(column));
                // FIXME should be BigDecimal if TableRow supported that
                break;

            case Types.BIGINT:
                statement.setLong(count, row.getLongColumn(column));
                break;

            case Types.CLOB:
                if (isOracle) {
                    // Support CLOBs in place of TEXT columns in Oracle
                    statement.setString(count, row.getStringColumn(column));
                } else {
                    throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
                }
                break;

            case Types.VARCHAR:
                statement.setString(count, row.getStringColumn(column));
                break;

            case Types.DATE:
                statement.setDate(count, new java.sql.Date(row.getDateColumn(column).getTime()));
                break;

            case Types.TIME:
                statement.setTime(count, new Time(row.getDateColumn(column).getTime()));
                break;

            case Types.TIMESTAMP:
                statement.setTimestamp(count, new Timestamp(row.getDateColumn(column).getTime()));
                break;

            default:
                throw new IllegalArgumentException("Unsupported JDBC type: " + jdbctype);
            }
        }
    }
}