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.yoncabt.ebr.logger.db.BaseDBReportLogger.java

@Override
public void logReport(ReportRequest request, ReportOutputFormat outputFormat, InputStream reportData)
        throws IOException {
    String table = EBRConf.INSTANCE.getValue(EBRParams.REPORT_LOGGER_DBLOGGER_TABLENAME, "log_reports");
    String sql = String.format("update %s set report_data = ? where id = ?", table);
    byte[] buff = IOUtils.toByteArray(reportData);

    try (EBRConnection con = dataSourceManager.get("dblogger", request.getUser(), "EBR",
            getClass().getSimpleName());) {
        con.setAutoCommit(false);//from  www .  j  av  a  2 s. c om
        try (PreparedStatement ps = con.prepareStatement(sql)) {
            ps.setBinaryStream(1, new ByteArrayInputStream(buff));
            ps.setString(2, request.getUuid());
            if (ps.executeUpdate() == 1) {// daha nce loglanm bir rapor ise sadece gncelle
                con.commit();
                return;
            }
            con.commit();
        }

        sql = String.format("insert into %s (" + "id, report_name, time_stamp, "
                + "request_params, report_data, file_extension," + "data_source_name, email, report_locale,"
                + "report_user) " + "values(" + "?, ?, ?," + "?, ?, ?," + "?, ?, ?," + "?)", table);
        try (PreparedStatement ps = con.prepareStatement(sql)) {
            ps.setString(1, request.getUuid());
            ps.setString(2, request.getReport());
            ps.setTimestamp(3, new Timestamp(System.currentTimeMillis()));

            JSONObject jo = new JSONObject(request.getReportParams());
            ps.setString(4, jo.toString(4));
            ps.setBinaryStream(5, new ByteArrayInputStream(buff));
            ps.setString(6, request.getExtension());

            ps.setString(7, request.getDatasourceName());
            ps.setString(8, request.getEmail());
            ps.setString(9, request.getLocale());

            ps.setString(10, request.getUser());

            ps.executeUpdate();
            con.commit();
        }
    } catch (SQLException ex) {
        Logger.getLogger(BaseDBReportLogger.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.mirth.connect.plugins.dashboardstatus.DashboardConnectorEventListener.java

@Override
protected void processEvent(Event event) {
    if (event instanceof ConnectionStatusEvent) {
        ConnectionStatusEvent connectionStatusEvent = (ConnectionStatusEvent) event;
        String channelId = connectionStatusEvent.getChannelId();
        Integer metaDataId = connectionStatusEvent.getMetaDataId();
        String information = connectionStatusEvent.getMessage();
        Timestamp timestamp = new Timestamp(event.getDateTime());

        String connectorId = channelId + "_" + metaDataId;

        ConnectionStatusEventType eventType = connectionStatusEvent.getState();

        ConnectionStatusEventType connectionStatusEventType = eventType;
        Integer connectorCount = null;
        Integer maximum = null;//from   ww  w . j av  a2  s .c om

        if (event instanceof ConnectorCountEvent) {
            ConnectorCountEvent connectorCountEvent = (ConnectorCountEvent) connectionStatusEvent;

            maximum = connectorCountEvent.getMaximum();
            Boolean increment = connectorCountEvent.isIncrement();

            if (maximum != null) {
                maxConnectionMap.put(connectorId, maximum);
            } else {
                maximum = maxConnectionMap.get(connectorId);
            }

            AtomicInteger count = connectorCountMap.get(connectorId);

            if (count == null) {
                count = new AtomicInteger();
                connectorCountMap.put(connectorId, count);
            }

            if (increment != null) {
                if (increment) {
                    count.incrementAndGet();
                } else {
                    count.decrementAndGet();
                }
            }

            connectorCount = count.get();

            if (connectorCount == 0) {
                connectionStatusEventType = ConnectionStatusEventType.IDLE;
            } else {
                connectionStatusEventType = ConnectionStatusEventType.CONNECTED;
            }
        }

        String stateString = null;
        if (connectionStatusEventType.isState()) {
            Color color = getColor(connectionStatusEventType);
            stateString = connectionStatusEventType.toString();
            if (connectorCount != null) {
                if (maximum != null && connectorCount.equals(maximum)) {
                    stateString += " <font color='red'>(" + connectorCount + ")</font>";
                } else if (connectorCount > 0) {
                    stateString += " (" + connectorCount + ")";
                }
            }

            connectorStateMap.put(connectorId, new Object[] { color, stateString });
        }

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
        String channelName = "";
        String connectorType = "";

        LinkedList<String[]> channelLog = null;

        Channel channel = ControllerFactory.getFactory().createChannelController()
                .getDeployedChannelById(channelId);

        if (channel != null) {
            channelName = channel.getName();
            // grab the channel's log from the HashMap, if not exist, create
            // one.
            if (connectorInfoLogs.containsKey(channelId)) {
                channelLog = connectorInfoLogs.get(channelId);
            } else {
                channelLog = new LinkedList<String[]>();
            }

            if (metaDataId == 0) {
                connectorType = "Source: " + channel.getSourceConnector().getTransportName() + "  ("
                        + channel.getSourceConnector().getTransformer().getInboundDataType().toString() + " -> "
                        + channel.getSourceConnector().getTransformer().getOutboundDataType().toString() + ")";
            } else {
                Connector connector = getConnectorFromMetaDataId(channel.getDestinationConnectors(),
                        metaDataId);
                connectorType = "Destination: " + connector.getTransportName() + " - " + connector.getName();
            }
        }

        if (channelLog != null) {
            synchronized (this) {
                if (channelLog.size() == MAX_LOG_SIZE) {
                    channelLog.removeLast();
                }
                channelLog.addFirst(
                        new String[] { String.valueOf(logId), channelName, dateFormat.format(timestamp),
                                connectorType, ((ConnectionStatusEvent) event).getState().toString(),
                                information, channelId, Integer.toString(metaDataId) });

                if (entireConnectorInfoLogs.size() == MAX_LOG_SIZE) {
                    entireConnectorInfoLogs.removeLast();
                }
                entireConnectorInfoLogs.addFirst(
                        new String[] { String.valueOf(logId), channelName, dateFormat.format(timestamp),
                                connectorType, ((ConnectionStatusEvent) event).getState().toString(),
                                information, channelId, Integer.toString(metaDataId) });

                logId++;

                // put the channel log into the HashMap.
                connectorInfoLogs.put(channelId, channelLog);
            }
        }

    }
}

From source file:ru.org.linux.spring.DelIPController.java

/**
 *     ?  ip  //from   w  ww  . j  a  va2  s  .  c om
 * @param request http ? (? ?  ?)
 * @param reason  ?
 * @param ip ip   ?
 * @param time ?   ? (hour, day, 3day)
 * @return  ? ?  ?
 * @throws Exception    - ???
 */
@RequestMapping(value = "/delip.jsp", method = RequestMethod.POST)
public ModelAndView delIp(HttpServletRequest request, @RequestParam("reason") String reason,
        @RequestParam("ip") String ip, @RequestParam("time") String time) throws Exception {
    Map<String, Object> params = new HashMap<>();

    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isModeratorSession()) {
        throw new AccessViolationException("Not moderator");
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());

    if ("hour".equals(time)) {
        calendar.add(Calendar.HOUR_OF_DAY, -1);
    } else if ("day".equals(time)) {
        calendar.add(Calendar.DAY_OF_MONTH, -1);
    } else if ("3day".equals(time)) {
        calendar.add(Calendar.DAY_OF_MONTH, -3);
    } else {
        throw new UserErrorException("Invalid count");
    }

    Timestamp ts = new Timestamp(calendar.getTimeInMillis());
    params.put("message", "?   ?? ? " + ts.toString()
            + " ? IP " + ip + "<br>");

    User moderator = tmpl.getCurrentUser();

    DeleteCommentResult deleteResult = commentService.deleteCommentsByIPAddress(ip, ts, moderator, reason);

    params.put("topics", deleteResult.getDeletedTopicIds().size()); // -  
    params.put("deleted", deleteResult.getDeleteInfo());

    for (int topicId : deleteResult.getDeletedTopicIds()) {
        searchQueueSender.updateMessage(topicId, true);
    }

    searchQueueSender.updateComment(deleteResult.getDeletedCommentIds());

    return new ModelAndView("delip", params);
}

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

private void createBanner(final int siteId, Banner banner) {
    final Banner tempBanner = banner;
    if (banner == null)
        return;/*from w  w  w.ja v  a  2s. com*/
    banner.setBannerProfile();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            int i = 0;
            PreparedStatement ps = conn.prepareStatement(createBannerSQL);
            ps.setInt(++i, siteId);
            ps.setString(++i, tempBanner.getDirName());
            ps.setString(++i, tempBanner.getName());
            ps.setInt(++i, tempBanner.getStatus());
            ps.setInt(++i, tempBanner.getType());
            ps.setString(++i, tempBanner.getCreator());
            ps.setTimestamp(++i, new Timestamp(tempBanner.getCreatedTime().getTime()));
            ps.setInt(++i, tempBanner.getLeftPictureClbId());
            ps.setInt(++i, tempBanner.getRightPictureClbId());
            ps.setInt(++i, tempBanner.getMiddlePictureClbId());
            ps.setInt(++i, tempBanner.getCssClbId());
            ps.setInt(++i, tempBanner.getBannerTitle());
            ps.setString(++i, tempBanner.getOwnedtype());
            ps.setString(++i, tempBanner.getBannerProfile());
            return ps;
        }
    });
}

From source file:net.chrisrichardson.bankingExample.domain.jdbc.JdbcAccountDao.java

public void saveAccount(Account account) {
    int count = jdbcTemplate.update(
            "UPDATE BANK_ACCOUNT set accountId = ?, BALANCE = ?, overdraftPolicy = ?, dateOpened = ?, requiredYearsOpen = ?, limit = ? WHERE ACCOUNT_ID = ?",
            new Object[] { account.getAccountId(), account.getBalance(), account.getOverdraftPolicy(),
                    new Timestamp(account.getDateOpened().getTime()), account.getRequiredYearsOpen(),
                    account.getLimit(), account.getId() },
            new int[] { Types.VARCHAR, Types.DOUBLE, Types.INTEGER, Types.TIMESTAMP, Types.DOUBLE, Types.DOUBLE,
                    Types.INTEGER });
    Assert.isTrue(count == 1);//w  w  w .ja v  a  2s  . co  m

}

From source file:net.naijatek.myalumni.util.date.DateConverter.java

protected Object convertToDate(Class type, Object value, String pattern) {
    DateFormat df = new SimpleDateFormat(pattern);
    if (value instanceof String) {
        try {//from  w w  w  .  j  av a2 s  .co  m
            if (StringUtils.isEmpty(value.toString())) {
                return null;
            }

            Date date = df.parse((String) value);
            if (type.equals(Timestamp.class)) {
                return new Timestamp(date.getTime());
            }
            return date;
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting String to Date");
        }
    }

    throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName());
}

From source file:net.duckling.ddl.service.resource.dao.StarmarkDAOImpl.java

@Override
public int create(final Starmark starmark) {
    GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
    this.getJdbcTemplate().update(new PreparedStatementCreator() {

        @Override//  w  ww .j a  v a 2s  . co m
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = null;
            ps = conn.prepareStatement(SQL_CREATE, PreparedStatement.RETURN_GENERATED_KEYS);
            int i = 0;
            ps.setInt(++i, starmark.getRid());
            ps.setInt(++i, starmark.getTid());
            ps.setString(++i, starmark.getUid());
            ps.setTimestamp(++i, new Timestamp(starmark.getCreateTime().getTime()));
            return ps;
        }

    }, keyHolder);
    Number key = keyHolder.getKey();
    return (key == null) ? -1 : key.intValue();
}

From source file:com.esri.geoportal.harvester.beans.HistoryManagerBean.java

@Override
public UUID create(History.Event data) throws CrudlException {
    UUID id = UUID.randomUUID();
    try (Connection connection = dataSource.getConnection();
            PreparedStatement st = connection.prepareStatement(
                    "INSERT INTO EVENTS (taskid,started,completed,report,id) VALUES (?,?,?,?,?)");
            Reader reportReader = new StringReader(serialize(data.getReport()));) {
        st.setString(1, data.getTaskId().toString());
        st.setTimestamp(2, new Timestamp(data.getStartTimestamp().getTime()));
        st.setTimestamp(3, new Timestamp(data.getEndTimestamp().getTime()));
        st.setClob(4, reportReader);/*from   ww w  .  j av a  2 s  .co m*/
        st.setString(5, data.getUuid().toString());
        st.executeUpdate();
    } catch (IOException | SQLException ex) {
        throw new CrudlException("Error creating history event", ex);
    }
    return id;
}

From source file:com.webbfontaine.valuewebb.irms.impl.assignment.snapshot.SnapshotManager.java

private Timestamp toTimestamp(Date dateValue) {
    return new Timestamp(dateValue.getTime());
}

From source file:airport.database.services.users.UsersDaoOnlineImpl.java

@Override
public void addUser(User user) {
    try {/*from www  .  ja v  a2s .  com*/
        jdbcTemplate.getJdbcOperations().update(SQL_QUERY_ADD_USER, user.getLogin(),
                new Timestamp(new GregorianCalendar().getTimeInMillis()), user.getId());
    } catch (Throwable e) {
        //? ? ? ?? SPRING JDBC TEMPLATE  
    }

    if (LOG.isInfoEnabled()) {
        LOG.info("add user online. User : " + user);
    }
}