List of usage examples for java.sql ResultSet getTimestamp
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Timestamp
object in the Java programming language. From source file:bboss.org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader.java
/** * Fetches the last modification time of the resource * * @param resource Resource object we are finding timestamp of * @param operation string for logging, indicating caller's intention * * @return timestamp as long/* w w w . ja v a 2 s.co m*/ */ private long readLastModified(final Resource resource, final String operation) { long timeStamp = 0; /* get the template name from the resource */ String name = resource.getName(); if (name == null || name.length() == 0) { String msg = "DataSourceResourceLoader: Template name was empty or null"; log.error(msg); throw new NullPointerException(msg); } else { Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; try { conn = openDbConnection(); ps = getStatement(conn, timestampColumn, name); rs = ps.executeQuery(); if (rs.next()) { Timestamp ts = rs.getTimestamp(timestampColumn); timeStamp = ts != null ? ts.getTime() : 0; } else { String msg = "DataSourceResourceLoader: could not find resource " + name + " while " + operation; log.error(msg); throw new ResourceNotFoundException(msg); } } catch (SQLException sqle) { String msg = "DataSourceResourceLoader: database problem while " + operation + " of '" + name + "': "; log.error(msg, sqle); throw ExceptionUtils.createRuntimeException(msg, sqle); } catch (NamingException ne) { String msg = "DataSourceResourceLoader: database problem while " + operation + " of '" + name + "': "; log.error(msg, ne); throw ExceptionUtils.createRuntimeException(msg, ne); } finally { closeResultSet(rs); closeStatement(ps); closeDbConnection(conn); } } return timeStamp; }
From source file:ru.org.linux.user.UserDao.java
/** * /* ww w . ja v a 2 s. co m*/ * @param user * @return ? :-) */ public BanInfo getBanInfoClass(User user) { List<BanInfo> infoList = jdbcTemplate.query(queryBanInfoClass, new RowMapper<BanInfo>() { @Override public BanInfo mapRow(ResultSet resultSet, int i) throws SQLException { Timestamp date = resultSet.getTimestamp("bandate"); String reason = resultSet.getString("reason"); User moderator; try { moderator = getUser(resultSet.getInt("ban_by")); } catch (UserNotFoundException exception) { throw new SQLException(exception.getMessage()); } return new BanInfo(date, reason, moderator); } }, user.getId()); if (infoList.isEmpty()) { return null; } else { return infoList.get(0); } }
From source file:com.concursive.connect.web.modules.discussion.dao.ReplyIndexer.java
/** * Given a database and a Lucene writer, this method will add content to the * searchable index/* w w w.j av a2 s .c o m*/ * * @param writer Description of the Parameter * @param db Description of the Parameter * @param context * @throws SQLException Description of the Exception * @throws IOException Description of the Exception */ public void add(IIndexerService writer, Connection db, IndexerContext context) throws SQLException, IOException { int count = 0; PreparedStatement pst = db.prepareStatement( "SELECT r.reply_id, r.issue_id, i.project_id, i.category_id, r.subject, r.message, r.modified " + "FROM project_issue_replies r " + "LEFT JOIN project_issues i ON r.issue_id = i.issue_id " + "WHERE i.project_id > -1 "); ResultSet rs = pst.executeQuery(); while (rs.next() && context.getEnabled()) { ++count; // read the record Reply reply = new Reply(); reply.setId(rs.getInt("reply_id")); reply.setIssueId(rs.getInt("issue_id")); reply.setProjectId(rs.getInt("project_id")); reply.setCategoryId(rs.getInt("category_id")); reply.setSubject(rs.getString("subject")); reply.setBody(rs.getString("message")); reply.setModified(rs.getTimestamp("modified")); // add the document writer.indexAddItem(reply, false); } rs.close(); pst.close(); LOG.info("IssueReplyIndexer Finished: " + count); }
From source file:com.concursive.connect.web.modules.plans.dao.AssignmentIndexer.java
/** * Given a database and a Lucene writer, this method will add content to the * searchable index//from w w w . j a v a 2 s . c o m * * @param writer Description of the Parameter * @param db Description of the Parameter * @param context * @throws SQLException Description of the Exception * @throws IOException Description of the Exception */ public void add(IIndexerService writer, Connection db, IndexerContext context) throws SQLException, IOException { int count = 0; PreparedStatement pst = db .prepareStatement("SELECT assignment_id, project_id, role, technology, requirement_id, modified " + "FROM project_assignments " + "WHERE assignment_id > -1 "); ResultSet rs = pst.executeQuery(); while (rs.next() && context.getEnabled()) { ++count; // read the record Assignment assignment = new Assignment(); assignment.setId(rs.getInt("assignment_id")); assignment.setProjectId(rs.getInt("project_id")); assignment.setRole(rs.getString("role")); assignment.setTechnology(rs.getString("technology")); assignment.setRequirementId(rs.getInt("requirement_id")); assignment.setModified(rs.getTimestamp("modified")); // add the document writer.indexAddItem(assignment, false); } rs.close(); pst.close(); LOG.info("Finished: " + count); }
From source file:edu.northwestern.bioinformatics.studycalendar.domain.tools.hibernate.ScheduledActivityStateType.java
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { // we don't know the owner yet, but that's okay because the MODE_TYPE doesn't use it. ScheduledActivityMode mode = (ScheduledActivityMode) MODE_TYPE.nullSafeGet(rs, names[MODE_INDEX], session, null);/*w ww . j ava 2s . co m*/ ScheduledActivityState loaded = createStateObject(mode); if (loaded == null) return null; loaded.setReason(rs.getString(names[REASON_INDEX])); loaded.setDate(rs.getTimestamp(names[DATE_INDEX])); loaded.setWithTime(rs.getBoolean(names[WITH_TIME_INDEX])); return loaded; }
From source file:net.solarnetwork.node.dao.jdbc.reactor.JdbcInstructionDao.java
private List<Instruction> extractInstructions(ResultSet rs) throws SQLException { List<Instruction> results = new ArrayList<Instruction>(5); BasicInstruction bi = null;/* www . j a v a2 s. c om*/ while (rs.next()) { long currId = rs.getLong(1); if (bi == null || bi.getId().longValue() != currId) { InstructionStatus status = new BasicInstructionStatus(currId, InstructionState.valueOf(rs.getString(6)), rs.getTimestamp(7), (rs.getString(8) == null ? null : InstructionState.valueOf(rs.getString(8)))); bi = new BasicInstruction(currId, rs.getString(2), rs.getTimestamp(3), rs.getString(4), rs.getString(5), status); results.add(bi); } String pName = rs.getString(9); String pValue = rs.getString(10); if (pName != null) { bi.addParameter(pName, pValue); } } return results; }
From source file:com.concursive.connect.web.modules.documents.dao.FileItemIndexer.java
/** * Given a database and a Lucene writer, this method will add content to the * searchable index//from w w w . j ava 2s . c o m * * @param writer Description of the Parameter * @param db Description of the Parameter * @param context * @throws SQLException Description of the Exception * @throws IOException Description of the Exception */ public void add(IIndexerService writer, Connection db, IndexerContext context) throws SQLException, IOException { int count = 0; PreparedStatement pst = db.prepareStatement( "SELECT item_id, folder_id, link_item_id, subject, client_filename, modified, size, filename " + "FROM project_files " + "WHERE link_module_id = ? "); pst.setInt(1, Constants.PROJECTS_FILES); ResultSet rs = pst.executeQuery(); while (rs.next() && context.getEnabled()) { ++count; // read the record FileItem fileItem = new FileItem(); fileItem.setId(rs.getInt("item_id")); fileItem.setFolderId(rs.getInt("folder_id")); fileItem.setLinkItemId(rs.getInt("link_item_id")); fileItem.setSubject(rs.getString("subject")); fileItem.setClientFilename(rs.getString("client_filename")); fileItem.setModified(rs.getTimestamp("modified")); fileItem.setSize(rs.getInt("size")); fileItem.setFilename(rs.getString("filename")); fileItem.setDirectory(context.getApplicationPrefs().get("FILELIBRARY") + "1" + File.separator + "projects" + File.separator); // add the document writer.indexAddItem(fileItem, false); } rs.close(); pst.close(); LOG.info("FileItemIndexer Finished: " + count); }
From source file:com.concursive.connect.web.modules.issues.dao.TicketIndexer.java
/** * Given a database and a Lucene writer, this method will add content to the * searchable index// ww w .j av a 2 s.co m * * @param writer Description of the Parameter * @param db Description of the Parameter * @param context * @throws SQLException Description of the Exception * @throws IOException Description of the Exception */ public void add(IIndexerService writer, Connection db, IndexerContext context) throws SQLException, IOException { int count = 0; PreparedStatement pst = db.prepareStatement( "SELECT ticketid, project_id, problem, solution, location, cause, modified, enteredby, key_count " + "FROM ticket t, ticketlink_project l " + "WHERE t.ticketid = l.ticket_id "); ResultSet rs = pst.executeQuery(); while (rs.next() && context.getEnabled()) { ++count; // read the record Ticket ticket = new Ticket(); ticket.setId(rs.getInt("ticketid")); ticket.setProjectId(rs.getInt("project_id")); ticket.setProblem(rs.getString("problem")); ticket.setSolution(rs.getString("solution")); ticket.setLocation(rs.getString("location")); ticket.setCause(rs.getString("cause")); ticket.setModified(rs.getTimestamp("modified")); ticket.setEnteredBy(rs.getInt("enteredby")); ticket.setProjectTicketCount(rs.getInt("key_count")); // add the document writer.indexAddItem(ticket, false); } rs.close(); pst.close(); LOG.info("Finished: " + count); }
From source file:net.algem.security.UserDaoImpl.java
@Override public PasswordResetToken getToken(final int userId) { String query = "SELECT jeton,creadate FROM " + T_TOKEN + " WHERE idper = ?"; return jdbcTemplate.queryForObject(query, new RowMapper<PasswordResetToken>() { @Override//from w ww.j ava2s .c o m public PasswordResetToken mapRow(ResultSet rs, int i) throws SQLException { PasswordResetToken token = new PasswordResetToken(userId); token.setToken(rs.getString(1)); token.setCreation(rs.getTimestamp(2).getTime()); return token; } }, userId); }
From source file:ru.org.linux.user.UserDao.java
/** * ?? ?//from w ww. j a va2 s. c o m * @param user * @param exact ? ? ?? * @return ?? */ public UserStatistics getUserStatisticsClass(User user, boolean exact) { int ignoreCount = ignoreListDao.getIgnoreStat(user); int commentCount = 0; boolean exactCommentCount = false; if (!exact) { List<Integer> res = jdbcTemplate.queryForList("SELECT cnt FROM user_comment_counts WHERE userid=?", Integer.class, user.getId()); if (res.size() > 0) { commentCount = (int) Math.round(res.get(0) / 1000.0) * 1000; } } if (commentCount == 0) { try { commentCount = jdbcTemplate.queryForInt(queryCommentStat, user.getId()); } catch (EmptyResultDataAccessException exception) { } exactCommentCount = true; } List<Timestamp> commentStat; try { commentStat = jdbcTemplate.queryForObject(queryCommentDates, new RowMapper<List<Timestamp>>() { @Override public List<Timestamp> mapRow(ResultSet resultSet, int i) throws SQLException { return Lists.newArrayList(resultSet.getTimestamp("first"), resultSet.getTimestamp("last")); } }, user.getId()); } catch (EmptyResultDataAccessException exception) { commentStat = null; } List<Timestamp> topicStat; try { topicStat = jdbcTemplate.queryForObject(queryTopicDates, new RowMapper<List<Timestamp>>() { @Override public List<Timestamp> mapRow(ResultSet resultSet, int i) throws SQLException { return Lists.newArrayList(resultSet.getTimestamp("first"), resultSet.getTimestamp("last")); } }, user.getId()); } catch (EmptyResultDataAccessException exception) { topicStat = null; } final ImmutableList.Builder<UsersSectionStatEntry> builder = ImmutableList.builder(); jdbcTemplate.query(queryTopicsBySectionStat, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { builder.add(new UsersSectionStatEntry(resultSet.getInt("section"), resultSet.getInt("c"))); } }, user.getId()); return new UserStatistics(ignoreCount, commentCount, exactCommentCount, commentStat.get(0), commentStat.get(1), topicStat.get(0), topicStat.get(1), builder.build()); }