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);
}
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);
}
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);
}
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;
}
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();
}
Aggregations