List of usage examples for java.sql Date Date
public Date(long date)
From source file:cherry.foundation.type.converter.LocalDateConverterTest.java
@Test public void testConvert() { LocalDate now = LocalDate.now(); for (int i = -1024; i <= 1024; i++) { LocalDate ld = now.plusDays(i); Date date = new Date(ld.toDate().getTime()); assertThat(cs.convert(date, LocalDate.class), is(ld)); assertThat(cs.convert(ld, Date.class), is(date)); }//from w w w. ja va2 s.c om }
From source file:org.beanfuse.security.service.GroupServiceImpl.java
public void saveOrUpdate(Group group) throws EntityExistException { group.setUpdatedAt(new Date(System.currentTimeMillis())); if (group.isVO()) { group.setCreatedAt(new Date(System.currentTimeMillis())); }// w ww . ja v a 2 s . co m groupDao.saveOrUpdate(group); }
From source file:com.splicemachine.db.iapi.types.SQLDateTest.java
@Test public void serdeValueData() throws Exception { UnsafeRow row = new UnsafeRow(1); UnsafeRowWriter writer = new UnsafeRowWriter(new BufferHolder(row), 1); Date date = new Date(System.currentTimeMillis()); int computeEncodedDate = SQLDate.computeEncodedDate(date); SQLDate value = new SQLDate(date); SQLDate valueA = new SQLDate(); value.write(writer, 0);//from w w w . j a v a 2 s . c om Assert.assertEquals("SerdeIncorrect", computeEncodedDate, row.getInt(0)); valueA.read(row, 0); Assert.assertEquals("SerdeIncorrect", date.toString(), valueA.getDate(new GregorianCalendar()).toString()); }
From source file:com.impetus.kundera.property.accessor.SQLDateAccessor.java
@Override public Date fromBytes(Class targetClass, byte[] b) { try {//from ww w.j av a2 s . co m if (b == null) { return null; } // In case date.getTime() is stored in DB. LongAccessor longAccessor = new LongAccessor(); return new Date(longAccessor.fromBytes(targetClass, b)); } catch (Exception e) { log.error("Error occured, Caused by {}.", e); throw new PropertyAccessException(e); } }
From source file:fr.xebia.demo.ws.employee.EmployeeServiceImpl.java
@Override public Employee getEmployee(int id) throws EmployeeServiceFaultMsg { Employee employee = new Employee(); employee.setId(id);/* w w w . ja va 2 s . co m*/ employee.setLastName("Doe"); employee.setFirstName("John"); employee.setGender(Gender.MALE); employee.setBirthdate(new Date(new GregorianCalendar(1976, 01, 05).getTimeInMillis())); logger.info("getEmployee(" + id + "): " + ToStringBuilder.reflectionToString(employee)); return employee; }
From source file:cz.fi.muni.pa165.dao.MusicianDaoImplementationTest.java
@BeforeMethod public void setUpClass() { metallica = new Musician(); acdc = new Musician(); avicii = new Musician(); dio = new Musician(); metallica.setRealName("James Hetfield"); metallica.setArtistName("Metallica"); metallica.setDateOfBirth(new Date(123)); acdc.setRealName("Brian Johnson"); acdc.setArtistName("AC-DC"); acdc.setDateOfBirth(new Date(456)); avicii.setRealName("Tim Bergling"); avicii.setArtistName("Avicii"); avicii.setDateOfBirth(new Date(789)); dio.setRealName("Ronnie James Dio"); dio.setArtistName("Dio"); dio.setDateOfBirth(new Date(666)); musicianDao.create(metallica);//from w ww. j a v a 2 s . c o m musicianDao.create(acdc); musicianDao.create(avicii); }
From source file:org.beangle.commons.converters.SqlDateConverter.java
/** * ??<br>//ww w . j a v a 2 s. c o m * format 1: yyyy-MM-dd<br> * format 2: yyyyMMdd * * @param type * @param value * @return */ protected Object convertToDate(final Object value) { if (value instanceof String) { if (StringUtils.isEmpty((String) value)) { return null; } else { String dateStr = (String) value; if (!StringUtils.contains(dateStr, "-")) { StringBuilder dateBuf = new StringBuilder(dateStr); dateBuf.insert("yyyyMM".length(), '-'); dateBuf.insert("yyyy".length(), '-'); dateStr = dateBuf.toString(); } return Date.valueOf(dateStr); } } else if (value instanceof java.util.Date) { return new Date(((java.util.Date) value).getTime()); } else { return null; } }
From source file:org.forumj.dbextreme.db.service.test.user.tests.CreateUserTest.java
private static void prepareUser1() { testUser1.setNick("nick1"); testUser1.setPass("pass1"); testUser1.setEmail("mail"); testUser1.setName("name"); testUser1.setFam("fam"); testUser1.setSex("M"); testUser1.setBith(new Date(new java.util.Date().getTime())); testUser1.setPass2("pass2"); testUser1.setShowMail(true);/*from w ww . j a v a 2 s . c o m*/ testUser1.setShowName(true); testUser1.setCity("city"); testUser1.setShowCity(true); testUser1.setCountry("country"); testUser1.setShowCountry(true); testUser1.setShowSex(true); testUser1.setIcq("icq"); testUser1.setShowIcq(true); testUser1.setShowBithday(true); testUser1.setLanguge(Locale.UA); testUser1.setHideIp(true); testUser1.setView(5); testUser1.setPp(66); testUser1.setPt(77); testUser1.setAvatar("avatar"); testUser1.setShowAvatar(true); testUser1.setAvatarApproved(true); testUser1.setWantSeeAvatars(true); testUser1.setTimeZone(7); testUser1.setFooter("footer"); testUser1.setBan(1); testUser1.setActivateCode(45567678); testUser1.setIsActive(true); }
From source file:com.sapienter.jbilling.server.user.validator.RepeatedPasswordValidator.java
/** * Queries the event_log table to check whether the user has already used * in the past the password he's trying to set now. * @param userId Id of the user whose password is being changed. * @return An array of <code>java.lang.String</code> containing the passwords * recently used by this user./*from www. j av a 2 s. c o m*/ */ private static String[] getPasswords(Integer userId) throws SQLException, NamingException { String[] passw = null; CachedRowSet cachedResults = new CachedRowSet(); JNDILookup jndi = JNDILookup.getFactory(); Connection conn = jndi.lookUpDataSource().getConnection(); cachedResults.setCommand(UserSQL.findUsedPasswords); GregorianCalendar date = new GregorianCalendar(); date.add(GregorianCalendar.YEAR, -2); cachedResults.setDate(1, new Date(date.getTimeInMillis())); cachedResults.setInt(2, userId); cachedResults.execute(conn); List<String> result = new ArrayList<String>(); while (cachedResults.next()) { result.add(cachedResults.getString(1)); } if (!result.isEmpty()) { passw = new String[result.size()]; int index = 0; for (Iterator i = result.iterator(); i.hasNext();) { passw[index] = (String) i.next(); index++; } } conn.close(); return passw; }
From source file:com.job.portal.utils.AbstractDAO.java
public int insert(String query, Object[] values) throws SQLException { int id = -1;/* w w w.ja v a 2s . c o m*/ Object o = null; String type = null; Date d = null; java.util.Date utilDate = null; if (con.isClosed()) { con = new DbConnection().getConnection(); } ps = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); for (int i = 0; i < values.length; i++) { o = values[i]; type = o.getClass().toString(); if (type.contains("String")) { ps.setString(i + 1, (String) o); } else if (type.contains("Integer")) { ps.setInt(i + 1, (Integer) o); } else if (type.contains("Long")) { ps.setLong(i + 1, (Long) o); } else if (type.contains("Date")) { utilDate = (java.util.Date) o; ps.setDate(i + 1, new Date(utilDate.getTime())); } } id = ps.executeUpdate(); closeConnections(); return id; }