Search in sources :

Example 96 with Time

use of java.sql.Time in project hazelcast by hazelcast.

the class DateHelperTest method testTimeWithTrailingZeros.

@Test
public void testTimeWithTrailingZeros() throws Exception {
    // Given
    Time expectedTime = new Time(new SimpleDateFormat(SQL_TIME_FORMAT).parse("10:20:30").getTime());
    // When
    Time actualTime = DateHelper.parseSqlTime(expectedTime.toString());
    // Then
    assertSqlTimesEqual(expectedTime, actualTime);
}
Also used : Time(java.sql.Time) SimpleDateFormat(java.text.SimpleDateFormat) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 97 with Time

use of java.sql.Time in project hazelcast by hazelcast.

the class DateHelperTest method testTimeWithLeadingZeros.

@Test
public void testTimeWithLeadingZeros() throws Exception {
    // Given
    Time expectedTime = new Time(new SimpleDateFormat(SQL_TIME_FORMAT).parse("01:02:03").getTime());
    // When
    Time actualTime = DateHelper.parseSqlTime(expectedTime.toString());
    // Then
    assertSqlTimesEqual(expectedTime, actualTime);
}
Also used : Time(java.sql.Time) SimpleDateFormat(java.text.SimpleDateFormat) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 98 with Time

use of java.sql.Time in project hibernate-orm by hibernate.

the class JdbcTimeTypeDescriptor method unwrap.

@SuppressWarnings({ "unchecked" })
@Override
public <X> X unwrap(Date value, Class<X> type, WrapperOptions options) {
    if (value == null) {
        return null;
    }
    if (Time.class.isAssignableFrom(type)) {
        final Time rtn = Time.class.isInstance(value) ? (Time) value : new Time(value.getTime());
        return (X) rtn;
    }
    if (java.sql.Date.class.isAssignableFrom(type)) {
        final java.sql.Date rtn = java.sql.Date.class.isInstance(value) ? (java.sql.Date) value : new java.sql.Date(value.getTime());
        return (X) rtn;
    }
    if (java.sql.Timestamp.class.isAssignableFrom(type)) {
        final java.sql.Timestamp rtn = java.sql.Timestamp.class.isInstance(value) ? (java.sql.Timestamp) value : new java.sql.Timestamp(value.getTime());
        return (X) rtn;
    }
    if (java.util.Date.class.isAssignableFrom(type)) {
        return (X) value;
    }
    if (Calendar.class.isAssignableFrom(type)) {
        final GregorianCalendar cal = new GregorianCalendar();
        cal.setTimeInMillis(value.getTime());
        return (X) cal;
    }
    if (Long.class.isAssignableFrom(type)) {
        return (X) Long.valueOf(value.getTime());
    }
    throw unknownUnwrap(type);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Time(java.sql.Time) Date(java.util.Date)

Example 99 with Time

use of java.sql.Time in project henplus by neurolabs.

the class DumpCommand method dumpTable.

private int dumpTable(final SQLSession session, final DumpSource dumpSource, final PrintStream dumpOut, final String fileEncoding) throws Exception {
    final long startTime = System.currentTimeMillis();
    final MetaProperty[] metaProps = dumpSource.getMetaProperties();
    if (metaProps.length == 0) {
        HenPlus.msg().println("No fields in " + dumpSource.getDescription() + " found.");
        return EXEC_FAILED;
    }
    HenPlus.msg().println("dump " + dumpSource.getTableName() + ":");
    dumpOut.println("(tabledump '" + dumpSource.getTableName() + "'");
    dumpOut.println("  (file-encoding '" + fileEncoding + "')");
    dumpOut.println("  (dump-version " + DUMP_VERSION + " " + DUMP_VERSION + ")");
    /*
         * if (whereClause != null) { dumpOut.print("  (where-clause ");
         * quoteString(dumpOut, whereClause); dumpOut.println(")"); }
         */
    dumpOut.println("  (henplus-version '" + Version.getVersion() + "')");
    dumpOut.println("  (time '" + new Timestamp(System.currentTimeMillis()) + "')");
    dumpOut.print("  (database-info ");
    quoteString(dumpOut, session.getDatabaseInfo());
    dumpOut.println(")");
    final long expectedRows = dumpSource.getExpectedRows();
    dumpOut.println("  (estimated-rows '" + expectedRows + "')");
    dumpOut.print("  (meta (");
    for (int i = 0; i < metaProps.length; ++i) {
        final MetaProperty p = metaProps[i];
        printWidth(dumpOut, p.fieldName, p.renderWidth(), i != 0);
    }
    dumpOut.println(")");
    dumpOut.print("\t(");
    for (int i = 0; i < metaProps.length; ++i) {
        final MetaProperty p = metaProps[i];
        printWidth(dumpOut, p.typeName, p.renderWidth(), i != 0);
    }
    dumpOut.println("))");
    dumpOut.print("  (data ");
    ResultSet rset = null;
    Statement stmt = null;
    try {
        long rows = 0;
        final ProgressWriter progressWriter = new ProgressWriter(expectedRows, HenPlus.msg());
        rset = dumpSource.getResultSet();
        stmt = dumpSource.getStatement();
        boolean isFirst = true;
        while (_running && rset.next()) {
            ++rows;
            progressWriter.update(rows);
            if (!isFirst) {
                dumpOut.print("\n\t");
            }
            isFirst = false;
            dumpOut.print("(");
            for (int i = 0; i < metaProps.length; ++i) {
                final int col = i + 1;
                final int thisType = metaProps[i].getType();
                switch(thisType) {
                    case HP_INTEGER:
                    case HP_NUMERIC:
                    case HP_DOUBLE:
                        {
                            final String val = rset.getString(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                dumpOut.print(val);
                            }
                            break;
                        }
                    case HP_TIMESTAMP:
                        {
                            final Timestamp val = rset.getTimestamp(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                quoteString(dumpOut, val.toString());
                            }
                            break;
                        }
                    case HP_TIME:
                        {
                            final Time val = rset.getTime(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                quoteString(dumpOut, val.toString());
                            }
                            break;
                        }
                    case HP_DATE:
                        {
                            final java.sql.Date val = rset.getDate(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                quoteString(dumpOut, val.toString());
                            }
                            break;
                        }
                    // we try our best by reading BLOB/CLOB
                    case HP_BLOB:
                    // as String (known not to work on Oracle)
                    case HP_CLOB:
                    case HP_STRING:
                        {
                            final String val = rset.getString(col);
                            if (rset.wasNull()) {
                                dumpOut.print(NULL_STR);
                            } else {
                                quoteString(dumpOut, val);
                            }
                            break;
                        }
                    case HP_BOOLEAN:
                        final boolean val = rset.getBoolean(col);
                        if (rset.wasNull()) {
                            dumpOut.print(NULL_STR);
                        } else {
                            dumpOut.print(val);
                        }
                        break;
                    default:
                        throw new IllegalArgumentException("type " + TYPES[thisType] + " not supported yet");
                }
                if (metaProps.length > col) {
                    dumpOut.print(",");
                } else {
                    dumpOut.print(")");
                }
            }
        }
        progressWriter.finish();
        dumpOut.println(")");
        dumpOut.println("  (rows " + rows + "))\n");
        HenPlus.msg().print("(" + rows + " rows)\n");
        final long execTime = System.currentTimeMillis() - startTime;
        HenPlus.msg().print("dumping '" + dumpSource.getTableName() + "' took ");
        TimeRenderer.printTime(execTime, HenPlus.msg());
        HenPlus.msg().print(" total; ");
        TimeRenderer.printFraction(execTime, rows, HenPlus.msg());
        HenPlus.msg().println(" / row");
        if (expectedRows >= 0 && rows != expectedRows) {
            HenPlus.msg().println(" == Warning: 'select count(*)' in the" + " beginning resulted in " + expectedRows + " but the dump exported " + rows + " rows == ");
        }
        if (!_running) {
            HenPlus.msg().println(" == INTERRUPTED. Wait for statement to cancel.. ==");
            if (stmt != null) {
                stmt.cancel();
            }
        }
    } catch (final Exception e) {
        // handle later.
        throw e;
    } finally {
        if (rset != null) {
            try {
                rset.close();
            } catch (final Exception e) {
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (final Exception e) {
            }
        }
    }
    return SUCCESS;
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ProgressWriter(henplus.view.util.ProgressWriter) Time(java.sql.Time) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) IOException(java.io.IOException) ResultSet(java.sql.ResultSet)

Example 100 with Time

use of java.sql.Time in project android-demos by novoda.

the class AudioStreamService method onPrepared.

public void onPrepared(MediaPlayer mp) {
    mAudioSrvState = PLAYING;
    Time duration = new Time(mp.getDuration());
    Log.v(TAG, "Prepared mediaplayer for track of duration =[" + duration + "]");
    mMediaPlayer.start();
}
Also used : Time(java.sql.Time)

Aggregations

Time (java.sql.Time)182 Test (org.junit.Test)58 Timestamp (java.sql.Timestamp)50 Date (java.sql.Date)43 ResultSet (java.sql.ResultSet)32 LocalTime (java.time.LocalTime)32 Test (org.testng.annotations.Test)30 SQLException (java.sql.SQLException)26 Calendar (java.util.Calendar)25 BaseTest (util.BaseTest)25 BigDecimal (java.math.BigDecimal)21 Connection (java.sql.Connection)21 PreparedStatement (java.sql.PreparedStatement)21 Date (java.util.Date)19 JDateTime (jodd.datetime.JDateTime)11 ArrayList (java.util.ArrayList)10 GregorianCalendar (java.util.GregorianCalendar)10 Statement (java.sql.Statement)8 SimpleDateFormat (java.text.SimpleDateFormat)8 MyTime (mbg.test.common.MyTime)8