List of usage examples for org.springframework.jdbc.support.rowset SqlRowSet getInt
int getInt(String columnLabel) throws InvalidResultSetAccessException;
From source file:ru.org.linux.tracker.TrackerDao.java
public List<TrackerItem> getTrackAll(TrackerFilterEnum filter, User currentUser, Timestamp interval, int topics, int offset, final int messagesInPage) { MapSqlParameterSource parameter = new MapSqlParameterSource(); parameter.addValue("interval", interval); parameter.addValue("topics", topics); parameter.addValue("offset", offset); String partIgnored;/*from www . ja v a 2 s . co m*/ if (currentUser != null) { partIgnored = queryPartIgnored + queryPartTagIgnored; parameter.addValue("userid", currentUser.getId()); } else { partIgnored = ""; } String partFilter; String partWiki = queryPartWiki; switch (filter) { case ALL: partFilter = ""; break; case NOTALKS: partFilter = queryPartNoTalks; break; case TECH: partFilter = queryPartTech; break; case MINE: if (currentUser != null) { partFilter = queryPartMine; partWiki = queryPartWikiMine; } else { partFilter = ""; } break; default: partFilter = ""; } boolean showUncommited = currentUser != null && (currentUser.isModerator() || currentUser.isCorrector()); String partUncommited = showUncommited ? "" : noUncommited; String query; if (filter != TrackerFilterEnum.ZERO) { query = String.format(queryTrackerMain, partUncommited, partIgnored, partFilter, partUncommited, partIgnored, partFilter, partWiki); } else { query = String.format(queryTrackerZeroMain, partIgnored); } SqlRowSet resultSet = jdbcTemplate.queryForRowSet(query, parameter); List<TrackerItem> res = new ArrayList<>(topics); while (resultSet.next()) { User author; try { int author_id = resultSet.getInt("author"); if (author_id != 0) { author = userDao.getUserCached(author_id); } else { author = null; } } catch (UserNotFoundException e) { throw new RuntimeException(e); } int msgid = resultSet.getInt("id"); Timestamp lastmod = resultSet.getTimestamp("lastmod"); int stat1 = resultSet.getInt("stat1"); int groupId = resultSet.getInt("gid"); String groupTitle = resultSet.getString("gtitle"); String title = resultSet.getString("title"); int cid = resultSet.getInt("cid"); User lastCommentBy; try { int id = resultSet.getInt("last_comment_by"); if (id != 0) { lastCommentBy = userDao.getUserCached(id); } else { lastCommentBy = null; } } catch (UserNotFoundException e) { throw new RuntimeException(e); } boolean resolved = resultSet.getBoolean("resolved"); int section = resultSet.getInt("section"); String groupUrlName = resultSet.getString("urlname"); Timestamp postdate = resultSet.getTimestamp("postdate"); boolean uncommited = resultSet.getBoolean("smod") && !resultSet.getBoolean("moderate"); int pages = Topic.getPageCount(stat1, messagesInPage); ImmutableList<String> tags; if (msgid != 0) { tags = topicTagService.getMessageTagsForTitle(msgid); } else { tags = ImmutableList.of(); } res.add(new TrackerItem(author, msgid, lastmod, stat1, groupId, groupTitle, title, cid, lastCommentBy, resolved, section, groupUrlName, postdate, uncommited, pages, tags)); } return res; }
From source file:ru.org.linux.group.GroupController.java
private List<TopicsListItem> prepareTopic(SqlRowSet rs, int messagesInPage) { List<TopicsListItem> topicsList = new ArrayList<>(); while (rs.next()) { User author;//from ww w . jav a2s. c om try { author = userDao.getUserCached(rs.getInt("userid")); } catch (UserNotFoundException e) { throw new RuntimeException(e); } ImmutableList<String> tags = topicTagService.getMessageTagsForTitle(rs.getInt("msgid")); TopicsListItem topic = new TopicsListItem(author, rs, messagesInPage, tags); topicsList.add(topic); } return topicsList; }
From source file:com.emc.ecs.sync.service.SqliteDbServiceTest.java
@Test public void testRowInsert() throws Exception { // test with various parameters and verify result Date now = new Date(); byte[] data = "Hello World!".getBytes("UTF-8"); String id = "1"; dbService.setStatus(new TestSyncObject(null, id, id, new byte[] {}, null), ObjectStatus.InTransfer, null, true);/* w w w. j a v a 2 s . c o m*/ SqlRowSet rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertNull(rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(0, rowSet.getInt("size")); Assert.assertEquals(0, rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.InTransfer.getValue(), rowSet.getString("status")); Assert.assertNotEquals(0, rowSet.getLong("transfer_start")); Assert.assertEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(0, rowSet.getInt("retry_count")); Assert.assertNull(rowSet.getString("error_message")); // double check that dates are represented accurately // the transfer_start date should be less than a second later than the start of this method Assert.assertTrue(rowSet.getLong("transfer_start") - now.getTime() < 1000); try { dbService.setStatus(new TestSyncObject(null, "2", "2", new byte[] {}, null), null, null, true); Assert.fail("status should be required"); } catch (NullPointerException e) { // expected } id = "3"; TestSyncObject object = new TestSyncObject(null, id, id, null, new ArrayList<TestSyncObject>()); object.getMetadata().setModificationTime(now); object.incFailureCount(); dbService.setStatus(object, ObjectStatus.Verified, "foo", true); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertNull(rowSet.getString("target_id")); Assert.assertTrue(rowSet.getBoolean("is_directory")); Assert.assertEquals(0, rowSet.getInt("size")); Assert.assertEquals(now.getTime(), rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.Verified.getValue(), rowSet.getString("status")); Assert.assertEquals(0, rowSet.getLong("transfer_start")); Assert.assertEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertNotEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(1, rowSet.getInt("retry_count")); Assert.assertEquals("foo", rowSet.getString("error_message")); id = "4"; object = new TestSyncObject(null, id, id, data, null); dbService.setStatus(object, ObjectStatus.Transferred, null, true); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertNull(rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(0, rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.Transferred.getValue(), rowSet.getString("status")); Assert.assertEquals(0, rowSet.getLong("transfer_start")); Assert.assertNotEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(0, rowSet.getInt("retry_count")); Assert.assertNull(rowSet.getString("error_message")); id = "5"; object = new TestSyncObject(null, id, id, data, null); dbService.setStatus(object, ObjectStatus.InVerification, null, true); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertNull(rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(0, rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.InVerification.getValue(), rowSet.getString("status")); Assert.assertEquals(0, rowSet.getLong("transfer_start")); Assert.assertEquals(0, rowSet.getLong("transfer_complete")); Assert.assertNotEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(0, rowSet.getInt("retry_count")); Assert.assertNull(rowSet.getString("error_message")); id = "6"; object = new TestSyncObject(null, id, id, data, null); dbService.setStatus(object, ObjectStatus.RetryQueue, "blah", true); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertNull(rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(0, rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.RetryQueue.getValue(), rowSet.getString("status")); Assert.assertEquals(0, rowSet.getLong("transfer_start")); Assert.assertEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(0, rowSet.getInt("retry_count")); Assert.assertEquals("blah", rowSet.getString("error_message")); id = "7"; object = new TestSyncObject(null, id, id, data, null); dbService.setStatus(object, ObjectStatus.Error, "blah", true); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertNull(rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(0, rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.Error.getValue(), rowSet.getString("status")); Assert.assertEquals(0, rowSet.getLong("transfer_start")); Assert.assertEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(0, rowSet.getInt("retry_count")); Assert.assertEquals("blah", rowSet.getString("error_message")); }
From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGeneratorSlowTest.java
/** * Tests the {@link QCLiveTestDataGenerator#generateTestData(String)} method with a valid archive name * and check assertions to verify that CNTL test data was loaded. *///ww w . j av a 2 s . c o m @Test public void testLoadCNTLTestDataForNonCNTLArchive() throws IOException, SQLException, ParseException { // Retrieve the QCLiveTestDataGenerator from the Spring context and invoke it using a valid archive name ((QCLiveTestDataGenerator) testAppCtx.getBean("qcLiveTestDataGenerator")) .generateTestData("nationwidechildrens.org_BRCA.bio.Level_1.85.21.0"); final JdbcTemplate diseaseLocalJdbcTemplate = (JdbcTemplate) testAppCtx.getBean("diseaseLocalJdbcTemplate"); final SqlRowSet rowSet = diseaseLocalJdbcTemplate.queryForRowSet("select * from data_level"); assertNotNull(rowSet); assertTrue(rowSet.first()); assertEquals(1, rowSet.getInt("level_number")); assertEquals("cAsESeNsItIvE", rowSet.getString("level_definition")); assertTrue(rowSet.isLast()); }
From source file:com.emc.ecs.sync.service.SqliteDbServiceTest.java
@Test public void testRowUpdate() throws Exception { byte[] data = "Hello World!".getBytes("UTF-8"); String id = "1"; Date now = new Date(); TestSyncObject object = new TestSyncObject(null, id, id, data, null); object.setTargetIdentifier(id);// www.j a v a 2 s . co m object.getMetadata().setModificationTime(now); dbService.setStatus(object, ObjectStatus.InTransfer, null, true); SqlRowSet rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertEquals(id, rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(now.getTime(), rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.InTransfer.getValue(), rowSet.getString("status")); Assert.assertNotEquals(0, rowSet.getLong("transfer_start")); Assert.assertEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(0, rowSet.getInt("retry_count")); Assert.assertNull(rowSet.getString("error_message")); String error = "ouch"; dbService.setStatus(object, ObjectStatus.RetryQueue, error, false); object.incFailureCount(); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertEquals(id, rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(now.getTime(), rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.RetryQueue.getValue(), rowSet.getString("status")); Assert.assertNotEquals(0, rowSet.getLong("transfer_start")); Assert.assertEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(0, rowSet.getInt("retry_count")); Assert.assertEquals(error, rowSet.getString("error_message")); dbService.setStatus(object, ObjectStatus.InTransfer, null, false); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertEquals(id, rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(now.getTime(), rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.InTransfer.getValue(), rowSet.getString("status")); Assert.assertNotEquals(0, rowSet.getLong("transfer_start")); Assert.assertEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(1, rowSet.getInt("retry_count")); Assert.assertEquals(error, rowSet.getString("error_message")); dbService.setStatus(object, ObjectStatus.Transferred, null, false); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertEquals(id, rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(now.getTime(), rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.Transferred.getValue(), rowSet.getString("status")); Assert.assertNotEquals(0, rowSet.getLong("transfer_start")); Assert.assertNotEquals(0, rowSet.getLong("transfer_complete")); Assert.assertEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(1, rowSet.getInt("retry_count")); Assert.assertEquals(error, rowSet.getString("error_message")); dbService.setStatus(object, ObjectStatus.InVerification, null, false); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertEquals(id, rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(now.getTime(), rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.InVerification.getValue(), rowSet.getString("status")); Assert.assertNotEquals(0, rowSet.getLong("transfer_start")); Assert.assertNotEquals(0, rowSet.getLong("transfer_complete")); Assert.assertNotEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(1, rowSet.getInt("retry_count")); Assert.assertEquals(error, rowSet.getString("error_message")); dbService.setStatus(object, ObjectStatus.Verified, null, false); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertEquals(id, rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(now.getTime(), rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.Verified.getValue(), rowSet.getString("status")); Assert.assertNotEquals(0, rowSet.getLong("transfer_start")); Assert.assertNotEquals(0, rowSet.getLong("transfer_complete")); Assert.assertNotEquals(0, rowSet.getLong("verify_start")); Assert.assertNotEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(1, rowSet.getInt("retry_count")); Assert.assertEquals(error, rowSet.getString("error_message")); dbService.setStatus(object, ObjectStatus.Error, error, false); rowSet = getRowSet(id); Assert.assertEquals(id, rowSet.getString("source_id")); Assert.assertEquals(id, rowSet.getString("target_id")); Assert.assertFalse(rowSet.getBoolean("is_directory")); Assert.assertEquals(data.length, rowSet.getInt("size")); Assert.assertEquals(now.getTime(), rowSet.getLong("mtime")); Assert.assertEquals(ObjectStatus.Error.getValue(), rowSet.getString("status")); Assert.assertNotEquals(0, rowSet.getLong("transfer_start")); Assert.assertNotEquals(0, rowSet.getLong("transfer_complete")); Assert.assertNotEquals(0, rowSet.getLong("verify_start")); Assert.assertEquals(0, rowSet.getLong("verify_complete")); Assert.assertEquals(1, rowSet.getInt("retry_count")); Assert.assertEquals(error, rowSet.getString("error_message")); }
From source file:com.zousu.mongopresser.Presser.java
public void press() { //get a list of all the tables and columns logger.info("Starting MySQL to Mongo Conversion..."); logger.info("Preparing Tables..."); mySQLHandler.initialiseDatabase();/*from w w w.j a va2 s. c om*/ List<Table> tables = mySQLHandler.getTableList(); for (int i = 0; i < tables.size(); i++) { Table table = tables.get(i); List<Column> columns = table.getColumns(); List<DBObject> dboList = new ArrayList<DBObject>(); SqlRowSet rs = mySQLHandler.selectAllFromTable(table.getTableName()); logger.info("Creating objects for " + table.getTableName() + "..."); while (rs.next()) { BasicDBObject dbo = new BasicDBObject(); for (int j = 0; j < columns.size(); j++) { Column col = columns.get(j); String colName = col.getColumnName(); switch (col.getType()) { case Types.INTEGER: case Types.BIGINT: dbo.append(colName, rs.getInt(colName)); break; case Types.DOUBLE: dbo.append(colName, rs.getDouble(colName)); break; case Types.DATE: dbo.append(colName, rs.getDate(colName)); break; default: dbo.append(colName, rs.getString(colName)); break; } } dboList.add(dbo); } //now insert it logger.info("Inserting " + dboList.size() + " mongo rows into " + table.getTableName() + "..."); table.setNumOfRows(dboList.size()); try { mongoHandler.createCollection(table.getTableName(), true); mongoHandler.batchInsert(dboList, table.getTableName()); assert (mongoHandler.getNumObjectsInCollection(table.getTableName()) == dboList.size()); logger.info(table.getTableName() + " DONE!"); } catch (CollectionExistException e) { e.printStackTrace(); } } logger.info(tables.size() + " collections added!"); //now check go get it from mongo and check if the data there is correct logger.info("Checking mongo consistency..."); for (int i = 0; i < tables.size(); i++) { Table table = tables.get(i); assert (mongoHandler.getNumObjectsInCollection(table.getTableName()) == table.getNumOfRows()); logger.info(table.getTableName() + " consistent!"); } logger.info("MySQL to Mongo Conversion Completed!!!!"); }
From source file:ru.org.linux.spring.SameIPController.java
@RequestMapping("/sameip.jsp") public ModelAndView sameIP(HttpServletRequest request, @RequestParam(required = false) Integer msgid) throws Exception { Template tmpl = Template.getTemplate(request); if (!tmpl.isModeratorSession()) { throw new AccessViolationException("Not moderator"); }/*from w w w. jav a2 s .c om*/ String ip; ModelAndView mv = new ModelAndView("sameip"); int userAgentId = 0; if (msgid != null) { SqlRowSet rs = jdbcTemplate.queryForRowSet("SELECT postip, ua_id FROM topics WHERE id=?", msgid); if (!rs.next()) { rs = jdbcTemplate.queryForRowSet("SELECT postip, ua_id FROM comments WHERE id=?", msgid); if (!rs.next()) { throw new MessageNotFoundException(msgid); } } ip = rs.getString("postip"); userAgentId = rs.getInt("ua_id"); if (ip == null) { throw new ScriptErrorException("No IP data for #" + msgid); } } else { ip = ServletParameterParser.getIP(request, "ip"); } mv.getModel().put("ip", ip); mv.getModel().put("uaId", userAgentId); mv.getModel().put("topics", getTopics(ip)); mv.getModel().put("comments", getComments(ip)); mv.getModel().put("users", getUsers(ip, userAgentId)); IPBlockInfo blockInfo = ipBlockDao.getBlockInfo(ip); Boolean allowPosting = false; Boolean captchaRequired = true; if (blockInfo.isInitialized()) { mv.getModel().put("blockInfo", blockInfo); allowPosting = blockInfo.isAllowRegistredPosting(); captchaRequired = blockInfo.isCaptchaRequired(); mv.getModel().put("blockModerator", userDao.getUserCached(blockInfo.getModerator())); } mv.addObject("allowPosting", allowPosting); mv.addObject("captchaRequired", captchaRequired); mv.getModel().put("tor", IPBlockDao.getTor(ip)); return mv; }
From source file:nl.surfnet.coin.teams.service.impl.GroupProviderServiceSQLImpl.java
private List<ConversionRule> getIdConverters(SqlRowSet sqlRowSet) { Map<Integer, ConversionRule> idConverterMap = new HashMap<Integer, ConversionRule>(); ConversionRule converter;/*from w w w .j av a 2 s. com*/ Integer ruleId; final String id = "id"; final String nameCol = "name"; final String valueCol = "value"; final String name_search = "search"; final String name_replace = "replace"; final String name_property = "property"; while (sqlRowSet.next()) { ruleId = sqlRowSet.getInt(id); if (idConverterMap.containsKey(ruleId)) { converter = idConverterMap.get(ruleId); } else { converter = new ConversionRule(); converter.setPropertyName(id); } final String name = sqlRowSet.getString(nameCol); final String value = sqlRowSet.getString(valueCol); if (name_search.equals(name)) { converter.setSearchPattern(value); } if (name_replace.equals(name)) { converter.setReplaceWith(value); } if (name_property.equals(name)) { converter.setPropertyName(value); } idConverterMap.put(ruleId, converter); } return new ArrayList<ConversionRule>(idConverterMap.values()); }
From source file:com.hygenics.parser.getDAOTemplate.java
/** * Checks for a table schema/*from w w w .ja va 2 s . c om*/ * * @param schema * @return */ public boolean checkSchema(String schema) { String sql = "SELECT count(schema_name) FROM information_schema.schemata WHERE schema_name='" + schema + "'"; SqlRowSet rs = this.jdbcTemplateObject.queryForRowSet(sql); if (rs.next()) { if (rs.getInt(1) > 0) { return true; } } return false; }
From source file:com.hygenics.parser.getDAOTemplate.java
/** * Check Table//w w w . ja v a2 s . c o m */ public boolean checkTable(String table, String schema) { String[] table_split = table.split("\\."); if (table_split.length > 0) { String sql = "SELECT count(table_name) FROM information_schema.tables WHERE table_name='" + table_split[1] + "' AND table_schema='" + schema + "'"; log.info(sql); SqlRowSet rs = this.jdbcTemplateObject.queryForRowSet(sql); if (rs.next()) { if (rs.getInt(1) > 0) { return true; } } } return false; }