@Override public DomainEntity getDomainDetails(String domainId) { DomainEntity domainEntity = new DomainEntity(); jdbcTemplate.query(SqlDefine.sys_rdbms_084, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { domainEntity.setDomain_id(domainId); domainEntity.setDomain_desc(resultSet.getString("domain_desc")); domainEntity.setDomain_status_desc(resultSet.getString("domain_status_desc")); domainEntity.setMaintance_date(resultSet.getString("maintance_date")); domainEntity.setCreate_user_id(resultSet.getString("create_user_id")); domainEntity.setDomain_modify_user(resultSet.getString("domain_modify_user")); domainEntity.setDomain_modify_date(resultSet.getString("domain_modify_date")); } }, domainId); return domainEntity; }
@Override public Map<String, UserBean> getInformationForUsers(final Collection<String> userIds) { String sql = config.getUserInfo(); if( Check.isEmpty(sql) ) { return null; } final Map<String, UserBean> users = new HashMap<String, UserBean>(); handleIn(sql, userIds, new RowCallbackHandler() { @Override public void processRow(ResultSet set) throws SQLException { String id = set.getString(1); String username = set.getString(2); String fname = set.getString(3); String lname = set.getString(4); String email = set.getString(5); DefaultUserBean user = new DefaultUserBean(id, username, fname, lname, email); users.put(id, user); } }); return users; }
@Override public Pair<ChainResult, Collection<RoleBean>> getRolesForUser(final String userID) { String sql = config.getUserRoles(); if( Check.isEmpty(sql) ) { return null; } final Collection<RoleBean> roles = new ArrayList<RoleBean>(); executeSql(sql, getParamValues(sql, userID), new RowCallbackHandler() { @Override public void processRow(ResultSet set) throws SQLException { String id = set.getString(1); String name = set.getString(2); roles.add(new DefaultRoleBean(id, name)); } }); return new Pair<ChainResult, Collection<RoleBean>>(ChainResult.CONTINUE, roles); }
@Override public Collection<RoleBean> searchRoles(final String query) { String sql = config.getSearchRoles(); if( Check.isEmpty(sql) ) { return null; } final Collection<RoleBean> roles = new ArrayList<RoleBean>(); executeSql(sql, getParamValues(sql, query.replace('*', '%')), new RowCallbackHandler() { @Override public void processRow(ResultSet set) throws SQLException { String id = set.getString(1); String name = set.getString(2); roles.add(new DefaultRoleBean(id, name)); } }); return roles; }
@Override public Map<String, RoleBean> getInformationForRoles(final Collection<String> roleIds) { String sql = config.getRoleInfo(); if( Check.isEmpty(sql) ) { return null; } final Map<String, RoleBean> roles = Maps.newHashMapWithExpectedSize(roleIds.size()); handleIn(sql, roleIds, new RowCallbackHandler() { @Override public void processRow(ResultSet set) throws SQLException { String id = set.getString(1); String name = set.getString(2); roles.put(id, new DefaultRoleBean(id, name)); } }); return roles; }
private UserInfo authenticate(String username) { String sql = config.getAuthenticate(); final UserInfo user = new UserInfo(); executeSql(sql, getParamValues(sql, username), new RowCallbackHandler() { @Override public void processRow(ResultSet set) throws SQLException { boolean suspended = set.getInt(3) > 0; if( suspended ) { throw new DisabledException("User suspended"); } String id = set.getString(1); String password = set.getString(2); user.setId(id); user.setPassword(password); } }); return user; }
private Map<String, GroupBean> getGroupInfo(Collection<String> ids) { final Map<String, GroupBean> groupMap = new HashMap<String, GroupBean>(); String sql = config.getGroupInfo(); if( Check.isEmpty(sql) || Check.isEmpty(ids) ) { return groupMap; } handleIn(sql, ids, new RowCallbackHandler() { @Override public void processRow(ResultSet set) throws SQLException { String id = set.getString(1); String name = set.getString(2); GroupBean group = new DefaultGroupBean(id, name); groupMap.put(id, group); } }); return groupMap; }
/** * Load bean definitions from the database via the given SQL string. * @param sql SQL query to use for loading bean definitions. * The first three columns must be bean name, property name and value. * Any join and any other columns are permitted: e.g. * {@code SELECT BEAN_NAME, PROPERTY, VALUE FROM CONFIG WHERE CONFIG.APP_ID = 1} * It's also possible to perform a join. Column names are not significant -- * only the ordering of these first three columns. */ public void loadBeanDefinitions(String sql) { Assert.notNull(this.jdbcTemplate, "Not fully configured - specify DataSource or JdbcTemplate"); final Properties props = new Properties(); this.jdbcTemplate.query(sql, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String beanName = rs.getString(1); String property = rs.getString(2); String value = rs.getString(3); // Make a properties entry by combining bean name and property. props.setProperty(beanName + "." + property, value); } }); this.propReader.registerBeanDefinitions(props); }
@Override public List<GroupTaskEntity> getJobList(String groupId) { List<GroupTaskEntity> list = new ArrayList<>(); jdbcTemplate.query(batchSqlText.getSql("sys_rdbms_133"), new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { GroupTaskEntity one = new GroupTaskEntity(); one.setCodeNumber(resultSet.getString("code_number")); one.setDomainId(resultSet.getString("domain_id")); one.setGroupId(resultSet.getString("group_id")); one.setJobKey(resultSet.getString("job_key")); one.setPosTop(resultSet.getInt("pos_top")); one.setTaskId(resultSet.getString("task_id")); one.setTaskType(resultSet.getString("task_type")); one.setTaskTypeDesc(resultSet.getString("task_type_desc")); one.setTaskDesc(resultSet.getString("task_type_desc")); one.setPosLeft(resultSet.getInt("pos_left")); list.add(one); } }, groupId); logger.debug("group id is:{},result is:{}", groupId, list); return list; }
@Test public void testQueryWithRowCallbackHandlerNoParameters() throws SQLException { given(resultSet.next()).willReturn(true, false); given(resultSet.getInt("id")).willReturn(1); given(resultSet.getString("forename")).willReturn("rod"); final List<Customer> customers = new LinkedList<Customer>(); namedParameterTemplate.query(SELECT_NO_PARAMETERS, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { Customer cust = new Customer(); cust.setId(rs.getInt(COLUMN_NAMES[0])); cust.setForename(rs.getString(COLUMN_NAMES[1])); customers.add(cust); } }); assertEquals(1, customers.size()); assertTrue("Customer id was assigned correctly", customers.get(0).getId() == 1); assertTrue("Customer forename was assigned correctly", customers.get(0).getForename().equals("rod")); verify(connection).prepareStatement(SELECT_NO_PARAMETERS); verify(preparedStatement).close(); verify(connection).close(); }
@Override public RegressionModel findOne(String id) { final List<RegressionModel> models = new ArrayList<>(); jdbcTemplate.query(SELECT_MODEL.replaceFirst("@", id), new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { RegressionModel m = new RegressionModel(); try { m.deserializeClassifierFromJson(rs.getString(1)); //m.setLongId(rs.getLong(2)); m.setStringId(rs.getString(2)); m.setGeneratedOn(rs.getDate(3).getTime()); models.add(m); } catch (IOException e) { throw new SQLException("Unable to deserialze model from string", e); } } }); return models.isEmpty() ? null : models.get(0); }
@Override public UserInfo findUserByUserName(String userName) { // TODO Auto-generated method stub String sql = "select * from user_info where user_name = ?"; final UserInfo user = new UserInfo(); jdbcTemplate.query(sql, new Object[]{userName}, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { // TODO Auto-generated method stub if (rs.next()) { user.setUserId(rs.getLong("user_id")); user.setUserName(rs.getString("user_name")); } } }); if (user.getUserId() == 0) { return null; } return user; }
@Override public List<OrderItem> queryOrderItems() { // TODO Auto-generated method stub String sql = "SELECT * FROM ORDER_ITEM"; final List<OrderItem> list = new ArrayList<OrderItem>(); jdbcTemplate.query(sql, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { // TODO Auto-generated method stub OrderItem item = new OrderItem(); item.setItemId(rs.getLong("ITEM_ID")); item.setGroupId(rs.getLong("GROUP_ID")); item.setStatus(rs.getInt("STATUS")); item.setItemCode(rs.getString("ITEM_CODE")); item.setItemName(rs.getString("ITEM_NAME")); item.setItemPrice(rs.getFloat("ITEM_PRICE")); item.setCreateDate(rs.getTimestamp("CREATE_DATE")); item.setItemPicurl(rs.getString("ITEM_PICURL")); item.setItemDetails(rs.getString("ITEM_DETAILS")); list.add(item); } }); return list; }
@Override public List<FoodInfo> selectFoods() { String sql = "select food_id, food_name, food_price from food_info"; final List<FoodInfo> list = new ArrayList<FoodInfo>(); jdbcTemplate.query(sql, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { FoodInfo info = new FoodInfo(); info.setFoodId(rs.getLong("food_id")); info.setFoodName(rs.getString("food_name")); info.setFoodPrice(rs.getFloat("food_price")); list.add(info); } }); return list; }
@Override public Map<String, Set<String>> getOrganisationUnitDataSetAssocationMap() { final String sql = "select ds.uid as ds_uid, ou.uid as ou_uid from datasetsource d " + "left join organisationunit ou on ou.organisationunitid=d.sourceid " + "left join dataset ds on ds.datasetid=d.datasetid"; final SetMap<String, String> map = new SetMap<>(); jdbcTemplate.query( sql, new RowCallbackHandler() { @Override public void processRow( ResultSet rs ) throws SQLException { String dataSetId = rs.getString( "ds_uid" ); String organisationUnitId = rs.getString( "ou_uid" ); map.putValue( organisationUnitId, dataSetId ); } } ); return map; }
@Override public User getUserByLogin(String username, String password) { String sqlStr = "select * from tuser where username=? and password=?"; final User user = new User(); jdbc.query(sqlStr,new Object[]{username,password},new RowCallbackHandler(){ @Override public void processRow(ResultSet resultSet) throws SQLException { user.setUid(resultSet.getInt("uid")); user.setUsername(resultSet.getString("username")); user.setPassword(resultSet.getString("password")); } }); return user; }
/** {@inheritDoc} */ @Override public void loadCache(final IgniteBiInClosure<Long, Person> clo, Object... args) { if (args == null || args.length == 0 || args[0] == null) throw new CacheLoaderException("Expected entry count parameter is not provided."); int entryCnt = (Integer)args[0]; final AtomicInteger cnt = new AtomicInteger(); jdbcTemplate.query("select * from PERSON limit ?", new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3)); clo.apply(person.id, person); cnt.incrementAndGet(); } }, entryCnt); System.out.println(">>> Loaded " + cnt + " values into cache."); }
private Map<Long, Long> queryBookedBookablePackageIds(Collection<Long> userIds) { final Map<Long, Long> packageIdsMap = new HashMap<Long, Long>(); String sql = "SELECT A.UserId, A.Id AS PackageId " + "FROM SG_SubjectOrderPackage A " + "INNER JOIN SG_SubjectSku B ON A.SkuId=B.Id " + "INNER JOIN SG_BookedCourse C ON A.Id=C.PackageId " + "INNER JOIN SG_CourseSku D ON C.CourseSkuId=D.Id " + "WHERE A.UserId IN (" + StringUtils.join(userIds, ",") + ") AND A.BookableCount>0 AND A.Status=1 AND B.Status<>0 AND C.Status<>0 AND D.Status<>0 " + "ORDER BY D.StartTime ASC"; query(sql, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { long userId = rs.getLong("userId"); long packageId = rs.getLong("packageId"); if (!packageIdsMap.containsKey(userId)) packageIdsMap.put(userId, packageId); } }); return packageIdsMap; }
private Map<Long, Long> queryNotBookedBookablePackageIds(Collection<Long> userIds) { final Map<Long, Long> packageIdsMap = new HashMap<Long, Long>(); String sql = "SELECT A.UserId, A.Id AS PackageId " + "FROM SG_SubjectOrderPackage A " + "INNER JOIN SG_SubjectSku B ON A.SkuId=B.Id " + "LEFT JOIN SG_BookedCourse C ON A.Id=C.PackageId AND C.Status<>0 " + "WHERE A.UserId IN (" + StringUtils.join(userIds, ",") + ") AND A.BookableCount>0 AND A.Status=1 AND B.Status<>0 AND C.Id IS NULL"; query(sql, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { long userId = rs.getLong("userId"); long packageId = rs.getLong("packageId"); if (!packageIdsMap.containsKey(userId)) packageIdsMap.put(userId, packageId); } }); return packageIdsMap; }
@Override public Set<Integer> getOrderPackageTypes(long orderId) { final Set<Integer> packageTypes = new HashSet<Integer>(); String sql = "SELECT B.CourseId, C.Type FROM SG_SubjectOrderPackage A INNER JOIN SG_SubjectSku B ON A.SkuId=B.Id INNER JOIN SG_Subject C ON B.SubjectId=C.Id WHERE A.OrderId=? AND A.Status<>0 AND B.Status<>0 AND C.Status<>0"; query(sql, new Object[] { orderId }, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { long courseId = rs.getLong("CourseId"); int type = rs.getInt("Type"); if (type == Subject.Type.TRIAL) { packageTypes.add(OrderPackage.Type.TRIAL); } else if (courseId > 0) { packageTypes.add(OrderPackage.Type.SINGLE_COURSE); } else { packageTypes.add(OrderPackage.Type.PACKAGE); } } }); return packageTypes; }
@Override public ChildRecord getRecord(long teacherUerId, long childId, long courseId, long courseSkuId) { final List<ChildRecord> records = new ArrayList<ChildRecord>(); String sql = "SELECT Tags, Content FROM SG_ChildRecord WHERE TeacherUserId=? AND ChildId=? AND CourseId=? AND CourseSkuId=? AND Status=1 LIMIT 1"; query(sql, new Object[] { teacherUerId, childId, courseId, courseSkuId }, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { ChildRecord record = new ChildRecord(); List<Integer> tags = new ArrayList<Integer>(); for (String tagId : Splitter.on(",").trimResults().omitEmptyStrings().split(rs.getString("Tags"))) { tags.add(Integer.valueOf(tagId)); } record.setTags(tags); record.setContent(rs.getString("Content")); records.add(record); } }); return records.isEmpty() ? ChildRecord.EMPTY_RECORD : records.get(0); }
@POST @Path("{sourceKey}/resolveConceptSetExpression") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Collection<Long> resolveConceptSetExpression(@PathParam("sourceKey") String sourceKey, ConceptSetExpression conceptSetExpression) { Source source = getSourceRepository().findBySourceKey(sourceKey); String tqName = "cdm_database_schema"; String tqValue = source.getTableQualifier(SourceDaimon.DaimonType.Vocabulary); ConceptSetExpressionQueryBuilder builder = new ConceptSetExpressionQueryBuilder(); String query = builder.buildExpressionQuery(conceptSetExpression); PreparedStatementRenderer psr = new PreparedStatementRenderer(source, query, tqName, tqValue); final ArrayList<Long> identifiers = new ArrayList<>(); getSourceJdbcTemplate(source).query(psr.getSql(), psr.getSetter(), new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { identifiers.add(rs.getLong("CONCEPT_ID")); } }); return identifiers; }
@Override public void findAll(Timestamp modifiedAfter, final Consumer consumer) { String sql = "SELECT * FROM ORDERS where orders.update_time >= ?"; getJdbcTemplate().query(sql, new Object[] { modifiedAfter }, new RowCallbackHandler() { @Override public void processRow(ResultSet row) throws SQLException { Order order = new Order(); order.setOrderId(row.getLong("order_id")); order.setNote(row.getString("note")); order.setSaleCode(row.getInt("sale_code")); Date createTime = new java.util.Date(row.getTimestamp("create_time").getTime()); order.setCreateTime(createTime); Date updateTime = new java.util.Date(row.getTimestamp("update_time").getTime()); order.setUpdateTime(updateTime); consumer.consume(order); } }); }
/** * Return a mapping * * {labelListValue : {labelId : labelListValueId}} * * @param labelListValues * @return */ public Map<String, Map<Integer, Integer>> findLabelListValueMapping(List<String> labelListValues) { if (labelListValues.isEmpty()) { return Collections.emptyMap(); } final Map<String, Map<Integer, Integer>> res = new HashMap<>(); jdbc.query(queries.findLabelListValueMapping(), new MapSqlParameterSource("values", labelListValues), new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String name = rs.getString("CARD_LABEL_LIST_VALUE"); if (!res.containsKey(name)) { res.put(name, new HashMap<Integer, Integer>()); } res.get(name).put(rs.getInt("CARD_LABEL_ID_FK"), rs.getInt("CARD_LABEL_LIST_VALUE_ID")); } }); return res; }
/** * * @param tcKey * @return */ public String getTcValueBytcKey(String tcKey) { String sql = " select tc_value from t_uitest_cases where tc_key=? "; Object params[] = new Object[] { tcKey }; final String[] tcValue = { "" }; System.out.println(jdbcTemplate); jdbcTemplate.query(sql, params, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { tcValue[0] = rs.getString("tc_value"); } }); return tcValue[0]; }
@Override public Map<Long, Payload> findPayloadByExecutionIds(Long... ids) { String qMarks = StringUtils.repeat("?", ",", ids.length); String sqlStat = QUERY_PAYLOAD_BY_EXECUTION_IDS.replace(":IDS", qMarks); final Map<Long, Payload> result = new HashMap<>(); findPayloadByExecutionIdsJDBCTemplate.query(sqlStat, ids, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { result.put( resultSet.getLong(1), new Payload(resultSet.getBytes("payload")) ); } }); return result; }
/** * {@inheritDoc} */ public int[] countMatchingAlarmsBySeverity(AlarmCriteria criteria) { String selectClause = "SELECT SEVERITY, COUNT(ALARMID) AS ALARMCOUNT FROM ALARMS LEFT OUTER JOIN NODE USING (NODEID) LEFT OUTER JOIN SERVICE USING (SERVICEID) "; String sql = getSql(selectClause, criteria); sql = sql + " GROUP BY SEVERITY"; final int[] alarmCounts = new int[8]; jdbc().query(sql, paramSetter(criteria), new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { int severity = rs.getInt("SEVERITY"); int alarmCount = rs.getInt("ALARMCOUNT"); alarmCounts[severity] = alarmCount; } }); return alarmCounts; }
/** {@inheritDoc} */ public int[] countMatchingEventsBySeverity(EventCriteria criteria) { String selectClause = "SELECT EVENTSEVERITY, COUNT(*) AS EVENTCOUNT FROM EVENTS LEFT OUTER JOIN NODE USING (NODEID) LEFT OUTER JOIN SERVICE USING (SERVICEID) "; String sql = getSql(selectClause, criteria); //sql = sql + " AND EVENTDISPLAY='Y'"; sql = sql + " GROUP BY EVENTSEVERITY"; final int[] alarmCounts = new int[8]; jdbc().query(sql, paramSetter(criteria), new RowCallbackHandler(){ public void processRow(ResultSet rs) throws SQLException { int severity = rs.getInt("EVENTSEVERITY"); int alarmCount = rs.getInt("EVENTCOUNT"); alarmCounts[severity] = alarmCount; } }); return alarmCounts; }
public AuthoritativeResource load(final String source) { final SortedRangeSet<Asn, AsnRange> autNums = new SortedRangeSet<>(); final SortedRangeSet<Ipv4, Ipv4Range> inetnums = new SortedRangeSet<>(); final SortedRangeSet<Ipv6, Ipv6Range> inet6nums = new SortedRangeSet<>(); jdbcTemplate.query("SELECT resource FROM authoritative_resource WHERE source = ?", new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { String resource = rs.getString(1); if (resource.startsWith("AS")) { autNums.add(resource.contains("-") ? AsnRange.parse(resource) : Asn.parse(resource).asRange()); } else if (resource.indexOf(':') >= 0) { inet6nums.add(Ipv6Range.parse(resource)); } else { inetnums.add(Ipv4Range.parse(resource)); } } }, source); return new AuthoritativeResource(autNums, inetnums, inet6nums); }
private Set<String> getAll(String roleId) { Set<String> set = new HashSet<>(); jdbcTemplate.query(SqlDefine.sys_rdbms_100, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { set.add(resultSet.getString("res_id")); } }, roleId); return set; }
@Override public Set<String> findAll(String userId) { Set<String> set = new HashSet<>(); jdbcTemplate.query(SqlDefine.sys_rdbms_115, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { set.add(resultSet.getString("res_id")); } }, userId); return set; }
@Override public RoleEntity getDetails(String roleId) { RoleEntity roleEntity = new RoleEntity(); jdbcTemplate.query(SqlDefine.sys_rdbms_208, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { roleEntity.setDomain_id(resultSet.getString("domain_id")); roleEntity.setRole_id(resultSet.getString("role_id")); roleEntity.setCode_number(resultSet.getString("code_number")); roleEntity.setRole_name(resultSet.getString("role_name")); roleEntity.setDomain_desc(resultSet.getString("domain_desc")); } }, roleId); return roleEntity; }
@Override public GroupBean getParentGroupForGroup(final String groupID) { String sql = config.getParentGroup(); if( Check.isEmpty(sql) ) { return null; } final UserInfo groupInfo = new UserInfo(); final Object[] ids = getParamValues(sql, groupID); executeSql(sql, ids, new RowCallbackHandler() { @Override public void processRow(ResultSet set) throws SQLException { String groupId = set.getString(1); String groupName = set.getString(2); groupInfo.setId(groupId); groupInfo.setPassword(groupName); } }); if( groupInfo.getId() == null ) { return null; } return new DefaultGroupBean(groupInfo.getId(), groupInfo.getPassword()); }
private List<String> getIds(String sql, Object[] values) { final List<String> ids = new ArrayList<String>(); executeSql(sql, values, new RowCallbackHandler() { @Override public void processRow(ResultSet set) throws SQLException { ids.add(set.getString(1)); } }); return ids; }
private Set<String> getAll(String roleId) { Set<String> set = new HashSet<>(); jdbcTemplate.query(sqlText.getSql("sys100"), new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { set.add(resultSet.getString("res_id")); } }, roleId); return set; }
@Override public Set<String> findAll(String userId) { Set<String> set = new HashSet<>(); jdbcTemplate.query(sqlText.getSql("sys115"), new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { set.add(resultSet.getString("res_id")); } }, userId); return set; }