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:com.th.jbp.backend.service.TrailerHeadService.java

@Override
public ObjectResult<TrailerHeadM> delete(TrailerHeadM entity) {
    ObjectResult<TrailerHeadM> result = new ObjectResult<>();
    if (entity == null || entity.getTrailerHeadId() == null || entity.getTrailerHeadId().equals(0L)) {
        result = new ObjectResult<>(ObjectResult.FAIL);
        result.setDetail("entity or id is null.");
    } else {//from  w  ww  .  j  ava  2  s.  c o  m
        ClassifierValueM status = classifierValueRepository.findOne(Status.DELETED.getId());
        entity.setStatus(status);
        entity.setUpdateDate(new Timestamp(System.currentTimeMillis()));
        repository.saveAndFlush(entity);
        result = new ObjectResult<>(ObjectResult.SUCCESS, entity);
    }
    return result;
}

From source file:com.leixl.easyframework.system.service.impl.EUserServiceImpl.java

public void updateLoginInfo(Long userId, String ip) {
    Date now = new Timestamp(System.currentTimeMillis());
    EUser user = findById(userId);/*w  w w. j ava 2 s. c o m*/
    if (user != null) {
        user.setLoginCount(user.getLoginCount() + 1);
        user.setLastLoginIp(ip);
        user.setLastLoginTime(now);
    }
}

From source file:javasnack.cli.CliDbUnitCsvExportDemo.java

void setup(Connection conn) throws Exception {

    new T1().setup(conn);
    Calendar c = Calendar.getInstance();

    c.clear();//from  www  .  j  a  va 2s . co  m
    c.set(2000, 11, 31, 23, 59, 59);
    long insertTIM = c.getTimeInMillis();
    new T1(true, 10, new BigDecimal(20), 30.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \"World\"!").insertMe(conn);

    c.clear();
    c.set(2001, 0, 1, 12, 30, 15);
    insertTIM = c.getTimeInMillis();
    new T1(false, 20, new BigDecimal(30), 40.0, new Time(insertTIM), new Date(insertTIM),
            new Timestamp(insertTIM), "'Hello', \n\"World\"!").insertMe(conn);

    new T2().setup(conn);
    new T2(UnsignedByte.create0x00to0xFFString(), UnsignedByte.create0x00to0xFF(),
            UnsignedByte.create0x00to0xFF()).insertMe(conn);
}

From source file:com.ex.dao.impl.TestGroupDaoImpl.java

public void testsaveGroup() {
    Group newGroup = new Group();
    XStream xstream1 = new XStream();
    newGroup.setId("GRP_2");
    newGroup.setVersion(0l);//from w w w  .ja v  a  2  s  .  c  o  m
    newGroup.setGroupName("SecondGroup");
    newGroup.setCreatedBy("Jane Doe");
    newGroup.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
    String xml = xstream1.toXML(newGroup);
    newGroup.setXml(xml);
    groupDao.saveGroup(newGroup);
    Group savedGroup = groupDao.findGroupByName("SecondGroup");
    Assert.assertEquals("Jane Doe", savedGroup.getCreatedBy());
    Assert.assertEquals("GRP_2", savedGroup.getId());
    return;
}

From source file:pdfjsannotator.controller.AnnotationController.java

@RequestMapping(value = "/api/annotations", method = RequestMethod.POST)
public Annotation create(@RequestBody Annotation annotation) {
    LOGGER.info("Requested creation of annotation: " + annotation.toString());
    if (annotation.getId() == null) {
        annotation.setId(UUID.randomUUID().toString());
        Timestamp ts = new Timestamp(Calendar.getInstance().getTimeInMillis());
        annotation.setCreated(ts);/*from   w  w w. j a  va 2  s.c om*/
        annotation.setUpdated(ts);
        annotation.setUser("Guest");
        annotation.setConsumer("pdfjs-annotator");
        annotation.setAnnotator_schema_version("v1.0");
    }
    return annotationRepository.save(annotation);
}

From source file:ltistarter.model.LtiUserEntity.java

/**
 * @param userKey user identifier/*  w  w w  .  ja  v a2s  . com*/
 * @param loginAt date of user login
 */
public LtiUserEntity(String userKey, Date loginAt) {
    assert StringUtils.isNotBlank(userKey);
    if (loginAt == null) {
        loginAt = new Date();
    }
    this.userKey = userKey;
    this.userSha256 = makeSHA256(userKey);
    this.loginAt = new Timestamp(loginAt.getTime());
}

From source file:daos.BetalingDaoTest.java

@Test
public void testCreateBetaling() {
    LOG.info("createBetalingTest");

    testBetaling.setBetaalDatum(new Timestamp(date.getTime()));
    testBetaling.setBetaalwijze(bw);/*from ww  w .  j a v  a  2  s .  c  o m*/
    testBetaling.setKlant(klant);
    testBetaling.setFactuur(f1);
    instance.createEntity(testBetaling);
    assertTrue(((Betaling) instance.readEntity(1)).getIdBetaling() > 0);
}

From source file:com.adanac.module.blog.dao.MessageDao.java

public Integer save(final String visitorIp, final Date createDate, final String message, final String username,
        final Integer referenceMessageId) {
    return execute(new TransactionalOperation<Integer>() {
        @Override/*from w w  w  .j a  v  a 2  s. c  o m*/
        public Integer doInConnection(Connection connection) {
            try {
                PreparedStatement statement = null;
                if (referenceMessageId == null) {
                    statement = connection.prepareStatement(
                            "insert into messages (visitor_ip,city,message,"
                                    + "create_date,username) values (?,?,?,?,?)",
                            Statement.RETURN_GENERATED_KEYS);
                } else {
                    statement = connection.prepareStatement(
                            "insert into messages (visitor_ip,city,message,"
                                    + "create_date,username,reference_message_id) values (?,?,?,?,?,?)",
                            Statement.RETURN_GENERATED_KEYS);
                }
                statement.setString(1, visitorIp);
                statement.setString(2,
                        Configuration.isProductEnv() ? HttpApiHelper.getCity(visitorIp) : "?");
                statement.setString(3, message);
                Date finalCommentDate = createDate;
                if (createDate == null) {
                    finalCommentDate = new Date();
                }
                statement.setTimestamp(4, new Timestamp(finalCommentDate.getTime()));
                statement.setString(5, username);
                if (referenceMessageId != null) {
                    statement.setInt(6, referenceMessageId);
                }
                int result = statement.executeUpdate();
                if (result > 0) {
                    ResultSet resultSet = statement.getGeneratedKeys();
                    if (resultSet.next()) {
                        return resultSet.getInt(1);
                    }
                }
            } catch (SQLException e) {
                error("save messages failed ...", e);
            }
            return null;
        }
    });
}

From source file:dsd.dao.CalculatedDataDAO.java

public static ArrayList<CalculatedData> GetAllForPeriod(Calendar startDate, Calendar endDate,
        eCalculatedDataType dataType) {//from  w w  w.ja  v a2 s  .com
    try {
        Connection con = DAOProvider.getDataSource().getConnection();
        ArrayList<CalculatedData> calculatedDataList = new ArrayList<CalculatedData>();
        try {
            String tableName = GetTableNameForDataType(dataType);
            Object[] parameters = new Object[2];
            parameters[0] = new Timestamp(startDate.getTimeInMillis());
            parameters[1] = new Timestamp(endDate.getTimeInMillis());
            ResultSet results = DAOProvider.SelectTableSecure(tableName, "*",
                    " timestamp >= ? and timestamp <= ? ", "", con, parameters);
            while (results.next()) {
                CalculatedData dataTuple = new CalculatedData();
                dataTuple.setCalulcatedDataID(results.getLong("ID"));
                dataTuple.setWindSpeed(results.getFloat(fields[0]));
                dataTuple.setWindDirection(results.getFloat(fields[1]));
                dataTuple.setWindSpeedMax(results.getFloat(fields[2]));
                dataTuple.setWindDirectionMax(results.getFloat(fields[3]));
                dataTuple.setHydrometer(results.getFloat(fields[4]));
                dataTuple.setHydrometerVariance(results.getFloat(fields[5]));
                dataTuple.setSonar(results.getFloat(fields[6]));
                dataTuple.setSonarVariance(results.getFloat(fields[7]));
                dataTuple.setSonarPercCorrect(results.getFloat(fields[8]));
                dataTuple.setSonarPercWrong(results.getFloat(fields[9]));
                dataTuple.setSonarPercOutOfWater(results.getFloat(fields[10]));
                dataTuple.setSonarPercError(results.getFloat(fields[11]));
                dataTuple.setSonarPercUncertain(results.getFloat(fields[12]));
                dataTuple.setSafetyFactor00(results.getFloat(fields[13]));
                dataTuple.setSafetyFactor01(results.getFloat(fields[14]));
                dataTuple.setSafetyFactor10(results.getFloat(fields[15]));
                dataTuple.setSafetyFactor11(results.getFloat(fields[16]));
                dataTuple.setWaterSpeed(results.getFloat(fields[17]));
                dataTuple.setWaterFlowRate(results.getFloat(fields[18]));
                dataTuple.setTimestamp(results.getTimestamp(fields[19]).getTime());
                calculatedDataList.add(dataTuple);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
        return calculatedDataList;
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return null;

}

From source file:edu.ucla.loni.server.Upload.java

/**
 *  Writes a file//from  ww  w  .  j  a va2  s . c om
 */
private void writeFile(Directory root, String packageName, InputStream in) throws Exception {
    Document doc = ServerUtils.readXML(in);
    Pipefile pipe = ServerUtils.parseXML(doc);

    // Update the packageName
    if (packageName != null && packageName.length() > 0) {
        pipe.packageName = packageName;
        doc = ServerUtils.updateXML(doc, pipe);
    }

    // Write the document
    String destPath = ServerUtils.newAbsolutePath(root.absolutePath, pipe.packageName, pipe.type, pipe.name);
    File dest = new File(destPath);

    // Create parent folders if needed
    File destDir = dest.getParentFile();
    if (destDir.exists() == false) {
        boolean success = destDir.mkdirs();
        if (!success) {
            throw new Exception("Destination folders could not be created");
        }
    }

    ServerUtils.writeXML(dest, doc);
    pipe.absolutePath = destPath;
    pipe.lastModified = new Timestamp(dest.lastModified());
    Database.insertPipefile(root.dirId, pipe);
}