@Override public int getPsmCount() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); try{ return jdbcTemplate.queryForInt( "SELECT COUNT(*) FROM prideq_psms"); }catch (DataAccessException e){ return 0; } }
@Override public int itemsOnShelf(int shelfNumber) { String sql = String.format("select sum(ITEMS) from PRODUCT_SHELF where SHELF_NUMBER='%s'", shelfNumber); return template.queryForInt(sql); }
@Override public int getProteinCount() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); try{ return jdbcTemplate.queryForInt( "SELECT COUNT(*) FROM prideq_proteins;"); }catch (DataAccessException e){ return 0; } }
private void dropTable(String tableName) { int res = this.jdbcTemplate.queryForInt("select count(*) from user_tables where table_name=?", tableName); if (res > 0) { this.jdbcTemplate.update("DROP TABLE " + tableName); } }
@Override public int getUniquePeptideSequenceCount() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); try{ return jdbcTemplate.queryForInt( "SELECT COUNT(DISTINCT(prots_psms_peptide_sequence)) FROM prideq_prots_psms"); }catch (DataAccessException e){ return 0; } }
/** * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciationBatchDao#getFullyDepreciatedAssetCount() */ public Integer getFullyDepreciatedAssetCount() { int count = getJdbcTemplate().queryForInt("SELECT COUNT(1) FROM CM_CPTLAST_T AST, (SELECT CPTLAST_NBR, (SUM(AST_DEPR1_BASE_AMT - AST_ACUM_DEPR1_AMT) - (SELECT 0.0+CPTLAST_SALVAG_AMT FROM CM_CPTLAST_T X WHERE X.CPTLAST_NBR = Y.CPTLAST_NBR)) BAL FROM CM_AST_PAYMENT_T Y WHERE AST_DEPR1_BASE_AMT IS NOT NULL AND AST_DEPR1_BASE_AMT <> 0.0 AND AST_ACUM_DEPR1_AMT IS NOT NULL AND AST_ACUM_DEPR1_AMT <> 0.0 AND (AST_TRNFR_PMT_CD = 'N' OR AST_TRNFR_PMT_CD = '' OR AST_TRNFR_PMT_CD IS NULL) GROUP BY CPTLAST_NBR) PMT WHERE PMT.BAL = 0.0 AND AST.CPTLAST_NBR = PMT.CPTLAST_NBR"); return count; }
public int getNumberOfActions(Integer tenantId, Integer actionType) { StringBuilder query = new StringBuilder("SELECT count(1) as cnt FROM "); query.append(BaseActionDAO.DEFAULT_TABLE_NAME); query.append(" WHERE ").append(BaseActionDAO.DEFAULT_TENANT_COLUMN_NAME).append("=? ") .append(" AND ").append(BaseActionDAO.DEFAULT_ACTION_TYPE_COLUMN_NAME).append("=?"); final Object[] args = {tenantId, actionType}; final int[] argTypes = {Types.INTEGER, Types.INTEGER}; return getJdbcTemplate().queryForInt(query.toString(), args, argTypes); } }
/** * Determine the number of subscriptions owned by the specified owner. * @param subscriptionOwner the federation-wide unique identifier for the person that owns the subscriptions * @return the count of subscriptions that person owns */ public int countSubscriptionsInSearch(@Header("saml_FederationID") String subscriptionOwner) { String sqlQuery = "select count(*) from subscription where subscriptionOwner=? and active =1"; int subscriptionCountForOwner = this.jdbcTemplate.queryForInt(sqlQuery, new Object[] { subscriptionOwner }); return subscriptionCountForOwner; }
/** * counts the number of rows from a table via jdbc * * @param tableName * name of the table for counting rows * @param condition * additional condition * @return number of rows */ protected int countRowsInTable(String tableName, String condition) { return getJdbcTemplate().queryForInt("select count(*) from " + tableName + " " + condition); }
private Integer retrieveTenantIdOfRecommendationByIdFromDatabase(Integer recommendationId) { StringBuilder query = new StringBuilder("SELECT "); query.append(DEFAULT_TENANT_COLUMN_NAME); query.append(" FROM "); query.append(DEFAULT_TABLE_NAME); query.append(" WHERE "); query.append(DEFAULT_ID_COLUMN_NAME); query.append("=?"); Object[] args = {recommendationId}; int[] argTypes = {Types.INTEGER}; return getJdbcTemplate().queryForInt(query.toString(), args, argTypes); } }
/** * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciationBatchDao#getTransferDocLockedAssetCount() */ public Integer getTransferDocLockedAssetCount() { return getJdbcTemplate().queryForInt("select count(1) from CM_AST_TRNFR_DOC_T t inner join FS_DOC_HEADER_T h on t.fdoc_nbr = h.fdoc_nbr where h.fdoc_status_cd ='" + KFSConstants.DocumentStatusCodes.ENROUTE + "'"); }
/** * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciationBatchDao#getRetireDocLockedAssetCount() */ public Integer getRetireDocLockedAssetCount() { return getJdbcTemplate().queryForInt("select count(1) from CM_AST_RETIRE_DTL_T t inner join FS_DOC_HEADER_T h on t.fdoc_nbr = h.fdoc_nbr where h.fdoc_status_cd ='" + KFSConstants.DocumentStatusCodes.ENROUTE + "'"); }
private int getNewTenantId() { StringBuilder query = new StringBuilder("Select MAX(").append(DEFAULT_ID_COLUMN_NAME).append(") FROM ") .append(DEFAULT_TABLE_NAME); return getJdbcTemplate().queryForInt(query.toString()) + 1; }
public Integer getArchiveSize(String tablename) { StringBuilder sql = new StringBuilder().append(" SELECT").append(" Count(1) as c ").append(" FROM ") .append(tablename); try { return getJdbcTemplate().queryForInt(sql.toString()); } catch (Exception e) { logger.debug(e); return -1; } }
public int queryForIntByMap(String sql,Map<String, Object> parameters){ StringBuffer buf = new StringBuffer(); ArrayList<Object> paraList = getParamArray(sql, parameters, buf); return jdbcTemplate.queryForInt(sql, paraList.toArray()); }
@Override public void execute(Connection conn) { JdbcTemplate jt = JuConnUtils.asJdbcTemplate(conn); jt.execute(String.format("DROP SCHEMA `%s`", schemaInfo.getName())); for (String user : users) { int cnt = jt.queryForInt(String.format("select count(*) from mysql.user where user = '%s'", user)); if (cnt > 0) { jt.execute(String.format("DROP USER `%s`", user)); } } } });
DataSource dataSource = getDataSourceFromSomewhere(); DataSourceTransactionManager tm = new DataSourceTransactionManager(dataSource); JdbcTemplate jdbc = new JdbcTemplate(dataSource); TransactionStatus tx = tm.getTransaction(new DefaultTransactionDefinition()); int update1 = jdbc.update("insert into employee..."); int employeeId = jdbc.queryForInt(select id from employee..."); int update2 = jdbc.update("insert into employee_department..."); if (employeeId > 0 && update2 > 0) tm.commit(tx); else tm.rollback(tx);
/** * Tests if the table TEST_A has been created correctly. */ @Test public final void testA() { List<String> columnNames = this.juDbUtils.getColumnNames("TEST_A"); Assert.assertEquals(3, columnNames.size()); Assert.assertTrue(columnNames.containsAll(JuCollectionUtils.arrayList("AID", "TEXT", "B_FK"))); int cnt = this.jdbcTemplate.queryForInt("select count(*) from test_a"); Assert.assertEquals(3, cnt); }
protected final boolean authenticateUsernamePasswordInternal(final UsernamePasswordCredential credentials) throws AuthenticationException { final String transformedUsername = credentials.getUsername(); final String encyptedPassword = getPasswordEncoder().encode(credentials.getPassword()); final int count = getJdbcTemplate().queryForInt(this.sql, transformedUsername, encyptedPassword); return count > 0; }
@Before public void before() throws SQLException { SimpleJdbcTestUtils.executeSqlScript( new SimpleJdbcTemplate(txContext.getJdbcTemplate()), new ClassPathResource("test.sql"), true); txContext.commitTransactionAndBeginNewOne(); firstExampleEntity = new ExampleEntity(0, "nameInBefore"); txContext.getJdbcTemplate().execute("INSERT INTO EXAMPLEENTITIES (name) VALUES ('" + firstExampleEntity.getName() + "')"); firstExampleEntity.setId(txContext.getJdbcTemplate().queryForInt("SELECT LAST_INSERT_ID()")); }