List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:com.gs.obevo.db.impl.platforms.oracle.OracleDeployIT.java
License:asdf
private void validateResults(Map<String, Object> map, Integer aId, Integer bId, String stringField, String timestampField, Integer cId) throws Exception { assertEquals(aId, toInteger(map.get("A_ID"))); assertEquals(bId, toInteger(map.get("B_ID"))); assertEquals(stringField, map.get("STRING_FIELD")); Timestamp millis = timestampField == null ? null : Timestamp.valueOf(timestampField); assertEquals(millis, new OracleDbPlatform().getTimestampValue((map.get("TIMESTAMP_FIELD")))); assertEquals(cId, toInteger(map.get("C_ID"))); }
From source file:cc.cicadabear.profile.infrastructure.jdbc.UserRepositoryJdbc.java
@Override public void saveUser(final User user) { final String sql = " insert into user_(guid,archived,create_time,email,password,salt,username,phone) " + " values (?,?,?,?,?,?,?,?) "; this.jdbcTemplate.update(sql, ps -> { ps.setString(1, user.guid());//from www .ja va 2s. co m ps.setBoolean(2, user.archived()); ps.setTimestamp(3, Timestamp.valueOf(user.createTime())); ps.setString(4, user.email()); ps.setString(5, user.password()); ps.setString(6, user.salt()); ps.setString(7, user.username()); ps.setString(8, user.phone()); }); //get user id final Integer id = this.jdbcTemplate.queryForObject("select id from user_ where guid = ?", new Object[] { user.guid() }, Integer.class); //insert privileges for (final Privilege privilege : user.privileges()) { this.jdbcTemplate.update("insert into user_privilege(user_id, privilege) values (?,?)", ps -> { ps.setInt(1, id); ps.setString(2, privilege.name()); }); } }
From source file:com.ebay.erl.mobius.core.model.TupleTest.java
@Test public void test_comparator() { Tuple t1 = new Tuple(); Tuple t2 = new Tuple(); // comparing short t1.put("C1", (byte) 12); t2.put("C1", (byte) 10); assertTrue(t1.compareTo(t2) > 0); assertTrue(t2.compareTo(t1) < 0); // comparing short t1.put("C1", (short) 12); t2.put("C1", (short) 10); assertTrue(t1.compareTo(t2) > 0); assertTrue(t2.compareTo(t1) < 0); // comparing integer t1.put("C1", (int) 10); t2.put("C1", (int) 10); assertTrue(t1.compareTo(t2) == 0);//from w w w .j av a 2 s . c om assertFalse(t2.compareTo(t1) < 0); assertFalse(t1.compareTo(t2) > 0); // comparing long t1.put("C1", 200000000L); t2.put("C1", 300000000L); assertTrue(t1.compareTo(t2) != 0); assertFalse(t1.compareTo(t2) > 0); assertTrue(t1.compareTo(t2) < 0); // comparing float t1.put("C1", 1.2F); t2.put("C1", 1.1F); assertTrue(t1.compareTo(t2) > 0); assertTrue(t2.compareTo(t1) < 0); // comparing double t1.put("C1", 1.7D); t2.put("C1", 1.5D); assertTrue(t1.compareTo(t2) > 0); assertTrue(t2.compareTo(t1) < 0); // comparing string t1.put("C1", "AA"); t2.put("C1", "AB"); assertTrue(t1.compareTo(t2) < 0); assertTrue(t2.compareTo(t1) > 0); // comparing date t1.put("C1", java.sql.Date.valueOf("2011-01-01")); t2.put("C1", java.sql.Date.valueOf("2011-01-02")); assertTrue(t1.compareTo(t2) < 0); assertTrue(t2.compareTo(t1) > 0); // comparing Timestamp Timestamp ts1 = Timestamp.valueOf("2011-12-31 12:30:42"); Timestamp ts2 = Timestamp.valueOf("2011-12-31 12:30:12"); t1.put("C1", ts1); t2.put("C1", ts2); assertTrue(t1.compareTo(t2) > 0); assertTrue(t2.compareTo(t1) < 0); // comparing Time Time tt1 = Time.valueOf("12:30:42"); Time tt2 = Time.valueOf("12:30:12"); t1.put("C1", tt1); t2.put("C1", tt2); assertTrue(t1.compareTo(t2) > 0); assertTrue(t2.compareTo(t1) < 0); // comparing boolean t1.put("C1", true); t2.put("C1", false); assertTrue(t1.compareTo(t2) > 0); assertTrue(t2.compareTo(t1) < 0); // comparing string map CaseInsensitiveTreeMap m1 = new CaseInsensitiveTreeMap(); CaseInsensitiveTreeMap m2 = new CaseInsensitiveTreeMap(); t1.put("C1", m1); t2.put("C1", m2); assertTrue(t1.compareTo(t2) == 0); m1.put("K1", "V1"); assertTrue(t1.compareTo(t2) > 0); // m1 is not empty, m2 is empty m2.put("K1", "V1"); assertTrue(t1.compareTo(t2) == 0);// m1 and m2 both are not empty and same value m1.put("K1", "V2"); assertTrue(t1.compareTo(t2) > 0);// m1 m2 has same key but different value m1.put("K1", "V1"); m1.put("K2", "V2"); assertTrue(t1.compareTo(t2) > 0);// m1 m2 both has same K1 and V1, but m1 has more k-v pair assertTrue(t2.compareTo(t1) < 0); // comparing WritableComparable t1.put("C1", new Text("AC")); t2.put("C1", new Text("AA")); assertTrue(t1.compareTo(t2) > 0); assertTrue(t2.compareTo(t1) < 0); // comparing serializable type t1.put("C1", new BigDecimal(123L)); t2.put("C1", new BigDecimal(456L)); assertTrue(t1.compareTo(t2) < 0); assertTrue(t2.compareTo(t1) > 0); // comparing null type t1.put("C1", this.getNull()); t2.put("C1", new BigDecimal(456L)); assertTrue(t1.compareTo(t2) < 0); assertTrue(t2.compareTo(t1) > 0); t2.put("C1", this.getNull()); assertTrue(t1.compareTo(t2) == 0); // comparing different numerical type t1.put("C1", 1.2F); t2.put("C1", 1); assertTrue(t1.compareTo(t2) > 0); }
From source file:com.fns.grivet.repo.JdbcEntityRepository.java
@Override public void save(Long eid, Attribute attribute, AttributeType attributeType, Object rawValue, LocalDateTime createdTime) { Assert.isTrue(rawValue != null, String .format("Attempt to persist value failed! %s's value must not be null!", attribute.getName())); Object value = ValueHelper.toValue(attributeType, rawValue); String createdBy = getCurrentUsername(); String[] columns = { "eid", "aid", "val", "created_time" }; Map<String, Object> keyValuePairs = ImmutableMap.of("eid", eid, "aid", attribute.getId(), "val", value, "created_time", Timestamp.valueOf(createdTime)); if (createdBy != null) { columns = Arrays.copyOf(columns, columns.length + 1); columns[columns.length - 1] = "created_by"; Map<String, Object> keyValuePairsWithCreatedBy = new HashMap<>(keyValuePairs); keyValuePairsWithCreatedBy.put("created_by", createdBy); keyValuePairs = keyValuePairsWithCreatedBy; }/*from ww w . ja va 2 s . co m*/ new SimpleJdbcInsert(jdbcTemplate).withTableName(String.join("_", "entityav", attributeType.getType())) .usingColumns(columns).execute(keyValuePairs); }
From source file:org.jumpmind.db.sql.Row.java
public Date dateValue() { Object obj = this.values().iterator().next(); if (obj != null) { if (obj instanceof Date) { return (Date) obj; } else {/*from w w w . j ava 2s .co m*/ return Timestamp.valueOf(obj.toString()); } } else { return null; } }
From source file:com.helixleisure.candidates.test.ThriftSerializeDeserializeTest.java
/** * Shows how to serialize one object as a JSON Thrift format. * @throws Exception//from w w w . ja va 2s . c o m */ @Test public void testSerializeAsJSON() throws Exception { ser = new TSerializer(new TJSONProtocol.Factory()); Data data = DataHelper.makeGameplay(12345L, "Snapshot", Timestamp.valueOf("2015-06-01 12:34:12")); assertEquals( "Data(pedigree:Pedigree(timestamp:2015-06-01 12:34:12.0), dataunit:<DataUnit game_play:GamePlayEdge(location:<LocationID location_id:12345>, game:<GameID name:Snapshot>, nonce:1)>)", data.toString()); String expected = "{\"1\":{\"rec\":{\"1\":{\"str\":\"2015-06-01 12:34:12.0\"}}},\"2\":{\"rec\":{\"3\":{\"rec\":{\"1\":{\"rec\":{\"1\":{\"i64\":12345}}},\"2\":{\"rec\":{\"1\":{\"str\":\"Snapshot\"}}},\"3\":{\"i64\":1}}}}}}"; String serialize = new String(ser.serialize(data)); assertEquals(expected, serialize); }
From source file:org.apache.ofbiz.content.cms.ContentJsonEvents.java
public static String moveContent(HttpServletRequest request, HttpServletResponse response) throws GenericEntityException, IOException { final Delegator delegator = (Delegator) request.getAttribute("delegator"); final String contentIdTo = request.getParameter("contentIdTo"); final String contentIdFrom = request.getParameter("contentIdFrom"); final String contentIdFromNew = request.getParameter("contentIdFromNew"); final String contentAssocTypeId = request.getParameter("contentAssocTypeId"); final Timestamp fromDate = Timestamp.valueOf(request.getParameter("fromDate")); final Timestamp now = UtilDateTime.nowTimestamp(); GenericValue assoc = TransactionUtil.inTransaction(new Callable<GenericValue>() { @Override//from w w w . ja v a 2s . c om public GenericValue call() throws Exception { GenericValue oldAssoc = delegator.findOne("ContentAssoc", UtilMisc.toMap("contentIdTo", contentIdTo, "contentId", contentIdFrom, "contentAssocTypeId", contentAssocTypeId, "fromDate", fromDate), false); if (oldAssoc == null) { throw new GenericEntityNotFoundException( "Could not find ContentAssoc by primary key [contentIdTo: $contentIdTo, contentId: $contentIdFrom, contentAssocTypeId: $contentAssocTypeId, fromDate: $fromDate]"); } GenericValue newAssoc = (GenericValue) oldAssoc.clone(); oldAssoc.set("thruDate", now); oldAssoc.store(); newAssoc.set("contentId", contentIdFromNew); newAssoc.set("fromDate", now); newAssoc.set("thruDate", null); delegator.clearCacheLine(delegator.create(newAssoc)); return newAssoc; } }, String.format("move content [%s] from [%s] to [%s]", contentIdTo, contentIdFrom, contentIdFromNew), 0, true).call(); IOUtils.write(JSON.from(getTreeNode(assoc)).toString(), response.getOutputStream()); return "success"; }
From source file:com.zuoxiaolong.blog.cache.service.UserArticleServiceManager.java
/** * ??/* w ww . j a v a 2s. co m*/ * * @param map * @return */ public List<UserArticle> getTopCommendArticles(Map<String, Object> map) { List<UserArticle> userArticles = userArticleService.getTopCommendArticles(map); List<UserArticle> recommendUserArticle = userArticleService .getArticleCommentByCategoryId((Integer) map.get(QUERY_PARAMETER_CATEGORY_ID)); if (CollectionUtils.isEmpty(userArticles) && !CollectionUtils.isEmpty(recommendUserArticle)) { //??DEFAULT_DAYS_BEFORE_PLUS map.put(QUERY_PARAMETER_TIME, Timestamp.valueOf(((Timestamp) map.get(QUERY_PARAMETER_TIME)) .toLocalDateTime().minus(DEFAULT_DAYS_BEFORE_PLUS, ChronoUnit.DAYS))); userArticles = this.getTopReadArticlesByCategoryIdAndTime(map); } return userArticles; }
From source file:org.openhie.openempi.util.DateConverterTest.java
public void testConvertTimestampToString() throws Exception { Timestamp timestamp = Timestamp.valueOf("2005-03-10 01:02:03.4"); String time = (String) converter.convert(String.class, timestamp); assertEquals(DateUtil.getDateTime(DateUtil.getDateTimePattern(), timestamp), time); }
From source file:org.athenasource.framework.unidbi.Datatypes.java
/** * Parses the given value represented in string and returns a proper Java object for the given type. * The class of the object returned is the same as {@link #getClass()}. * @param type the target type./*from w ww .j ava 2s. c o m*/ * @param value the string to be parsed. * @return a proper Java object for the given type. * @see #getClass() */ public static Object parseValue(int type, String value) { if (value == null) { return null; } value = value.trim(); switch (type) { case BOOLEAN: if (value.equals("0") || value.equalsIgnoreCase("false")) { return new Integer(0); // Boolean.FALSE; // internally represented as Integer. } else { return new Integer(1); // Boolean.TRUE; } case TINYINT: /* fall thru */ case SMALLINT: /* fall thru */ case INTEGER: /* fall thru */ return new Integer(value); case BIGINT: return new Long(value); case DECIMAL: return new BigDecimal(value); case REAL: return new Float(value); case DOUBLE: return new Double(value); case TIMESTAMP: return Timestamp.valueOf(value); case CHAR: case NCHAR: case VARCHAR: case NVARCHAR: return value; case CLOB: case NCLOB: return value; // string. case BLOB: throw new UnsupportedOperationException("LOBs are currently not supported yet."); default: throw new UnsupportedOperationException("Invalid type."); } }