Example usage for java.sql Timestamp Timestamp

List of usage examples for java.sql Timestamp Timestamp

Introduction

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

Prototype

public Timestamp(long time) 

Source Link

Document

Constructs a Timestamp object using a milliseconds time value.

Usage

From source file:libepg.epg.section.body.eventinformationtable.EventInformationTableRepeatingPart.java

/**
 * // ww w .ja  v  a  2 s  .c  o m
 *
 * @return ???? 
 * @throws java.text.ParseException ????????????
 */
public synchronized Timestamp getStopTime_Object() throws ParseException {
    try {
        byte[] t = this.getDuration();
        long x = DateTimeFieldConverter.BcdTimeToSecond(t) * 1000;
        x = x + this.getStart_time_Object().getTime();
        return new Timestamp(x);
    } catch (ParseException ex) {
        LOG.warn("????????");
        throw ex;
    }
}

From source file:cn.vlabs.duckling.vwb.service.init.provider.DPageInitProvider.java

private DPage createDpage(final int siteId, final DPagePo dpage) {
    final String sql = "insert into vwb_dpage_content_info "
            + "(siteId,resourceid,version,change_time,content,change_by,title) " + " values(?,?,?,?,?,?,?)";
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(sql);
            int i = 0;
            ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            ps.setInt(++i, siteId);//from w w w. jav a 2 s.  c  om
            ps.setInt(++i, dpage.getResourceId());
            ps.setInt(++i, dpage.getVersion());
            ps.setTimestamp(++i, new Timestamp(dpage.getTime().getTime()));
            ps.setString(++i, dpage.getContent());
            ps.setString(++i, dpage.getCreator());
            ps.setString(++i, dpage.getTitle());
            return ps;
        }
    }, keyHolder);
    dpage.setId(Integer.valueOf(keyHolder.getKey().intValue()));
    return DtoPoConvertor.convertPoToDto(dpage);
}

From source file:kuona.processor.JenkinsProcessor.java

public void collectMetrics(BuildMetrics metrics) {
    try {//from  ww w.  j  a va  2s  .c  o  m
        puts("Updating " + getURI());
        final int[] jobCount = { 0 };
        final int[] buildCount = { 0 };
        Set<String> jobNames = getJobs().keySet();
        jobCount[0] = jobNames.size();
        jobNames.stream().forEach(key -> {
            try {
                JobWithDetails job = getJob(key);
                puts("Updating " + key);
                final List<Build> builds = job.details().getBuilds();

                buildCount[0] += builds.size();

                builds.stream().forEach(buildDetails -> {
                    try {
                        final BuildWithDetails details = buildDetails.details();
                        Timestamp timestamp = new Timestamp(details.getTimestamp());

                        Date buildDate = new Date(timestamp.getTime());

                        int year = buildDate.getYear() + 1900;

                        if (!metrics.activity.containsKey(year)) {
                            metrics.activity.put(year, new int[12]);
                        }

                        int[] yearMap = metrics.activity.get(year);
                        yearMap[buildDate.getMonth()] += 1;

                        if (details.getResult() == null) {
                            metrics.buildCountsByResult.put(BuildResult.UNKNOWN,
                                    metrics.buildCountsByResult.get(BuildResult.UNKNOWN) + 1);
                        } else {
                            metrics.buildCountsByResult.put(details.getResult(),
                                    metrics.buildCountsByResult.get(details.getResult()) + 1);
                        }

                        metrics.byDuration.collect(details.getDuration());
                        final List<Map> actions = details.getActions();
                        actions.stream().filter(action -> action != null).forEach(action -> {
                            if (action.containsKey("causes")) {
                                List<HashMap> causes = (List<HashMap>) action.get("causes");

                                causes.stream().filter(cause -> cause.containsKey("shortDescription"))
                                        .forEach(cause -> {
                                            metrics.triggers.add((String) cause.get("shortDescription"));
                                        });
                            }
                        });
                        metrics.completedBuilds.add(details);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        metrics.dashboardServers.add(new HashMap<String, Object>() {
            {
                MainView serverInfo = getServerInfo();
                put("name", serverInfo.getName());
                put("description", serverInfo.getDescription());
                put("uri", getURI().toString());
                put("jobs", jobCount[0]);
                put("builds", buildCount[0]);
            }
        });

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.luna.common.repository.search.SearchUserRepositoryIT.java

@Test
public void testLteAndGteForDate() throws ParseException {
    int count = 15;
    String dateStr = "2012-01-15 16:59:00";
    String dateStrFrom = "2012-01-15 16:59:00";
    String dateStrEnd = "2012-01-15 16:59:00";
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (int i = 0; i < count; i++) {
        User user = createUser();/*from   ww w.  jav a  2s .com*/
        user.getBaseInfo().setBirthday(new Timestamp(df.parse(dateStr).getTime()));
        userRepository.save(user);
    }
    Map<String, Object> searchParams = new HashMap<String, Object>();
    searchParams.put("baseInfo.birthday_gte", dateStrFrom);
    searchParams.put("baseInfo.birthday_lte", dateStrEnd);
    Searchable search = Searchable.newSearchable(searchParams);
    assertEquals(count, userRepository.count(search));
}

From source file:org.dcache.chimera.H2FsSqlDriver.java

@Override
long createTagInode(int uid, int gid, int mode, byte[] value) {
    final String CREATE_TAG_INODE_WITH_VALUE = "INSERT INTO t_tags_inodes (imode, inlink, iuid, igid, isize, "
            + "ictime, iatime, imtime, ivalue) VALUES (?,1,?,?,?,?,?,?,?)";

    Timestamp now = new Timestamp(System.currentTimeMillis());
    KeyHolder keyHolder = new GeneratedKeyHolder();
    int rc = _jdbc.update(con -> {
        PreparedStatement ps = con.prepareStatement(CREATE_TAG_INODE_WITH_VALUE,
                Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, mode | UnixPermission.S_IFREG);
        ps.setInt(2, uid);/*from w  ww  .ja v a 2s.co  m*/
        ps.setInt(3, gid);
        ps.setLong(4, value.length);
        ps.setTimestamp(5, now);
        ps.setTimestamp(6, now);
        ps.setTimestamp(7, now);
        ps.setBinaryStream(8, new ByteArrayInputStream(value), value.length);
        return ps;
    }, keyHolder);
    if (rc != 1) {
        throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(CREATE_TAG_INODE_WITH_VALUE, 1, rc);
    }
    /* H2 uses weird names for the column with the auto-generated key, so we cannot use the code
     * in the base class.
     */
    return (Long) keyHolder.getKey();
}

From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java

public static Timestamp readTimestamp(ByteBuf in) {
    byte length = in.readByte();
    int year = readInt(in);
    byte month = readByte(in);
    byte date = readByte(in);
    int hour = readByte(in);
    int minute = readByte(in);
    int second = readByte(in);
    if (length == 11) {
        long nanos = readUB4(in) * 1000;
        Calendar cal = getLocalCalendar();
        cal.set(year, --month, date, hour, minute, second);
        Timestamp time = new Timestamp(cal.getTimeInMillis());
        time.setNanos((int) nanos);
        return time;
    } else {//from w w  w. jav  a2s.com
        Calendar cal = getLocalCalendar();
        cal.set(year, --month, date, hour, minute, second);
        return new Timestamp(cal.getTimeInMillis());
    }
}

From source file:cn.afterturn.easypoi.excel.imports.CellValueService.java

/**
 * ??/* w  w  w .  j a  v a2 s. co m*/
 *
 * @param cell
 * @param entity
 * @return
 */
private Object getCellValue(String classFullName, Cell cell, ExcelImportEntity entity) {
    if (cell == null) {
        return "";
    }
    Object result = null;
    if ("class java.util.Date".equals(classFullName) || "class java.sql.Date".equals(classFullName)
            || ("class java.sql.Time").equals(classFullName)
            || ("class java.time.Instant").equals(classFullName)
            || ("class java.time.LocalDate").equals(classFullName)
            || ("class java.time.LocalDateTime").equals(classFullName)
            || ("class java.sql.Timestamp").equals(classFullName)) {
        //FIX: ?yyyyMMdd cell.getDateCellValue() ?
        if (CellType.NUMERIC == cell.getCellType() && DateUtil.isCellDateFormatted(cell)) {
            result = DateUtil.getJavaDate(cell.getNumericCellValue());
        } else {
            String val = "";
            try {
                val = cell.getStringCellValue();
            } catch (Exception e) {
                cell.setCellType(CellType.STRING);
                val = cell.getStringCellValue();
            }

            result = getDateData(entity, val);
            if (result == null) {
                return null;
            }
        }
        if (("class java.time.Instant").equals(classFullName)) {
            result = ((Date) result).toInstant();
        } else if (("class java.time.LocalDate").equals(classFullName)) {
            result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        } else if (("class java.time.LocalDateTime").equals(classFullName)) {
            result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        } else if (("class java.sql.Date").equals(classFullName)) {
            result = new java.sql.Date(((Date) result).getTime());
        } else if (("class java.sql.Time").equals(classFullName)) {
            result = new Time(((Date) result).getTime());
        } else if (("class java.sql.Timestamp").equals(classFullName)) {
            result = new Timestamp(((Date) result).getTime());
        }
    } else {
        switch (cell.getCellType()) {
        case STRING:
            result = cell.getRichStringCellValue() == null ? "" : cell.getRichStringCellValue().getString();
            break;
        case NUMERIC:
            if (DateUtil.isCellDateFormatted(cell)) {
                if ("class java.lang.String".equals(classFullName)) {
                    result = formateDate(entity, cell.getDateCellValue());
                }
            } else {
                result = readNumericCell(cell);
            }
            break;
        case BOOLEAN:
            result = Boolean.toString(cell.getBooleanCellValue());
            break;
        case BLANK:
            break;
        case ERROR:
            break;
        case FORMULA:
            try {
                result = readNumericCell(cell);
            } catch (Exception e1) {
                try {
                    result = cell.getRichStringCellValue() == null ? ""
                            : cell.getRichStringCellValue().getString();
                } catch (Exception e2) {
                    throw new RuntimeException("???", e2);
                }
            }
            break;
        default:
            break;
        }
    }
    return result;
}

From source file:com.luna.common.repository.search.SearchUserRepository2WithRepository2ImpIT.java

@Test
public void testLteAndGteForDate() throws ParseException {
    int count = 15;
    String dateStr = "2012-01-15 16:59:00";
    String dateStrFrom = "2012-01-15 16:59:00";
    String dateStrEnd = "2012-01-15 16:59:00";
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (int i = 0; i < count; i++) {
        User user = createUser();//from w  w  w . ja v  a2  s .c  o m
        user.getBaseInfo().setBirthday(new Timestamp(df.parse(dateStr).getTime()));
        userRepository2.save(user);
    }
    Map<String, Object> searchParams = new HashMap<String, Object>();
    searchParams.put("baseInfo.birthday_gte", dateStrFrom);
    searchParams.put("baseInfo.birthday_lte", dateStrEnd);
    Searchable search = Searchable.newSearchable(searchParams);
    assertEquals(count, userRepository2.count(search));
}

From source file:org.cloudfoundry.identity.uaa.audit.JdbcFailedLoginCountingAuditServiceTests.java

@Test
public void findMethodOnlyReturnsEventsWithinRequestedPeriod() {
    long now = System.currentTimeMillis();
    auditService.log(getAuditEvent(UserAuthenticationFailure, "1", "joe"));
    // Set the created column to one hour past
    template.update("update sec_audit set created=?", new Timestamp(now - 3600 * 1000));
    auditService.log(getAuditEvent(UserAuthenticationFailure, "1", "joe"));
    auditService.log(getAuditEvent(UserAuthenticationFailure, "2", "joe"));
    // Find events within last 2 mins
    List<AuditEvent> events = auditService.find("1", now - 120 * 1000);
    assertEquals(1, events.size());/*from w  w  w.java2  s .co m*/
}