Example usage for java.sql Timestamp from

List of usage examples for java.sql Timestamp from

Introduction

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

Prototype

public static Timestamp from(Instant instant) 

Source Link

Document

Obtains an instance of Timestamp from an Instant object.

Usage

From source file:Main.java

public static Timestamp timeZoneAdjustedDate(LocalDateTime due) {
    return Timestamp.from(due.toInstant(ZoneOffset.ofHours(0)));
}

From source file:com.fluke.realtime.data.RediffParser.java

public void fillData() {
    Timestamp lastUpdated = dao.getLastTimeStamp(name);
    Timestamp currentTime = Timestamp.from(Calendar.getInstance().toInstant());
    int lastMins = lastUpdated != null ? Util.getMinutes(Date.from(lastUpdated.toInstant())) : ((9 * 60) + 15);
    int currentMins = Util.getMinutes(Date.from(currentTime.toInstant()));
    if (currentMins - lastMins < 4) {
        //lost data of less than 4 mins. no need to process further
        return;/*from ww  w  .jav  a2  s .c om*/
    }
    YahooIntradayParser parser = new YahooIntradayParser();
    IntradayDetails data = parser.getIntradayDetails(name);
    fillOldData(data);
}

From source file:echange.service.EnvoieMessageService.java

public void envoieMessage(Long idEmetteur, Long idDestinataire, String titre, String msg)
        throws ExceptionUtilisateurInexistant {
    // Dclaration des Exceptions si l'utilisateur ou l'emetteur sont inexistants
    if (utilisateurService.exists(idEmetteur) == false) {
        throw new ExceptionUtilisateurInexistant();
    }// w w  w. j  a  v a 2s.com
    if (utilisateurService.exists(idDestinataire) == false) {
        throw new ExceptionUtilisateurInexistant();
    }
    //Rcupration des emetteur et recepteur
    Utilisateur emetteur = utilisateurService.findOne(idEmetteur);
    Utilisateur destinataire = utilisateurService.findOne(idDestinataire);
    //Cration et Edition des attributs du messages
    Message m = new Message();
    m.setEmeteurMessage(emetteur);
    m.setDestinataireMessage(destinataire);
    m.setTitre(titre);
    m.setContenu(msg);
    m.setLu(false);
    Timestamp date;
    date = Timestamp.from(Instant.now());
    m.setDateCreation(date);
    //Enregistrement du message
    messageService.save(m);
}

From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java

public static Timestamp getTimestamp(final ZonedDateTime date) {
    return date != null ? Timestamp.from(date.toInstant()) : null;
}

From source file:br.ufac.sion.service.AuditoriaService.java

public Set<AuditoriaDTO> findAllRevisions(FiltroAuditoria filtro) throws NegocioException {
    if (filtro.getDataInicio() != null && filtro.getDataFim() != null) {
        if (!filtro.getDataFim().isAfter(filtro.getDataInicio())) {
            throw new NegocioException("A data de termino deve ser maior que a data de incio!");
        }//from   w w  w .  ja v  a  2 s .c  om
    }
    Set<AuditoriaDTO> dtos = new HashSet<>();

    AuditReader reader = AuditReaderFactory.get(em);

    AuditQuery query = reader.createQuery().forRevisionsOfEntity(filtro.getClasse(), false, true);

    if (filtro.getDataInicio() != null) {
        query.add(AuditEntity.revisionProperty("timestamp")
                .gt(Timestamp.from(filtro.getDataInicio().toInstant(ZoneOffset.UTC)).getTime()));
    }
    if (filtro.getDataFim() != null) {
        query.add(AuditEntity.revisionProperty("timestamp")
                .lt(Timestamp.from(filtro.getDataFim().toInstant(ZoneOffset.UTC)).getTime()));
    }

    if (StringUtils.isNotEmpty(filtro.getLogin())) {
        query.add(AuditEntity.revisionProperty("username").ilike(filtro.getLogin(), MatchMode.EXACT));
    }

    if (filtro.getTiposRevisao().length > 0) {
        System.out.println("entra id tipo revisao");
        query.add(AuditEntity.property("REVTYPE").in(filtro.getTiposRevisao()));
    }

    List<Object[]> result = query.getResultList();

    for (Object[] o : result) {
        try {
            //                Object instancia = filtro.getClass().cast(o[0]);
            Object instancia = Class.forName(filtro.getClasse().getName()).cast(o[0]);
            //                Method metodo;
            //                metodo = instancia.getClass().getMethod("getId");
            //                Long id = (Long) metodo.invoke(instancia);

            CustomRevisionEntity revision = (CustomRevisionEntity) o[1];
            RevisionType revisionType = (RevisionType) o[2];

            Instant instant = Instant.ofEpochMilli(revision.getTimestamp());

            AuditoriaDTO dto = new AuditoriaDTO(instancia, revisionType, filtro.getEntidade(), revision);

            dtos.add(dto);
        } catch (Exception ex) {
            throw new NegocioException(ex.getMessage());
        }
    }
    return dtos;
}

From source file:org.ulyssis.ipp.snapshot.Event.java

public static List<Event> loadFrom(Connection connection, Instant time) throws SQLException, IOException {
    String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" "
            + "WHERE \"time\" >= ? ORDER BY \"time\" ASC, \"id\" ASC";
    List<Event> events = new ArrayList<>();
    try (PreparedStatement stmt = connection.prepareStatement(statement)) {
        stmt.setTimestamp(1, Timestamp.from(time));
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            String evString = rs.getString("data");
            Event event = Serialization.getJsonMapper().readValue(evString, Event.class);
            event.id = rs.getLong("id");
            event.removed = rs.getBoolean("removed");
            events.add(event);/*from   w w w. j a v a 2 s.co  m*/
        }
    }
    return events;
}

From source file:com.khartec.waltz.data.application.ApplicationDao.java

public AppRegistrationResponse registerApp(AppRegistrationRequest request) {

    checkNotEmptyString(request.name(), "Cannot register app with no name");

    LOG.info("Registering new application: " + request);

    ApplicationRecord record = dsl.newRecord(APPLICATION);

    record.setName(request.name());/*  w  w w . j a  va 2  s  . c  om*/
    record.setDescription(request.description().orElse("TBC"));
    record.setAssetCode(request.assetCode().orElse(""));
    record.setParentAssetCode(request.parentAssetCode().orElse(""));
    record.setOrganisationalUnitId(request.organisationalUnitId());
    record.setKind(request.kind().name());
    record.setLifecyclePhase(request.lifecyclePhase().name());
    record.setOverallRating(request.overallRating().name());
    record.setUpdatedAt(Timestamp.from(Instant.now()));

    try {
        int count = record.insert();

        if (count == 1) {
            return ImmutableAppRegistrationResponse.builder().id(record.getId()).message("created")
                    .originalRequest(request).build();
        } else {
            return ImmutableAppRegistrationResponse.builder().message("Failed").originalRequest(request)
                    .build();
        }

    } catch (DataAccessException dae) {
        return ImmutableAppRegistrationResponse.builder()
                .message("Could not create app because: " + dae.getMessage()).originalRequest(request).build();
    }
}

From source file:org.ulyssis.ipp.snapshot.Snapshot.java

public static Optional<Snapshot> loadBefore(Connection connection, Instant time)
        throws SQLException, IOException {
    String statement = "SELECT \"id\", \"data\", \"event\" FROM \"snapshots\" "
            + "WHERE \"time\" < ? ORDER BY \"time\" DESC, \"event\" DESC FETCH FIRST ROW ONLY";
    try (PreparedStatement stmt = connection.prepareStatement(statement)) {
        stmt.setTimestamp(1, Timestamp.from(time));
        LOG.debug("Executing query: {}", stmt);
        ResultSet rs = stmt.executeQuery();
        if (rs.next()) {
            String data = rs.getString("data");
            Snapshot result = Serialization.getJsonMapper().readValue(data, Snapshot.class);
            result.id = rs.getLong("id");
            result.eventId = rs.getLong("event");
            return Optional.of(result);
        } else {/*from w  w w .jav  a2s.com*/
            return Optional.empty();
        }
    }
}

From source file:org.ulyssis.ipp.snapshot.Event.java

public static List<Event> loadAfter(Connection connection, Instant time, long id)
        throws SQLException, IOException {
    String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" "
            + "WHERE \"time\" > ? OR (\"time\" = ? AND \"id\" > ?) ORDER BY \"time\" ASC, \"id\" ASC";
    List<Event> events = new ArrayList<>();
    try (PreparedStatement stmt = connection.prepareStatement(statement)) {
        stmt.setTimestamp(1, Timestamp.from(time));
        stmt.setTimestamp(2, Timestamp.from(time));
        stmt.setLong(3, id);//from   ww  w.j  a  v a  2s. c  o  m
        LOG.debug("Executing query: {}", stmt);
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            String evString = rs.getString("data");
            Event event = Serialization.getJsonMapper().readValue(evString, Event.class);
            event.id = rs.getLong("id");
            event.removed = rs.getBoolean("removed");
            events.add(event);
        }
    }
    LOG.debug("Loaded {} events", events.size());
    return events;
}

From source file:com.fluke.realtime.data.RediffParser.java

private void finalTicker(RediffData rediff) {
    IntradayTicker third = getTicker(rediff, two);
    IntradayTicker last = new IntradayTicker();
    last.setOpenPrice(one.getOpenPrice());
    last.setClosePrice(third.getClosePrice());
    float high = (float) Arrays.asList(one, two, third).stream().mapToDouble(t -> t.getHighPrice()).max()
            .getAsDouble();/*from  www. j a va 2 s. c  om*/
    float low = (float) Arrays.asList(one, two, third).stream().mapToDouble(t -> t.getLowPrice()).min()
            .getAsDouble();
    last.setHighPrice(high);
    last.setLowPrice(low);
    last.setTime(Timestamp.from(Calendar.getInstance().toInstant()));
    last.setVolume(one.getVolume() + two.getVolume() + third.getVolume());
    insert(last);
    lastTicker = last;
}