List of usage examples for java.sql ResultSet getLong
long getLong(String columnLabel) throws SQLException;
ResultSet
object as a long
in the Java programming language. From source file:org.ulyssis.ipp.snapshot.Snapshot.java
public void save(Connection connection) throws SQLException { if (id != -1) return;/* w w w. ja va 2 s . co m*/ try (PreparedStatement statement = connection.prepareStatement( "INSERT INTO \"snapshots\" (\"time\",\"data\",\"event\") VALUES (?,?,?)", Statement.RETURN_GENERATED_KEYS)) { statement.setTimestamp(1, Timestamp.from(snapshotTime)); String serialized; try { serialized = Serialization.getJsonMapper().writeValueAsString(this); } catch (JsonProcessingException e) { assert false; // TODO(Roel): Programming error return; } statement.setString(2, serialized); statement.setLong(3, eventId); statement.executeUpdate(); ResultSet keys = statement.getGeneratedKeys(); keys.next(); this.id = keys.getLong(1); } }
From source file:ar.com.zauber.commons.gis.street.impl.UsigRouter.java
/** dada una cordena, encuentra el eje del grafo de ruteo ms cercano */ private RoutingEdge findNearestEdge(final Point geom) { final List<RoutingEdge> ret = new ArrayList<RoutingEdge>(); jdbcTemplate.query(SQL_NEDGE, new Object[] { geom.toString() }, new ResultSetExtractor() { public Object extractData(final ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { final RoutingEdge edge = new RoutingEdge(); edge.gid = rs.getLong("gid"); edge.source = rs.getLong("source"); edge.target = rs.getLong("target"); edge.distance = rs.getLong("distance"); ret.add(edge);// w w w.ja va2 s . c om } return null; } }); if (ret.size() == 0) { throw new NoSuchEntityException(geom); } if (ret.size() > 1) { throw new IllegalStateException("bla"); } return ret.get(0); }
From source file:iddb.runtime.db.model.dao.impl.mysql.UserDAOImpl.java
/** * @param user/*from w w w .j a va 2 s . c o m*/ * @param rs * @throws SQLException */ private void loadUser(User user, ResultSet rs) throws SQLException { user.setKey(rs.getLong("id")); user.setLoginId(rs.getString("loginid")); user.setPassword(rs.getString("password")); user.setRoles(new LinkedHashSet<String>(Arrays.asList(StringUtils.split(rs.getString("roles"), ",")))); }
From source file:org.openvpms.tools.data.migration.DetailsMigrator.java
private void export(Connection connection, String from, String to, String key) throws SQLException { System.out.println("Migrating details from " + from + " to " + to); Date start = new Date(); PreparedStatement select = connection .prepareStatement("select " + key + ", details from " + from + " where details is not null"); PreparedStatement insert = connection.prepareStatement( "insert into " + to + " (" + key + ", type, name, value) " + "values (?, ?, ?, ?)"); ResultSet set = select.executeQuery(); int input = 0; int output = 0; int batch = 0; while (set.next()) { ++input;//from www . jav a 2s . c o m long id = set.getLong(1); String details = set.getString(2); if (!StringUtils.isEmpty(details)) { DynamicAttributeMap map = (DynamicAttributeMap) stream.fromXML(details); Map<String, Serializable> attributes = map.getAttributes(); for (Map.Entry<String, Serializable> entry : attributes.entrySet()) { if (entry.getValue() != null) { // don't insert nulls. See OBF-161 String name = entry.getKey(); TypedValue value = new TypedValue(entry.getValue()); insert.setLong(1, id); insert.setString(2, value.getType()); insert.setString(3, name); insert.setString(4, value.getValue()); insert.addBatch(); ++output; } } } ++batch; if (batch >= 1000) { // commit every 1000 input rows insert.executeBatch(); connection.commit(); batch = 0; } } if (batch != 0) { insert.executeBatch(); connection.commit(); } set.close(); insert.close(); select.close(); Date end = new Date(); double elapsed = (end.getTime() - start.getTime()) / 1000; System.out.printf("Processed %d rows, generating %d rows in %.2fs\n", input, output, elapsed); }
From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet.java
/** * @param connection//from ww w .j a va2 s . c o m * @param series * @param metrica * @param timeBegin * @param timeEnd * @param dataset * @throws SQLException */ private void getMetrics(Connection connection, String series, String metrica, long timeBegin, long timeEnd, DefaultCategoryDataset dataset) throws SQLException { PreparedStatement stmt = null; try { // String dateStr = format.format(calendar.getTime()); // System.out.println("!!! " + dateStr); SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); stmt = connection.prepareStatement("SELECT METRIC_VALUE_LONG, METRIC_DATE" + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ? and " + " METRIC_DATE BETWEEN ? AND ? "); stmt.setString(1, metrica); stmt.setDate(2, new java.sql.Date(timeBegin)); stmt.setDate(3, new java.sql.Date(timeEnd)); ResultSet rs = stmt.executeQuery(); while (rs.next()) { long value = rs.getLong("METRIC_VALUE_LONG") / 1000; Date date = rs.getDate("METRIC_DATE"); String dateStr = format.format(date.getTime()); String category = dateStr; dataset.addValue(value, series, category); // System.out.println("!!!! ALL_DCM_SIZE="+dateStr+"="+value); } rs.close(); } finally { if (stmt != null) stmt.close(); } }
From source file:com.bleum.canton.jms.dao.impl.JMSTaskDao.java
@Override public List<JMSTask> findTaskForProcessing(int type, int limit) { return this.jdbcTemplate.query(QUERY_TASK_FOR_PROCESSING, new Object[] { type, limit }, new RowMapper<JMSTask>() { public JMSTask mapRow(ResultSet rs, int rowNum) throws SQLException { JMSTask task = new JMSTask(); task.setId(rs.getLong("id")); task.setContentId(rs.getString("content_id")); task.setType(rs.getInt("type")); task.setStatus(rs.getInt("status")); task.setCreatedDate(rs.getDate("created_time")); task.setOperatedDate(rs.getDate("operated_time")); if (rs.getClob("message") != null) { task.setMessage(CantonStringUtils.convertToString(rs.getClob("message"))); }/* w ww . j a va 2s . co m*/ task.setRetry(rs.getInt("retry")); task.setLastError(rs.getString("last_error")); return task; } }); }
From source file:ca.nrc.cadc.vos.server.NodeMapper.java
/** * Map the row to the appropriate type of node object. * @param rs// w w w.ja v a 2s. c o m * @param row * @return a Node * @throws SQLException */ public Object mapRow(ResultSet rs, int row) throws SQLException { long nodeID = rs.getLong("nodeID"); String name = rs.getString("name"); String type = rs.getString("type"); String busyString = rs.getString("busyState"); String groupRead = rs.getString("groupRead"); String groupWrite = rs.getString("groupWrite"); boolean isPublic = rs.getBoolean("isPublic"); boolean isLocked = rs.getBoolean("isLocked"); Object ownerObject = rs.getObject("ownerID"); String contentType = rs.getString("contentType"); String contentEncoding = rs.getString("contentEncoding"); String link = null; Long contentLength = null; Object o = rs.getObject("contentLength"); if (o != null) { Number n = (Number) o; contentLength = new Long(n.longValue()); } log.debug("readNode: contentLength = " + contentLength); Object contentMD5 = rs.getObject("contentMD5"); Date lastModified = rs.getTimestamp("lastModified", cal); String path = basePath + "/" + name; VOSURI vos; try { vos = new VOSURI(new URI("vos", authority, path, null, null)); } catch (URISyntaxException bug) { throw new RuntimeException("BUG - failed to create vos URI", bug); } Node node; if (NodeDAO.NODE_TYPE_CONTAINER.equals(type)) { node = new ContainerNode(vos); } else if (NodeDAO.NODE_TYPE_DATA.equals(type)) { node = new DataNode(vos); ((DataNode) node).setBusy(NodeBusyState.getStateFromValue(busyString)); } else if (NodeDAO.NODE_TYPE_LINK.equals(type)) { link = rs.getString("link"); try { node = new LinkNode(vos, new URI(link)); } catch (URISyntaxException bug) { throw new RuntimeException("BUG - failed to create link URI", bug); } } else { throw new IllegalStateException("Unknown node database type: " + type); } NodeID nid = new NodeID(); nid.id = nodeID; nid.ownerObject = ownerObject; node.appData = nid; if (contentType != null && contentType.trim().length() > 0) { node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_TYPE, contentType)); } if (contentEncoding != null && contentEncoding.trim().length() > 0) { node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTENCODING, contentEncoding)); } if (contentLength != null) node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTLENGTH, contentLength.toString())); else node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTLENGTH, "0")); if (contentMD5 != null && contentMD5 instanceof byte[]) { byte[] md5 = (byte[]) contentMD5; if (md5.length < 16) { byte[] tmp = md5; md5 = new byte[16]; System.arraycopy(tmp, 0, md5, 0, tmp.length); // extra space is init with 0 } String contentMD5String = HexUtil.toHex(md5); node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTMD5, contentMD5String)); } if (lastModified != null) { node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_DATE, dateFormat.format(lastModified))); } if (groupRead != null && groupRead.trim().length() > 0) { node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_GROUPREAD, groupRead)); } if (groupWrite != null && groupWrite.trim().length() > 0) { node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_GROUPWRITE, groupWrite)); } node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_ISPUBLIC, isPublic ? "true" : "false")); if (isLocked) node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_ISLOCKED, isLocked ? "true" : "false")); // set the read-only flag on the properties for (String propertyURI : VOS.READ_ONLY_PROPERTIES) { int propertyIndex = node.getProperties().indexOf(new NodeProperty(propertyURI, "")); if (propertyIndex != -1) { node.getProperties().get(propertyIndex).setReadOnly(true); } } log.debug("read: " + node.getUri() + "," + node.appData); return node; }
From source file:com.springsource.greenhouse.invite.JdbcInviteRepository.java
private Invite queryForInvite(String token) throws NoSuchInviteException { try {/*w w w . j ava2 s . c o m*/ return jdbcTemplate.queryForObject(SELECT_INVITE, new RowMapper<Invite>() { public Invite mapRow(ResultSet rs, int rowNum) throws SQLException { Invitee invitee = new Invitee(rs.getString("firstName"), rs.getString("lastName"), rs.getString("email")); ProfileReference sentBy = ProfileReference.textOnly(rs.getLong("sentById"), rs.getString("sentByUsername"), rs.getString("sentByFirstName"), rs.getString("sentByLastName")); return new Invite(invitee, sentBy, rs.getBoolean("accepted")); } }, token, token); } catch (EmptyResultDataAccessException e) { throw new NoSuchInviteException(token); } }
From source file:nl.surfnet.coin.teams.service.impl.GroupProviderServiceSQLImpl.java
private GroupProvider mapRowToGroupProvider(ResultSet rs) throws SQLException { Long id = rs.getLong("id"); String identifier = rs.getString("identifier"); String name = rs.getString("name"); String gpClassName = rs.getString("classname"); GroupProvider gp = new GroupProvider(id, identifier, name, gpClassName); String logoUrl = rs.getString("logo_url"); gp.setLogoUrl(logoUrl);/* w ww. j a v a2 s . c o m*/ gp.setAllowedOptions(getAllowedOptions(gp)); gp.setUserIdPrecondition(getUserIdPreCondition(id)); gp.setPersonDecorators(getPersonIdDecorators(gp)); gp.setGroupDecorators(getGroupIdDecorators(gp)); gp.setPersonFilters(getPersonIdFilters(gp)); gp.setGroupFilters(getGroupIdFilters(gp)); gp.setServiceProviderGroupAcls(getServiceProviderGroupAcl(gp)); return gp; }
From source file:online.themixhub.demo.sql.impl.JobCommentMapper.java
public JobComment mapRow(ResultSet rs, int rowNum) throws SQLException { JobComment jobComment = new JobComment(); jobComment.setId(rs.getInt("id")); jobComment.setDate(rs.getLong("date")); jobComment.setReply_to_id(rs.getInt("reply_to_id")); jobComment.setParent_account_id(rs.getInt("parent_account_id")); jobComment.setParent_job_id(rs.getInt("parent_job_id")); jobComment.setComment(rs.getString("comment")); jobComment.setFilepaths(rs.getString("filepaths")); return jobComment; }