List of usage examples for org.apache.commons.dbutils QueryRunner QueryRunner
public QueryRunner(DataSource ds)
DataSource
to use. From source file:de.iritgo.aktario.jdbc.LoadUser.java
/** * Perform the command./*from w w w.j a va 2 s. c om*/ */ public void perform() { if (properties.get("id") == null) { Log.logError("persist", "LoadUser", "Missing unique id for the user to load"); return; } long uniqueId = ((Long) properties.get("id")).longValue(); JDBCManager jdbcManager = (JDBCManager) Engine.instance().getManager("persist.JDBCManager"); DataSource dataSource = jdbcManager.getDefaultDataSource(); try { QueryRunner query = new QueryRunner(dataSource); final User user = (User) query.query("select * from IritgoUser where id=?", new Long(uniqueId), new ResultSetHandler() { public Object handle(ResultSet rs) throws SQLException { if (rs.next()) { User user = new User(rs.getString("name"), rs.getString("email"), rs.getInt("id"), rs.getString("password"), 0); Server.instance().getUserRegistry().addUser(user); Engine.instance().getBaseRegistry().add(user); return user; } else { return null; } } }); if (user == null) { Log.logError("persist", "LoadUser", "Unable to find user with id " + uniqueId); return; } Log.logVerbose("persist", "LoadUser", "Successfully loaded user " + user.getName() + ":" + user.getUniqueId()); } catch (SQLException x) { Log.logError("persist", "LoadUser", "Error while loading the users: " + x); } }
From source file:com.pinterest.arcee.db.DBAsgLifecycleEventDAOImpl.java
@Override public void insertAsgLifecycleEvent(AsgLifecycleEventBean asgLifecycleEventBean) throws Exception { SetClause setClause = asgLifecycleEventBean.genSetClause(); String clause = String.format(INSERT_ASG_LIFE_CYCLE_EVENT, setClause.getClause()); new QueryRunner(dataSource).update(clause, setClause.getValueArray()); }
From source file:com.pinterest.clusterservice.db.DBHostTypeDAOImpl.java
@Override public HostTypeBean getById(String id) throws Exception { ResultSetHandler<HostTypeBean> h = new BeanHandler<HostTypeBean>(HostTypeBean.class); return new QueryRunner(dataSource).query(GET_BY_ID, h, id); }
From source file:com.pinterest.clusterservice.db.DBBaseImageDAOImpl.java
@Override public BaseImageBean getById(String id) throws Exception { ResultSetHandler<BaseImageBean> h = new BeanHandler<BaseImageBean>(BaseImageBean.class); return new QueryRunner(dataSource).query(GET_BY_ID, h, id); }
From source file:com.pinterest.clusterservice.db.DBPlacementDAOImpl.java
@Override public PlacementBean getById(String id) throws Exception { ResultSetHandler<PlacementBean> h = new BeanHandler<PlacementBean>(PlacementBean.class); return new QueryRunner(dataSource).query(GET_BY_ID, h, id); }
From source file:com.pinterest.arcee.db.DBGroupMappingDAOImpl.java
@Override public void insertGroupMapping(String asgGroupName, GroupMappingBean groupMappingsBean) throws Exception { SetClause setClause = groupMappingsBean.genSetClause(); String clause = String.format(INSERT_GROUP_MAPPING, setClause.getClause(), GroupMappingBean.UPDATE_CLAUSE); new QueryRunner(dataSource).update(clause, setClause.getValueArray()); }
From source file:com.example.data.PetData.java
public List<Map<String, Object>> findPetByStatus(String status) throws SQLException { QueryRunner run = new QueryRunner(H2DB.getDataSource()); String[] statues = status.split(","); String statusInStr = StringUtils.join( Arrays.asList(statues).stream().map(s -> "'" + s.trim() + "'").collect(Collectors.toList()), ","); if (statues.length > 0) { return run .query("select * from pet where status in (" + statusInStr + ")", H2DB.mkResultSetHandler("id", "name", "categoryId", "photoUrls", "tags", "status")) .stream().map(m -> {//from w ww.ja v a2 s. co m m.put("photoUrls", H2DB.strToList((String) m.get("photoUrls"))); m.put("tags", H2DB.strToList((String) m.get("tags"))); m.put("category", getCategory(run, (Long) m.get("categoryId"))); m.remove("categoryId"); return m; }).collect(Collectors.toList()); } return Collections.EMPTY_LIST; }
From source file:com.pinterest.deployservice.db.DBHotfixDAOImpl.java
@Override public void insert(HotfixBean bean) throws Exception { SetClause setClause = bean.genSetClause(); String clause = String.format(INSERT_HOTFIX_TEMPLATE, setClause.getClause()); new QueryRunner(dataSource).update(clause, setClause.getValueArray()); }
From source file:com.pinterest.arcee.db.DBImageDAOImpl.java
@Override public void insertOrUpdate(ImageBean amiBean) throws Exception { SetClause setClause = amiBean.genSetClause(); String clause = String.format(INSERT_AMI_TEMPLATE, setClause.getClause(), ImageBean.UPDATE_CLAUSE); new QueryRunner(dataSource).update(clause, setClause.getValueArray()); }
From source file:com.pinterest.clusterservice.db.DBSecurityZoneDAOImpl.java
@Override public SecurityZoneBean getById(String id) throws Exception { ResultSetHandler<SecurityZoneBean> h = new BeanHandler<SecurityZoneBean>(SecurityZoneBean.class); return new QueryRunner(dataSource).query(GET_BY_ID, h, id); }