Example usage for java.sql Date Date

List of usage examples for java.sql Date Date

Introduction

In this page you can find the example usage for java.sql Date Date.

Prototype

public Date(long date) 

Source Link

Document

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Usage

From source file:org.forumj.dbextreme.db.service.test.user.tests.UpdateUserTest.java

private static void prepareUser2(Long id) {
    testUser2.setId(id);/*from  w  ww .  j  a  v  a  2  s  .  com*/
    testUser2.setNick("nick2");
    testUser2.setPass("pass11112");
    testUser2.setEmail("mail2");
    testUser2.setName("name");
    testUser2.setFam("fam");
    testUser2.setSex("M");
    testUser2.setBith(new Date(new java.util.Date().getTime()));
    testUser2.setPass2("pass2");
    testUser2.setShowMail(false);
    testUser2.setShowName(false);
    testUser2.setCity("city");
    testUser2.setShowCity(false);
    testUser2.setCountry("country");
    testUser2.setShowCountry(false);
    testUser2.setShowSex(false);
    testUser2.setIcq("icq");
    testUser2.setShowIcq(false);
    testUser2.setShowBithday(false);
    testUser2.setLanguge(Locale.RU);
    testUser2.setHideIp(false);
    testUser2.setView(6);
    testUser2.setPp(66);
    testUser2.setPt(77);
    testUser2.setAvatar("avatar");
    testUser2.setShowAvatar(false);
    testUser2.setAvatarApproved(false);
    testUser2.setWantSeeAvatars(false);
    testUser2.setTimeZone(7);
    testUser2.setFooter("footer");
    testUser2.setBan(0);
    testUser2.setActivateCode(45567678);
    testUser2.setIsActive(false);
}

From source file:su90.mybatisdemo.dao.Job_HistoryMapperTest.java

@Test(groups = { "find" })
public void testFindById02() {
    try {/*from   w ww .j  av a 2s.c o m*/
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        Employee searchemp = new Employee();
        searchemp.setId(200L);
        java.util.Date start_util_date = formatter.parse("20020701");
        Job_History result = job_HistoryMapper.findByIdObj(searchemp, new Date(start_util_date.getTime()));
        assertNotNull(result);
    } catch (ParseException ex) {
        assertTrue(false);
    }
}

From source file:org.kepler.objectmanager.cache.CacheContent.java

public void populate(KeplerLSID lsid, Statement stmt) throws Exception {

    String query = "SELECT NAME,LSID,DATE,FILE,TYPE,CLASSNAME FROM " + CacheManager.CACHETABLENAME
            + " WHERE LSID = '" + lsid.toString() + "'";
    if (isDebugging)
        log.debug(query);//from w  w w  .j a v  a 2s . com
    ResultSet rs = stmt.executeQuery(query);
    if (rs == null)
        throw new SQLException("Query Failed: " + query);
    if (rs.next()) {
        String name = rs.getString(1);
        String lsidStr = rs.getString(2);
        Long d = rs.getLong(3);
        String file = rs.getString(4);
        String type = rs.getString(5);
        String className = rs.getString(6);

        setName(name);
        setLsid(new KeplerLSID(lsidStr));
        setDateChanged(new Date(d));
        setFile(new File(file));
        setType(type);
        setClassName(className);
    } else {
        throw new SQLException(lsid + " was not found in " + CacheManager.CACHETABLENAME);
    }
    rs.close();

}

From source file:fr.xebia.demo.ws.employee.EmployeeServiceIntegrationTest.java

@Test
public void testPutEmployee() throws Exception {
    int id = random.nextInt();

    Employee employee = new Employee();
    employee.setId(null);//from ww w  . j  a  v  a  2s  . c  o m
    employee.setLastName("Doe-" + id);
    employee.setFirstName("John");
    employee.setGender(Gender.MALE);
    employee.setBirthdate(new Date(new GregorianCalendar(1976, 01, 05).getTimeInMillis()));

    employeeService.putEmployee(new Holder<Employee>(employee));
    System.out.println(ToStringBuilder.reflectionToString(employee));

}

From source file:edu.ku.kuali.kra.negotiations.service.NegotiationServiceImpl.java

@Override
public List<NegotiationActivityHistoryLineBean> getNegotiationActivityHistoryLineBeans(
        List<NegotiationActivity> activities) {
    List<NegotiationActivityHistoryLineBean> beans = new ArrayList<NegotiationActivityHistoryLineBean>();
    for (NegotiationActivity activity : activities) {
        if (activity.getLocation() != null && activity.getActivityType() != null) {
            NegotiationActivityHistoryLineBean bean = new NegotiationActivityHistoryLineBean(activity);
            beans.add(bean);//from w ww. j a v a2  s . c om
        }
    }
    Collections.sort(beans);

    // now set the effective dates and calculate the location days.
    Date previousStartDate = null;
    Date previousEndDate = null;
    String previousLocation = "";
    int counter = 1;
    List<NegotiationActivityHistoryLineBean> beansToReturn = new ArrayList<NegotiationActivityHistoryLineBean>();
    for (NegotiationActivityHistoryLineBean bean : beans) {
        if (StringUtils.equals(previousLocation, bean.getLocation())) {
            if (isDateBetween(bean.getStartDate(), previousStartDate, previousEndDate)
                    && isDateBetween(bean.getEndDate(), previousStartDate, previousEndDate)) {
                // current date range lies within the previous date range
                setBeanStuff(bean, null, null, "0 Days");
                // leave previous alone
            } else if (isDateBetween(bean.getStartDate(), previousStartDate, previousEndDate)
                    && (bean.getEndDate() != null) && bean.getEndDate().after(previousEndDate)) {
                // current date range starts within the previous range, but
                // finishes past it.
                Date previousEndDatePlusOneDay = new Date(
                        previousEndDate.getTime() + NegotiationActivity.MILLISECS_PER_DAY);
                previousEndDate = bean.getEndDate();
                setBeanStuff(bean, previousEndDatePlusOneDay, bean.getEndDate(),
                        NegotiationActivity.getNumberOfDays(previousEndDatePlusOneDay, bean.getEndDate()));
            } else {
                // completely separate range.
                previousStartDate = bean.getStartDate();
                previousEndDate = bean.getEndDate();
                setBeanStuff(bean, bean.getStartDate(), bean.getEndDate(),
                        NegotiationActivity.getNumberOfDays(bean.getStartDate(), bean.getEndDate()));
            }
        } else {
            // new location so set the effective date
            previousStartDate = bean.getStartDate();
            previousEndDate = bean.getEndDate();
            previousLocation = bean.getLocation();
            setBeanStuff(bean, bean.getStartDate(), bean.getEndDate(),
                    NegotiationActivity.getNumberOfDays(bean.getStartDate(), bean.getEndDate()));

            // BUKC-0150: Negotiation - Line skip on Activity/Location History page (Neg. QA Testing Issue 13)
            /*
             * if (!beansToReturn.isEmpty()) {
             * beansToReturn.add(new NegotiationActivityHistoryLineBean());
             * }
             */
        }
        bean.setLineNumber(String.valueOf(counter));
        beansToReturn.add(bean);
        counter++;
    }
    return beansToReturn;
}

From source file:com.seajas.search.utilities.logging.SearchLogger.java

/**
 * Default constructor.// w  w  w  .  j av a  2s . c o  m
 * 
 * @param name
 * @param level
 * @param dataSource
 * @param loggingDAO
 */
public SearchLogger(final String name, final String level, final BasicDataSource dataSource,
        final LoggingDAO loggingDAO) {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    // Create the actual logger

    Logger logger = (Logger) LoggerFactory.getLogger(name);

    logger.setLevel(Level.toLevel(level));
    logger.setAdditive(true);

    // Create the logging appender

    AppenderBase<ILoggingEvent> appender = new AppenderBase<ILoggingEvent>() {
        @Override
        protected void append(final ILoggingEvent event) {
            Connection connection = null;

            PreparedStatement statement = null;

            try {
                connection = dataSource.getConnection();

                statement = connection.prepareStatement(JDBC_INSERT);

                statement.setString(1, event.getLevel().toString());
                statement.setString(2, event.getFormattedMessage());
                statement.setDate(3, new Date(event.getTimeStamp()));

                statement.executeUpdate();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (statement != null)
                        statement.close();
                    if (connection != null)
                        connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    };

    appender.setContext(loggerContext);

    appender.start();

    // Make this the definitive logger

    logger.addAppender(appender);

    this.logger = logger;
}

From source file:tools.xor.logic.DefaultJson.java

protected void checkDateField() throws JSONException {
    // create person
    JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
    jsonBuilder.add("name", "DILIP_DALTON");
    jsonBuilder.add("displayName", "Dilip Dalton");
    jsonBuilder.add("description", "Software engineer in the bay area");
    jsonBuilder.add("userName", "daltond");

    // 1/1/15 7:00 PM EST
    final long CREATED_ON = 1420156800000L;
    Date createdOn = new Date(CREATED_ON);
    DateFormat df = new SimpleDateFormat(ImmutableJsonProperty.ISO8601_FORMAT);
    jsonBuilder.add("createdOn", df.format(createdOn));

    Settings settings = new Settings();
    settings.setEntityClass(Person.class);
    Person person = (Person) aggregateService.create(jsonBuilder.build(), settings);
    assert (person.getId() != null);
    assert (person.getName().equals("DILIP_DALTON"));
    assert (person.getCreatedOn().getTime() == CREATED_ON);

    Object jsonObject = aggregateService.read(person, settings);
    JsonObject json = (JsonObject) jsonObject;
    System.out.println("JSON string: " + json.toString());
    assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON"));
    assert (((JsonString) json.get("createdOn")).getString().equals("2015-01-01T16:00:00.000-0800"));
}

From source file:org.forumj.dbextreme.db.service.test.user.tests.CreateUserTest.java

private static void prepareUser2() {
    testUser2.setNick("nick2");
    testUser2.setPass("pass11112");
    testUser2.setEmail("mail2");
    testUser2.setName("name");
    testUser2.setFam("fam");
    testUser2.setSex("M");
    testUser2.setBith(new Date(new java.util.Date().getTime()));
    testUser2.setPass2("pass2");
    testUser2.setShowMail(false);//from ww w .j  a v  a2  s.  c o m
    testUser2.setShowName(false);
    testUser2.setCity("city");
    testUser2.setShowCity(false);
    testUser2.setCountry("country");
    testUser2.setShowCountry(false);
    testUser2.setShowSex(false);
    testUser2.setIcq("icq");
    testUser2.setShowIcq(false);
    testUser2.setShowBithday(false);
    testUser2.setLanguge(Locale.RU);
    testUser2.setHideIp(false);
    testUser2.setView(6);
    testUser2.setPp(66);
    testUser2.setPt(77);
    testUser2.setAvatar("avatar");
    testUser2.setShowAvatar(false);
    testUser2.setAvatarApproved(false);
    testUser2.setWantSeeAvatars(false);
    testUser2.setTimeZone(7);
    testUser2.setFooter("footer");
    testUser2.setBan(0);
    testUser2.setActivateCode(45567678);
    testUser2.setIsActive(false);
}

From source file:com.iscas.rent.rest.TaskRestController.java

@RequestMapping(value = "data", method = RequestMethod.POST, produces = MediaTypes.JSON_UTF_8)
public String send(@RequestParam(value = "id") Long toid, @RequestParam(value = "content") String content,
        @RequestParam(value = "sign_key", defaultValue = "1") int sign_key,
        @RequestParam(value = "time") Long timestamp, Model model) throws JSONException {

    JSONObject data = new JSONObject();
    Date time = new Date(timestamp);
    data.put("id", toid);
    data.put("conent", content);
    data.put("sign_key", sign_key);
    data.put("time", time);
    ImMsg imMsg = new ImMsg();
    imMsg.setFromid(getCurrentUserId());
    imMsg.setToid(toid);/*from   www . j  a v  a2 s .c  o m*/
    imMsg.setBody(content);
    imMsg.setTime(time);
    imMsg.setStatus((short) 0);
    imMsgService.saveImMsg(imMsg);
    return data.toString();
}

From source file:org.apache.phoenix.end2end.index.IndexMaintenanceIT.java

/**
 * Adds a row to the index data table/*from   w  w w  . j  a  v a2  s  . c om*/
 * 
 * @param i
 *            row number
 */
private void insertRow(PreparedStatement stmt, int i) throws SQLException {
    // insert row
    stmt.setString(1, "varchar" + String.valueOf(i));
    stmt.setString(2, "char" + String.valueOf(i));
    stmt.setInt(3, i);
    stmt.setLong(4, i);
    stmt.setBigDecimal(5, new BigDecimal(i * 0.5d));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY);
    stmt.setDate(6, date);
    stmt.setString(7, "a.varchar" + String.valueOf(i));
    stmt.setString(8, "a.char" + String.valueOf(i));
    stmt.setInt(9, i);
    stmt.setLong(10, i);
    stmt.setBigDecimal(11, new BigDecimal(i * 0.5d));
    stmt.setDate(12, date);
    stmt.setString(13, "b.varchar" + String.valueOf(i));
    stmt.setString(14, "b.char" + String.valueOf(i));
    stmt.setInt(15, i);
    stmt.setLong(16, i);
    stmt.setBigDecimal(17, new BigDecimal(i * 0.5d));
    stmt.setDate(18, date);
    stmt.executeUpdate();
}