public QNameFilter mapRow(ResultSet rs, int rowNum) throws SQLException { QNameFilter filter = new QNameFilter(); filter.setId(rs.getLong("id")); filter.setName(rs.getString("name")); filter.setWorkspaceId(rs.getLong("workspace_id")); return filter; }
@Override protected SqlParameterSource toInsertData(QNameFilter object) { final MapSqlParameterSource ps = new MapSqlParameterSource(); ps.addValue("name", object.getName()); ps.addValue("workspace_id", object.getWorkspaceId()); return ps; }
@Override public void update(QNameFilter filter) { jt.update( "update " + this.tableName + " set name = ? where id = ?", filter.getName(), filter.getId()); jt.update("delete from " + MEMBER_TABLE_NAME + " where filter_id = ?", filter.getId()); insertQnames(filter); }
private void addFilterMembers(QNameFilter filter) { if (filter != null) { final String memberSql = "select text_qname.id, local_name, namespace from " + MEMBER_TABLE_NAME + " inner join text_qname on text_qname.id = qname_id" + " where filter_id=?"; List<Name> names = this.jt.query(memberSql, new QnameMapper(), filter.getId()); filter.setQNames(new HashSet<Name>(names)); } }
private void insertQnames(QNameFilter filter) { if (filter.getQNames().size() > 0) { final List<SqlParameterSource> batch = new ArrayList<SqlParameterSource>(); for (Name qname : filter.getQNames()) { MapSqlParameterSource ps = new MapSqlParameterSource(); ps.addValue("filter_id", filter.getId()); ps.addValue("qname_id", ((RelationalName) qname).getId()); batch.add(ps); } this.memberInsert.executeBatch(batch.toArray(new SqlParameterSource[batch.size()])); } }
@Override public long create(QNameFilter filter) { Long id = super.create(filter); filter.setId(id); insertQnames(filter); return id; }
@Override public void delete(QNameFilter filter) { final String sql = "delete from " + this.tableName + " where id=?"; this.jt.update(sql, filter.getId()); }