Example usage for java.sql Types TIME

List of usage examples for java.sql Types TIME

Introduction

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

Prototype

int TIME

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

Click Source Link

Document

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

Usage

From source file:org.apache.openjpa.persistence.jdbc.AnnotationPersistenceMappingParser.java

/**
 * Parse @Temporal.// ww w .  ja  va  2s  .c  o m
 */
private void parseTemporal(FieldMapping fm, Temporal anno) {
    List<Column> cols = fm.getValueInfo().getColumns();
    if (!cols.isEmpty() && cols.size() != 1)
        throw new MetaDataException(_loc.get("num-cols-mismatch", fm, String.valueOf(cols.size()), "1"));
    if (cols.isEmpty()) {
        cols = Arrays.asList(new Column[] { new Column() });
        if (fm.isElementCollection()) {
            if (!fm.getElementMapping().getValueInfo().getColumns().isEmpty())
                cols = fm.getElementMapping().getValueInfo().getColumns();
            else
                fm.getElementMapping().getValueInfo().setColumns(cols);
        } else
            fm.getValueInfo().setColumns(cols);
    }

    Column col = (Column) cols.get(0);
    switch (anno.value()) {
    case DATE:
        col.setType(Types.DATE);
        break;
    case TIME:
        col.setType(Types.TIME);
        break;
    case TIMESTAMP:
        col.setType(Types.TIMESTAMP);
        break;
    }
}

From source file:org.apache.openjpa.persistence.jdbc.AnnotationPersistenceMappingParser.java

/**
 * Parse @Temporal./*from  www.  j  a v a  2  s.  c o  m*/
 */
private void parseMapKeyTemporal(FieldMapping fm, MapKeyTemporal anno) {
    List<Column> cols = fm.getKeyMapping().getValueInfo().getColumns();
    if (!cols.isEmpty() && cols.size() != 1)
        throw new MetaDataException(_loc.get("num-cols-mismatch", fm, String.valueOf(cols.size()), "1"));
    if (cols.isEmpty()) {
        cols = Arrays.asList(new Column[] { new Column() });
        fm.getKeyMapping().getValueInfo().setColumns(cols);
    }

    Column col = (Column) cols.get(0);
    switch (anno.value()) {
    case DATE:
        col.setType(Types.DATE);
        break;
    case TIME:
        col.setType(Types.TIME);
        break;
    case TIMESTAMP:
        col.setType(Types.TIMESTAMP);
        break;
    }
}

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

/**
 * Generates the string representation of the given value.
 *
 * @param column/*from  ww  w  . j a  va 2  s  . co  m*/
 *            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.wso2.carbon.dataservices.core.description.query.SQLQuery.java

private void setTimeValue(int queryType, String paramName, String value, String paramType,
        PreparedStatement sqlQuery, int i) throws SQLException, DataServiceFault {
    Time time = null;/* w w  w.  j a  v a  2  s . c  om*/
    try {
        if (value != null) {
            time = DBUtils.getTime(value);
        }
    } catch (ParseException e) {
        throw new DataServiceFault(e, "Incorrect Time format for parameter : " + paramName
                + ". Time should be in the format hh:mm:ss");
    } catch (DataServiceFault e) {
        throw new DataServiceFault(e,
                "Error processing parameter - " + paramName + ", Error - " + e.getMessage());
    }
    if ("IN".equals(paramType)) {
        if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
            if (value == null) {
                sqlQuery.setNull(i + 1, java.sql.Types.TIME);
            } else {
                sqlQuery.setTime(i + 1, time);
            }
        } else {
            if (value == null) {
                ((CallableStatement) sqlQuery).setNull(i + 1, java.sql.Types.TIME);
            } else {
                ((CallableStatement) sqlQuery).setTime(i + 1, time);
            }
        }
    } else if ("INOUT".equals(paramType)) {
        if (value == null) {
            ((CallableStatement) sqlQuery).setNull(i + 1, java.sql.Types.TIME);
        } else {
            ((CallableStatement) sqlQuery).setTime(i + 1, time);
        }
        ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.TIME);
    } else {
        ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.TIME);
    }
}

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

/**
 * Return the preferred {@link Types} constant for the given
 * {@link JavaTypes} or {@link JavaSQLTypes} constant.
 *///w  w  w .jav  a  2 s .  com
public int getJDBCType(int metaTypeCode, boolean lob, int precis, int scale) {
    if (lob) {
        switch (metaTypeCode) {
        case JavaTypes.STRING:
        case JavaSQLTypes.ASCII_STREAM:
        case JavaSQLTypes.CHAR_STREAM:
            return getPreferredType(Types.CLOB);
        default:
            return getPreferredType(Types.BLOB);
        }
    }

    switch (metaTypeCode) {
    case JavaTypes.BOOLEAN:
    case JavaTypes.BOOLEAN_OBJ:
        return getPreferredType(Types.BIT);
    case JavaTypes.BYTE:
    case JavaTypes.BYTE_OBJ:
        return getPreferredType(Types.TINYINT);
    case JavaTypes.CHAR:
    case JavaTypes.CHAR_OBJ:
        if (storeCharsAsNumbers)
            return getPreferredType(Types.INTEGER);
        return getPreferredType(Types.CHAR);
    case JavaTypes.DOUBLE:
    case JavaTypes.DOUBLE_OBJ:
        if (precis > 0 || scale > 0) {
            return getPreferredType(Types.NUMERIC);
        } else {
            return getPreferredType(Types.DOUBLE);
        }
    case JavaTypes.FLOAT:
    case JavaTypes.FLOAT_OBJ:
        if (precis > 0 || scale > 0) {
            return getPreferredType(Types.NUMERIC);
        } else {
            return getPreferredType(Types.REAL);
        }
    case JavaTypes.INT:
    case JavaTypes.INT_OBJ:
        return getPreferredType(Types.INTEGER);
    case JavaTypes.LONG:
    case JavaTypes.LONG_OBJ:
        return getPreferredType(Types.BIGINT);
    case JavaTypes.SHORT:
    case JavaTypes.SHORT_OBJ:
        return getPreferredType(Types.SMALLINT);
    case JavaTypes.STRING:
    case JavaTypes.LOCALE:
    case JavaSQLTypes.ASCII_STREAM:
    case JavaSQLTypes.CHAR_STREAM:
        return getPreferredType(Types.VARCHAR);
    case JavaTypes.BIGINTEGER:
        if (storeLargeNumbersAsStrings)
            return getPreferredType(Types.VARCHAR);
        return getPreferredType(Types.BIGINT);
    case JavaTypes.BIGDECIMAL:
        if (storeLargeNumbersAsStrings)
            return getPreferredType(Types.VARCHAR);
        return getPreferredType(Types.NUMERIC);
    case JavaTypes.NUMBER:
        if (storeLargeNumbersAsStrings)
            return getPreferredType(Types.VARCHAR);
        return getPreferredType(Types.NUMERIC);
    case JavaTypes.CALENDAR:
    case JavaTypes.DATE:
        return getPreferredType(Types.TIMESTAMP);
    case JavaSQLTypes.SQL_ARRAY:
        return getPreferredType(Types.ARRAY);
    case JavaSQLTypes.BINARY_STREAM:
    case JavaSQLTypes.BLOB:
    case JavaSQLTypes.BYTES:
        return getPreferredType(Types.BLOB);
    case JavaSQLTypes.CLOB:
        return getPreferredType(Types.CLOB);
    case JavaSQLTypes.SQL_DATE:
        return getPreferredType(Types.DATE);
    case JavaSQLTypes.TIME:
        return getPreferredType(Types.TIME);
    case JavaSQLTypes.TIMESTAMP:
        return getPreferredType(Types.TIMESTAMP);
    default:
        return getPreferredType(Types.BLOB);
    }
}

From source file:helma.objectmodel.db.NodeManager.java

private void setStatementValue(PreparedStatement stmt, int stmtNumber, Property p, int columnType)
        throws SQLException {
    if (p.getValue() == null) {
        stmt.setNull(stmtNumber, columnType);
    } else {//from  w  w  w . j av a  2 s  .  c  o m
        switch (columnType) {
        case Types.BIT:
        case Types.BOOLEAN:
            stmt.setBoolean(stmtNumber, p.getBooleanValue());

            break;

        case Types.TINYINT:
        case Types.BIGINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            stmt.setLong(stmtNumber, p.getIntegerValue());

            break;

        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.NUMERIC:
        case Types.DECIMAL:
            stmt.setDouble(stmtNumber, p.getFloatValue());

            break;

        case Types.LONGVARBINARY:
        case Types.VARBINARY:
        case Types.BINARY:
        case Types.BLOB:
            Object b = p.getJavaObjectValue();
            if (b instanceof byte[]) {
                byte[] buf = (byte[]) b;
                try {
                    stmt.setBytes(stmtNumber, buf);
                } catch (SQLException x) {
                    ByteArrayInputStream bout = new ByteArrayInputStream(buf);
                    stmt.setBinaryStream(stmtNumber, bout, buf.length);
                }
            } else {
                throw new SQLException(
                        "expected byte[] for binary column '" + p.getName() + "', found " + b.getClass());
            }

            break;

        case Types.LONGVARCHAR:
            try {
                stmt.setString(stmtNumber, p.getStringValue());
            } catch (SQLException x) {
                String str = p.getStringValue();
                Reader r = new StringReader(str);
                stmt.setCharacterStream(stmtNumber, r, str.length());
            }

            break;

        case Types.CLOB:
            String val = p.getStringValue();
            Reader isr = new StringReader(val);
            stmt.setCharacterStream(stmtNumber, isr, val.length());

            break;

        case Types.CHAR:
        case Types.VARCHAR:
        case Types.OTHER:
            stmt.setString(stmtNumber, p.getStringValue());

            break;

        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
            stmt.setTimestamp(stmtNumber, p.getTimestampValue());

            break;

        case Types.NULL:
            stmt.setNull(stmtNumber, 0);

            break;

        default:
            stmt.setString(stmtNumber, p.getStringValue());

            break;
        }
    }
}

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   ww w  .  j  a v a2s . co  m*/
 *
 * @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.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 ww. ja va  2s.c om*/

        return sType;
    }
}

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

/**
 * Return a SQL string to act as a placeholder for the given column.
 *//* www .  j a  v  a  2s  . c o m*/
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:com.streamsets.pipeline.stage.origin.jdbc.cdc.oracle.OracleCDCSource.java

private Map<String, Integer> getTableSchema(SchemaAndTable schemaAndTable) throws SQLException {
    Map<String, Integer> columns = new HashMap<>();
    String query = "SELECT * FROM \"" + schemaAndTable.getSchema() + "\".\"" + schemaAndTable.getTable()
            + "\" WHERE 1 = 0";
    try (Statement schemaStatement = connection.createStatement();
            ResultSet rs = schemaStatement.executeQuery(query)) {
        ResultSetMetaData md = rs.getMetaData();
        int colCount = md.getColumnCount();
        for (int i = 1; i <= colCount; i++) {
            int colType = md.getColumnType(i);
            String colName = md.getColumnName(i);
            if (!configBean.baseConfigBean.caseSensitive) {
                colName = colName.toUpperCase();
            }//from  ww  w . j  a v a 2 s.co  m
            if (colType == Types.DATE || colType == Types.TIME || colType == Types.TIMESTAMP) {
                dateTimeColumns.computeIfAbsent(schemaAndTable, k -> new HashMap<>());
                dateTimeColumns.get(schemaAndTable).put(colName, md.getColumnTypeName(i));
            }

            if (colType == Types.DECIMAL || colType == Types.NUMERIC) {
                decimalColumns.computeIfAbsent(schemaAndTable, k -> new HashMap<>());
                decimalColumns.get(schemaAndTable).put(colName,
                        new PrecisionAndScale(md.getPrecision(i), md.getScale(i)));
            }
            columns.put(md.getColumnName(i), md.getColumnType(i));
        }
    }
    return columns;
}