Example usage for java.sql Time Time

List of usage examples for java.sql Time Time

Introduction

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

Prototype

public Time(long time) 

Source Link

Document

Constructs a Time object using a milliseconds time value.

Usage

From source file:org.openxdata.server.export.rdbms.engine.DataBuilder.java

private Object getColumnValue(Document schemaDocument, Node node) {
    String x = node.getTextContent();
    if (x == null || x.trim().length() == 0) {
        return null;
    }/*from   ww  w.ja v  a  2 s .c  o m*/
    String columnType = Functions.resolveType(schemaDocument, node.getNodeName());
    if (columnType.equalsIgnoreCase(Constants.TYPE_DATE)) {
        java.sql.Date date = java.sql.Date.valueOf(x); // must be yyyy-MM-dd format
        return date;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_TIME)) {
        Time time = null;
        String xTime = x.toUpperCase();
        try {
            if (xTime.contains("PM") || xTime.contains("AM")) {
                time = new Time(new SimpleDateFormat("hh:mm:ss aaa").parse(xTime).getTime());
            } else {
                time = Time.valueOf(x); // must be HH:mm:ss format
            }
        } catch (Exception e) {
            log.warn("Could not convert time '" + x + "' to sql Time", e);
        }
        return time;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_DATETIME)) {
        Timestamp datetime = Timestamp.valueOf(x); // must be yyyy-MM-dd HH:mm:ss format
        return datetime;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_BOOLEAN)) {
        Boolean bool = new Boolean(x); // note: see Functions.resolveType - boolean is actually VARCHAR
        return bool;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_DECIMAL)) {
        Double dub = new Double(x);
        return dub;
    }
    if (columnType.equalsIgnoreCase(Constants.TYPE_INTEGER)) {
        Integer in = new Integer(x);
        return in;
    }
    // VARCHAR or CHAR
    return x;
}

From source file:org.wso2.carbon.ml.model.spark.algorithms.SupervisedModel.java

/**
 * This method builds a logistic regression model
 *
 * @param trainingData Training data//  w ww  .j ava 2 s .c o  m
 * @param testingData  Testing data
 * @param workflow     Machine learning workflow
 * @throws org.wso2.carbon.ml.model.exceptions.ModelServiceException
 */
private void buildLogisticRegressionModel(String modelID, JavaRDD<LabeledPoint> trainingData,
        JavaRDD<LabeledPoint> testingData, MLWorkflow workflow) throws ModelServiceException {
    try {
        DatabaseHandler databaseHandler = new DatabaseHandler();
        databaseHandler.insertModel(modelID, workflow.getWorkflowID(), new Time(System.currentTimeMillis()));
        LogisticRegression logisticRegression = new LogisticRegression();
        Map<String, String> hyperParameters = workflow.getHyperParameters();
        LogisticRegressionModel model = logisticRegression.trainWithSGD(trainingData,
                Double.parseDouble(hyperParameters.get(LEARNING_RATE)),
                Integer.parseInt(hyperParameters.get(ITERATIONS)), hyperParameters.get(REGULARIZATION_TYPE),
                Double.parseDouble(hyperParameters.get(REGULARIZATION_PARAMETER)),
                Double.parseDouble(hyperParameters.get(SGD_DATA_FRACTION)));
        model.clearThreshold();
        JavaRDD<Tuple2<Object, Object>> scoresAndLabels = logisticRegression.test(model, testingData);
        ProbabilisticClassificationModelSummary probabilisticClassificationModelSummary = logisticRegression
                .getModelSummary(scoresAndLabels);
        databaseHandler.updateModel(modelID, model, probabilisticClassificationModelSummary,
                new Time(System.currentTimeMillis()));
    } catch (DatabaseHandlerException e) {
        throw new ModelServiceException(
                "An error occured while building logistic regression " + "model: " + e.getMessage(), e);
    }
}

From source file:org.kuali.kpme.core.calendar.entry.CalendarEntryBo.java

public Time getBatchEndPayPeriodTime() {
    return batchEndPayPeriodDateTime != null ? new Time(batchEndPayPeriodDateTime.getTime()) : null;
}

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

private Object convertStringTypes(Object val, String javaColType) {
    String valStr = val.toString();
    if (javaColType.equals(BIG_DECIMAL_TYPE)) {
        return new BigDecimal(valStr);
    } else if (javaColType.equals(DATE_TYPE) || javaColType.equals(TIME_TYPE)
            || javaColType.equals(TIMESTAMP_TYPE)) {
        // Oracle expects timestamps for Date also by default based on version
        // Just allow all date types to be assignment compatible
        if (valStr.length() == 10 && valStr.matches("^\\d{4}-\\d{2}-\\d{2}$")) {
            // Date in yyyy-mm-dd format
            Date d = Date.valueOf(valStr);
            if (javaColType.equals(DATE_TYPE)) {
                return d;
            } else if (javaColType.equals(TIME_TYPE)) {
                return new Time(d.getTime());
            } else if (javaColType.equals(TIMESTAMP_TYPE)) {
                return new Timestamp(d.getTime());
            }// w  w  w  . j a  va2  s.c  o m
        } else if (valStr.length() == 8 && valStr.matches("^\\d{2}:\\d{2}:\\d{2}$")) {
            // time in hh:mm:ss
            Time t = Time.valueOf(valStr);
            if (javaColType.equals(DATE_TYPE)) {
                return new Date(t.getTime());
            } else if (javaColType.equals(TIME_TYPE)) {
                return t;
            } else if (javaColType.equals(TIMESTAMP_TYPE)) {
                return new Timestamp(t.getTime());
            }
        } else if (valStr.length() >= 19 && valStr.length() <= 26
                && valStr.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(.\\d+)?$")) {
            // timestamp in yyyy-mm-dd hh:mm:ss
            Timestamp ts = Timestamp.valueOf(valStr);
            if (javaColType.equals(DATE_TYPE)) {
                return new Date(ts.getTime());
            } else if (javaColType.equals(TIME_TYPE)) {
                return new Time(ts.getTime());
            } else if (javaColType.equals(TIMESTAMP_TYPE)) {
                return ts;
            }
        } else {
            return null;
        }
    } else if (javaColType.equals(STRING_TYPE)) {
        return valStr;
    } else if (javaColType.equals(BOOLEAN_TYPE)) {
        return Boolean.valueOf(valStr);
    } else if (javaColType.equals(BYTE_TYPE)) {
        return Byte.parseByte(valStr);
    } else if (javaColType.equals(SHORT_TYPE)) {
        return Short.parseShort(valStr);
    } else if (javaColType.equals(INTEGER_TYPE)) {
        return Integer.parseInt(valStr);
    } else if (javaColType.equals(LONG_TYPE)) {
        return Long.parseLong(valStr);
    } else if (javaColType.equals(FLOAT_TYPE)) {
        return Float.parseFloat(valStr);
    } else if (javaColType.equals(DOUBLE_TYPE)) {
        return Double.parseDouble(valStr);
    }
    return null;
}

From source file:javasnack.h2.DbUnitCsvUsageTest.java

@BeforeTest
public void prepareDb() throws Exception {
    tmpDir = FileDirHelper.createTmpDir();

    Class.forName("org.h2.Driver");
    conn = DriverManager.getConnection("jdbc:h2:mem:test2", "sa", "");

    new T1().setup(conn);
    Calendar c = Calendar.getInstance();

    c.clear();//from   w w w .jav a  2s. c o  m
    c.set(2000, 11, 31, 23, 59, 59);
    long insertTIM = c.getTimeInMillis();
    new T1(true, 10, new BigDecimal(20), 30.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \"World\"!").insertMe(conn);

    c.clear();
    c.set(2001, 0, 1, 12, 30, 15);
    insertTIM = c.getTimeInMillis();
    new T1(false, 20, new BigDecimal(30), 40.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \n\"World\"!").insertMe(conn);

    new T2().setup(conn);
    new T2(10, "abc").insertMe(conn);
    new T2(20, "def").insertMe(conn);

    new T3().setup(conn);
    new T3("label100").insertMe(conn);
    new T3("label200").insertMe(conn);

    new T4().setup(conn);
    new T4(UnsignedByte.create0x00to0xFFString(), UnsignedByte.create0x00to0xFF(),
            UnsignedByte.create0x00to0xFF()).insertMe(conn);
}

From source file:org.castor.jdo.engine.SQLTypeInfos.java

/**
 * Set given value on given PreparedStatement at given index with given SQL type.
 * /*w  w w .j  av  a2s. c  om*/
 * @param stmt The PreparedStatement to set value on.
 * @param index The index of the value in the PreparedStatement.
 * @param value The value to set.
 * @param sqlType The SQL type of the value.
 */
public static void setValue(final PreparedStatement stmt, final int index, final Object value,
        final int sqlType) {
    try {
        if (value == null) {
            stmt.setNull(index, sqlType);
        } else {
            // Special processing for BLOB and CLOB types, because they are mapped
            // by Castor to java.io.InputStream and java.io.Reader, respectively,
            // while JDBC driver expects java.sql.Blob and java.sql.Clob.
            switch (sqlType) {
            case Types.FLOAT:
            case Types.DOUBLE:
                stmt.setDouble(index, ((Double) value).doubleValue());
                break;
            case Types.REAL:
                stmt.setFloat(index, ((Float) value).floatValue());
                break;
            case Types.TIME:
                final Time time = value instanceof java.util.Date ? new Time(((java.util.Date) value).getTime())
                        : null;
                stmt.setTime(index, time != null ? time : (Time) value, getCalendar());
                break;
            case Types.DATE:
                final Date date = value instanceof java.util.Date ? new Date(((java.util.Date) value).getTime())
                        : null;
                stmt.setDate(index, date != null ? date : (Date) value);
                break;
            case Types.TIMESTAMP:
                final Timestamp timestamp = value instanceof java.util.Date
                        ? new Timestamp(((java.util.Date) value).getTime())
                        : null;
                stmt.setTimestamp(index, timestamp != null ? timestamp : (Timestamp) value, getCalendar());
                break;
            case Types.BLOB:
                try {
                    InputStream stream;
                    if (value instanceof byte[]) {
                        stream = new ByteArrayInputStream((byte[]) value);
                    } else {
                        stream = (InputStream) value;
                    }
                    stmt.setBinaryStream(index, stream, stream.available());
                } catch (IOException ex) {
                    throw new SQLException(ex.toString());
                }
                break;
            case Types.CLOB:
                if (value instanceof String) {
                    stmt.setCharacterStream(index, new StringReader((String) value),
                            Math.min(((String) value).length(), Integer.MAX_VALUE));
                } else {
                    stmt.setCharacterStream(index, ((Clob) value).getCharacterStream(),
                            (int) Math.min(((Clob) value).length(), Integer.MAX_VALUE));
                }
                break;
            default:
                stmt.setObject(index, value, sqlType);
                break;
            }
        }
    } catch (SQLException ex) {
        LOG.error("Unexpected SQL exception: ", ex);
    }
}

From source file:org.eclipse.birt.data.oda.mongodb.impl.MDbResultSet.java

public Time getTime(String columnName) throws OdaException {
    Date dateValue = getDate(columnName);
    if (dateValue == null)
        return null;
    return new Time(dateValue.getTime());
}

From source file:com.appeligo.search.actions.account.BaseAccountAction.java

public void setEarliestSmsTime(String earliestSmsTime) {
    DateFormat format = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
    try {//from ww w .j a  v a2s. co m
        this.earliestSmsTime = new Time(format.parse(earliestSmsTime).getTime());
    } catch (ParseException e) {
        log.error("Format from account_macros.vm was wrong", e);
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.appeligo.search.actions.account.BaseAccountAction.java

public void setLatestSmsTime(String latestSmsTime) {
    DateFormat format = SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
    try {//from  w  w  w  . j  a v a 2  s  . c o m
        this.latestSmsTime = new Time(format.parse(latestSmsTime).getTime());
    } catch (ParseException e) {
        log.error("Format from account_macros.vm was wrong", e);
    }
}

From source file:org.wso2.carbon.ml.model.spark.algorithms.SupervisedModel.java

/**
 * This method builds a decision tree model
 *
 * @param trainingData Training data//from w w  w .j  a v a2 s . c o m
 * @param testingData  Testing data
 * @param workflow     Machine learning workflow
 * @throws ModelServiceException
 */
private void buildDecisionTreeModel(String modelID, JavaRDD<LabeledPoint> trainingData,
        JavaRDD<LabeledPoint> testingData, MLWorkflow workflow) throws ModelServiceException {
    try {
        DatabaseHandler databaseHandler = new DatabaseHandler();
        databaseHandler.insertModel(modelID, workflow.getWorkflowID(), new Time(System.currentTimeMillis()));
        Map<String, String> hyperParameters = workflow.getHyperParameters();
        DecisionTree decisionTree = new DecisionTree();
        DecisionTreeModel decisionTreeModel = decisionTree.train(trainingData,
                Integer.parseInt(hyperParameters.get(NUM_CLASSES)), new HashMap<Integer, Integer>(),
                hyperParameters.get(IMPURITY), Integer.parseInt(hyperParameters.get(MAX_DEPTH)),
                Integer.parseInt(hyperParameters.get(MAX_BINS)));
        JavaPairRDD<Double, Double> predictionsAnsLabels = decisionTree.test(decisionTreeModel, trainingData);
        ClassClassificationModelSummary classClassificationModelSummary = decisionTree
                .getClassClassificationModelSummary(predictionsAnsLabels);
        databaseHandler.updateModel(modelID, decisionTreeModel, classClassificationModelSummary,
                new Time(System.currentTimeMillis()));
    } catch (DatabaseHandlerException e) {
        throw new ModelServiceException(
                "An error occured while building decision tree model: " + e.getMessage(), e);
    }

}