Java Code Examples for microsoft.sql.DateTimeOffset#valueOf()

The following examples show how to use microsoft.sql.DateTimeOffset#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLValidation.java    From das with Apache License 2.0 4 votes vote down vote up
/**
 * Mock a object according to the SQL Type
 *
 * @param javaSqlTypes The specified SQL Type @see java.sql.CheckTypes
 * @return Mocked object
 */

private static Object mockSQLValue(int javaSqlTypes) {
    switch (javaSqlTypes) {
        case Types.BIT:
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
        case Types.BIGINT:
            return 0;
        case Types.REAL:
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.DECIMAL:
            return 0.0;
        case Types.NUMERIC:
            return BigDecimal.ZERO;
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.NULL:
        case Types.OTHER:
            return null;
        case Types.CHAR:
            return "X";
        case Types.DATE:
            return Date.valueOf("2012-01-01");
        case Types.TIME:
            return Time.valueOf("10:00:00");
        case Types.TIMESTAMP:
            return Timestamp.valueOf("2012-01-01 10:00:00");
        case microsoft.sql.Types.DATETIMEOFFSET:
            return DateTimeOffset.valueOf(Timestamp.valueOf("2012-01-01 10:00:00"), 0);
        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
            return "TT";
        case 10001: // uniqueidentifier
            return "C4AECF65-1D5C-47B6-BFFC-0C9550C4E158";
        default:
            return null;

    }
}
 
Example 2
Source File: SQLValidation.java    From das with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the String value to java Object according to different SQL Type
 *
 * @param javaSqlTypes The SQL CheckTypes @see java.sql.CheckTypes
 * @param val The string value
 * @return Java Object
 */
private static Object parseSQLValue(int javaSqlTypes, String val) {
    if (null == val || val.equalsIgnoreCase("null")){
        return null;
    }
    switch (javaSqlTypes) {
        case Types.BIT:
            return Integer.parseInt(val) == 0 ? 0 : 1;
        case Types.TINYINT:
            return Byte.parseByte(val);
        case Types.SMALLINT:
            return Short.parseShort(val);
        case Types.INTEGER:
            return Integer.parseInt(val);
        case Types.BIGINT:
            return Long.parseLong(val);
        case Types.REAL:
            return Float.parseFloat(val);
        case Types.FLOAT:
        case Types.DOUBLE:
            return Double.parseDouble(val);
        case Types.DECIMAL:
        case Types.NUMERIC:
            return BigDecimal.valueOf(Double.parseDouble(val));
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return val.getBytes();
        case Types.NULL:
        case Types.OTHER:
            return null;
        case Types.CHAR:
            return val;
        case Types.DATE:
            // return Date.valueOf(val);
            return parseDate(val);
        case Types.TIME:
            return Time.valueOf(val);
        case Types.TIMESTAMP:
            return Timestamp.valueOf(val);
        case microsoft.sql.Types.DATETIMEOFFSET:
            return DateTimeOffset.valueOf(Timestamp.valueOf(val), 0);
        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
            return val;
        case 10001: // uniqueidentifier
            return val;
        default:
            return null;

    }
}
 
Example 3
Source File: SQLValidation.java    From dal with Apache License 2.0 4 votes vote down vote up
/**
 * Mock a object according to the SQL Type
 *
 * @param javaSqlTypes The specified SQL Type @see java.sql.Types
 * @return Mocked object
 */

private static Object mockSQLValue(int javaSqlTypes) {
    switch (javaSqlTypes) {
        case java.sql.Types.BIT:
        case java.sql.Types.TINYINT:
        case java.sql.Types.SMALLINT:
        case java.sql.Types.INTEGER:
        case java.sql.Types.BIGINT:
            return 0;
        case java.sql.Types.REAL:
        case java.sql.Types.FLOAT:
        case java.sql.Types.DOUBLE:
        case java.sql.Types.DECIMAL:
            return 0.0;
        case java.sql.Types.NUMERIC:
            return BigDecimal.ZERO;
        case java.sql.Types.BINARY:
        case java.sql.Types.VARBINARY:
        case java.sql.Types.LONGVARBINARY:
        case java.sql.Types.NULL:
        case java.sql.Types.OTHER:
            return null;
        case java.sql.Types.CHAR:
            return "X";
        case java.sql.Types.DATE:
            return java.sql.Date.valueOf("2012-01-01");
        case java.sql.Types.TIME:
            return Time.valueOf("10:00:00");
        case java.sql.Types.TIMESTAMP:
            return Timestamp.valueOf("2012-01-01 10:00:00");
        case microsoft.sql.Types.DATETIMEOFFSET:
            return DateTimeOffset.valueOf(Timestamp.valueOf("2012-01-01 10:00:00"), 0);
        case java.sql.Types.VARCHAR:
        case java.sql.Types.NVARCHAR:
        case java.sql.Types.LONGNVARCHAR:
        case java.sql.Types.LONGVARCHAR:
            return "TT";
        case 10001: // uniqueidentifier
            return "C4AECF65-1D5C-47B6-BFFC-0C9550C4E158";
        default:
            return null;

    }
}
 
Example 4
Source File: SQLValidation.java    From dal with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the String value to java Object according to different SQL Type
 *
 * @param javaSqlTypes The SQL Types @see java.sql.Types
 * @param val The string value
 * @return Java Object
 */
private static Object parseSQLValue(int javaSqlTypes, String val) {
    if (null == val || val.equalsIgnoreCase("null"))
        return null;
    switch (javaSqlTypes) {
        case java.sql.Types.BIT:
            return Integer.parseInt(val) == 0 ? 0 : 1;
        case java.sql.Types.TINYINT:
            return Byte.parseByte(val);
        case java.sql.Types.SMALLINT:
            return Short.parseShort(val);
        case java.sql.Types.INTEGER:
            return Integer.parseInt(val);
        case java.sql.Types.BIGINT:
            return Long.parseLong(val);
        case java.sql.Types.REAL:
            return Float.parseFloat(val);
        case java.sql.Types.FLOAT:
        case java.sql.Types.DOUBLE:
            return Double.parseDouble(val);
        case java.sql.Types.DECIMAL:
        case java.sql.Types.NUMERIC:
            return BigDecimal.valueOf(Double.parseDouble(val));
        case java.sql.Types.BINARY:
        case java.sql.Types.VARBINARY:
        case java.sql.Types.LONGVARBINARY:
            return val.getBytes();
        case java.sql.Types.NULL:
        case java.sql.Types.OTHER:
            return null;
        case java.sql.Types.CHAR:
            return val;
        case java.sql.Types.DATE:
            // return Date.valueOf(val);
            return parseDate(val);
        case java.sql.Types.TIME:
            return Time.valueOf(val);
        case java.sql.Types.TIMESTAMP:
            return Timestamp.valueOf(val);
        case microsoft.sql.Types.DATETIMEOFFSET:
            return DateTimeOffset.valueOf(Timestamp.valueOf(val), 0);
        case java.sql.Types.VARCHAR:
        case java.sql.Types.NVARCHAR:
        case java.sql.Types.LONGNVARCHAR:
        case java.sql.Types.LONGVARCHAR:
            return val;
        case 10001: // uniqueidentifier
            return val;
        default:
            return null;

    }
}