List of usage examples for java.sql Timestamp setNanos
public void setNanos(int n)
From source file:com.commander4j.util.JUtility.java
public static Timestamp getTimeStampFromISOString(String isoString) { Timestamp result; // 2010-05-31T10:14:49 // 0123456789111111111 // 012345678// ww w . j a v a2s . co m try { Calendar caldate = Calendar.getInstance(); int year = 0; int month = 0; int day = 0; int hour = 0; int min = 0; int second = 0; year = Integer.valueOf(isoString.substring(0, 4)); month = Integer.valueOf(isoString.substring(5, 7)); day = Integer.valueOf(isoString.substring(8, 10)); hour = Integer.valueOf(isoString.substring(11, 13)); min = Integer.valueOf(isoString.substring(14, 16)); second = Integer.valueOf(isoString.substring(17, 19)); if ((month < 1) | (month > 12)) { throw new Exception("Invalid month " + String.valueOf(month)); } if ((day < 1) | (day > 31)) { throw new Exception("Invalid day " + String.valueOf(day)); } caldate.set(year, month - 1, day, hour, min, second); result = new Timestamp(caldate.getTimeInMillis()); result.setNanos(0); // or other value } catch (Exception ex) { result = null; } return result; }
From source file:kx.c.java
Timestamp rp() { long j = rj(), d = j < 0 ? (j + 1) / n - 1 : j / n; Timestamp p = new Timestamp(j == nj ? j : gl(k + 1000 * d)); if (j != nj)/* w ww . ja va 2 s.c o m*/ p.setNanos((int) (j - n * d)); return p; }
From source file:com.clustercontrol.monitor.util.MonitorFilterPropertyUtil.java
/** * DTO?????//from www.j a va 2 s .com * * @param property * @return */ public static MonitorFilterInfo property2dto(Property property) { MonitorFilterInfo info = new MonitorFilterInfo(); String monitorId = null; // ID String monitorTypeId = null;// ID String description = null; // String facilityId = null; // ID String calendarId = null; // String regUser = null; // ?? Timestamp regFromDate = null; // ?(From) Timestamp regToDate = null; // ?(To) String updateUser = null; // Timestamp updateFromDate = null; // (From) Timestamp updateToDate = null; // (To) Boolean monitorFlg = null; // Boolean collectorFlg = null; // ? String ownerRoleId = null; // ID ArrayList<?> values = null; //ID values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.MONITOR_ID); if (!"".equals(values.get(0))) { monitorId = (String) values.get(0); info.setMonitorId(monitorId); } //ID values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.MONITOR_TYPE_ID); if (!"".equals(values.get(0))) { monitorTypeId = (String) values.get(0); info.setMonitorTypeId(monitorTypeId); } // values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.DESCRIPTION); if (!"".equals(values.get(0))) { description = (String) values.get(0); info.setDescription(description); } //ID values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.FACILITY_ID); if (!"".equals(values.get(0))) { FacilityTreeItem item = (FacilityTreeItem) values.get(0); facilityId = item.getData().getFacilityId(); info.setFacilityId(facilityId); } // values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.CALENDAR_ID); if (!"".equals(values.get(0))) { calendarId = (String) values.get(0); info.setCalendarId(calendarId); } //?? values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.REG_USER); if (!"".equals(values.get(0))) { regUser = (String) values.get(0); info.setRegUser(regUser); } //?(From) values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.REG_FROM_DATE); if (values.get(0) instanceof Date) { regFromDate = new Timestamp(((Date) values.get(0)).getTime()); regFromDate.setNanos(999999999); info.setRegFromDate(regFromDate.getTime()); } //?(To) values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.REG_TO_DATE); if (values.get(0) instanceof Date) { regToDate = new Timestamp(((Date) values.get(0)).getTime()); regToDate.setNanos(999999999); info.setRegToDate(regToDate.getTime()); } // values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.UPDATE_USER); if (!"".equals(values.get(0))) { updateUser = (String) values.get(0); info.setUpdateUser(updateUser); } //(From) values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.UPDATE_FROM_DATE); if (values.get(0) instanceof Date) { updateFromDate = new Timestamp(((Date) values.get(0)).getTime()); updateFromDate.setNanos(999999999); info.setUpdateFromDate(updateFromDate.getTime()); } //(To) values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.UPDATE_TO_DATE); if (values.get(0) instanceof Date) { updateToDate = new Timestamp(((Date) values.get(0)).getTime()); updateToDate.setNanos(999999999); info.setUpdateToDate(updateToDate.getTime()); } // values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.MONITOR_FLG); if (!"".equals(values.get(0))) { if (ValidMessage.STRING_VALID.equals(values.get(0))) { monitorFlg = true; } else { monitorFlg = false; } } info.setMonitorFlg(monitorFlg); // ? values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.COLLECTOR_FLG); if (!"".equals(values.get(0))) { if (ValidMessage.STRING_VALID.equals(values.get(0))) { collectorFlg = true; } else { collectorFlg = false; } } info.setCollectorFlg(collectorFlg); //ID values = PropertyUtil.getPropertyValue(property, MonitorFilterConstant.OWNER_ROLE_ID); if (!"".equals(values.get(0))) { ownerRoleId = (String) values.get(0); info.setOwnerRoleId(ownerRoleId); } return info; }
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests making an indexed column required. *///www . j a va 2 s . co m public void testIndexColumnMakeRequired() { if (!getPlatformInfo().isIndicesSupported()) { return; } final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='INTEGER'/>\n" + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <index name='testindex'>\n" + " <index-column name='avalue1'/>\n" + " <index-column name='avalue2'/>\n" + " </index>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='INTEGER'/>\n" + " <column name='avalue2' type='TIMESTAMP' required='true'/>\n" + " <index name='testindex'>\n" + " <index-column name='avalue1'/>\n" + " <index-column name='avalue2'/>\n" + " </index>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Timestamp time = new Timestamp(new Date().getTime()); // some databases (such as MySql) don't store micro-/nanoseconds time.setNanos(0); insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2), time }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); assertEquals(new Integer(1), beans.get(0), "pk"); assertEquals(new Integer(2), beans.get(0), "avalue1"); assertEquals(time, beans.get(0), "avalue2"); }
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests making an indexed column no longer required. *//*from w w w . j av a2 s. c o m*/ public void testIndexColumnUnmakeRequired() { if (!getPlatformInfo().isIndicesSupported()) { return; } final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='SMALLINT' required='true'/>\n" + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <index name='testindex'>\n" + " <index-column name='avalue1'/>\n" + " <index-column name='avalue2'/>\n" + " </index>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='SMALLINT'/>\n" + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <index name='testindex'>\n" + " <index-column name='avalue1'/>\n" + " <index-column name='avalue2'/>\n" + " </index>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Timestamp time = new Timestamp(new Date().getTime()); // some databases (such as MySql) don't store micro-/nanoseconds time.setNanos(0); insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2), time }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); assertEquals(new Integer(1), beans.get(0), "pk"); assertEquals(new Integer(2), beans.get(0), "avalue1"); assertEquals(time, beans.get(0), "avalue2"); }
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests making an indexed column auto increment. *//* w ww . j a va 2s . c om*/ public void testIndexColumnMakeAutoIncrement() { if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported()) { return; } boolean isSybase = SybasePlatform.DATABASENAME.equals(getPlatform().getName()); final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + (isSybase ? " <column name='avalue1' type='NUMERIC' size='12,0'/>\n" : " <column name='avalue1' type='INTEGER'/>\n") + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <index name='testindex'>\n" + " <index-column name='avalue1'/>\n" + " <index-column name='avalue2'/>\n" + " </index>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + (isSybase ? " <column name='avalue1' type='NUMERIC' size='12,0' autoIncrement='true'/>\n" : " <column name='avalue1' type='INTEGER' autoIncrement='true'/>\n") + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <index name='testindex'>\n" + " <index-column name='avalue1'/>\n" + " <index-column name='avalue2'/>\n" + " </index>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Object value = isSybase ? (Object) new BigDecimal("0") : new Integer(0); Timestamp time = new Timestamp(new Date().getTime()); // to avoid problems with the database's time resolution time.setNanos(0); insertRow("roundtrip", new Object[] { new Integer(1), value, time }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); assertEquals(new Integer(1), beans.get(0), "pk"); assertEquals(time, beans.get(0), "avalue2"); assertEquals(value, beans.get(0), "avalue1"); }
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests making an indexed column no longer auto increment. *//* ww w . j a v a2s. c o m*/ public void testUniqeIndexColumnUnmakeAutoIncrement() { if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported()) { return; } boolean isSybase = SybasePlatform.DATABASENAME.equals(getPlatform().getName()); final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + (isSybase ? " <column name='avalue1' type='NUMERIC' size='12,0' autoIncrement='true'/>\n" : " <column name='avalue1' type='INTEGER' autoIncrement='true'/>\n") + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <unique name='testindex'>\n" + " <unique-column name='avalue1'/>\n" + " <unique-column name='avalue2'/>\n" + " </unique>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + (isSybase ? " <column name='avalue1' type='NUMERIC' size='12,0'/>\n" : " <column name='avalue1' type='INTEGER'/>\n") + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <unique name='testindex'>\n" + " <unique-column name='avalue1'/>\n" + " <unique-column name='avalue2'/>\n" + " </unique>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Timestamp time = new Timestamp(new Date().getTime()); // to avoid problems with the database's time resolution time.setNanos(0); insertRow("roundtrip", new Object[] { new Integer(1), null, time }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); List beans = getRows("roundtrip"); Object value = isSybase ? (Object) new BigDecimal("1") : new Integer(1); assertEquals(new Integer(1), beans.get(0), "pk"); assertEquals(value, beans.get(0), "avalue1"); assertEquals(time, beans.get(0), "avalue2"); }
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests adding a default value to a primary key column. *///from w ww .j a va 2 s . c o m public void testPKColumnAddDefault() throws ParseException { final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='TIMESTAMP' primaryKey='true' required='true'/>\n" + " <column name='avalue' type='INTEGER'/>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='TIMESTAMP' primaryKey='true' required='true' default='2000-01-01 00:00:00'/>\n" + " <column name='avalue' type='INTEGER'/>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Timestamp time = new Timestamp(new Date().getTime()); // some databases (such as MySql) don't store micro-/nanoseconds time.setNanos(0); insertRow("roundtrip", new Object[] { time, new Integer(1) }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); insertRow("roundtrip", new Object[] { null, new Integer(2) }); List beans = getRows("roundtrip", "avalue"); Timestamp defaultTime = Timestamp.valueOf("2000-01-01 00:00:00"); assertEquals(time, beans.get(0), "pk"); assertEquals(new Integer(1), beans.get(0), "avalue"); assertEquals(defaultTime, beans.get(1), "pk"); assertEquals(new Integer(2), beans.get(1), "avalue"); }
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests adding a default value to an indexed column. *//*from w w w . j a va 2 s .c o m*/ public void testIndexColumnAddDefault() { if (!getPlatformInfo().isIndicesSupported()) { return; } final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='INTEGER'/>\n" + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <index name='testindex'>\n" + " <index-column name='avalue1'/>\n" + " <index-column name='avalue2'/>\n" + " </index>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='INTEGER' default='3'/>\n" + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <index name='testindex'>\n" + " <index-column name='avalue1'/>\n" + " <index-column name='avalue2'/>\n" + " </index>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Timestamp time = new Timestamp(new Date().getTime()); // some databases (such as MySql) don't store micro-/nanoseconds time.setNanos(0); insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2), time }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); insertRow("roundtrip", new Object[] { new Integer(2), null, time }); List beans = getRows("roundtrip"); assertEquals(new Integer(1), beans.get(0), "pk"); assertEquals(new Integer(2), beans.get(0), "avalue1"); assertEquals(time, beans.get(0), "avalue2"); assertEquals(new Integer(2), beans.get(1), "pk"); assertEquals(new Integer(3), beans.get(1), "avalue1"); assertEquals(time, beans.get(1), "avalue2"); }
From source file:org.apache.ddlutils.io.TestChangeColumn.java
/** * Tests adding a default value to an indexed column. *//*from w ww .ja va 2s . co m*/ public void testUniqueIndexColumnAddDefault() { if (!getPlatformInfo().isIndicesSupported()) { return; } final String model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='INTEGER'/>\n" + " <column name='avalue2' type='TIMESTAMP'/>\n" + " <unique name='testindex'>\n" + " <unique-column name='avalue1'/>\n" + " <unique-column name='avalue2'/>\n" + " </unique>\n" + " </table>\n" + "</database>"; final String model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n" + " <table name='roundtrip'>\n" + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='avalue1' type='INTEGER'/>\n" + " <column name='avalue2' type='TIMESTAMP' default='2000-01-01 00:00:00'/>\n" + " <unique name='testindex'>\n" + " <unique-column name='avalue1'/>\n" + " <unique-column name='avalue2'/>\n" + " </unique>\n" + " </table>\n" + "</database>"; createDatabase(model1Xml); Timestamp time = new Timestamp(new Date().getTime()); // some databases (such as MySql) don't store micro-/nanoseconds time.setNanos(0); insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2), time }); alterDatabase(model2Xml); assertEquals(getAdjustedModel(), readModelFromDatabase("roundtriptest")); insertRow("roundtrip", new Object[] { new Integer(2), new Integer(3) }); List beans = getRows("roundtrip"); Timestamp defaultTime = Timestamp.valueOf("2000-01-01 00:00:00"); assertEquals(new Integer(1), beans.get(0), "pk"); assertEquals(new Integer(2), beans.get(0), "avalue1"); assertEquals(time, beans.get(0), "avalue2"); assertEquals(new Integer(2), beans.get(1), "pk"); assertEquals(new Integer(3), beans.get(1), "avalue1"); assertEquals(defaultTime, beans.get(1), "avalue2"); }