📄 sqlworkitemcoder.java
字号:
throw new IllegalArgumentException ("cannot encode list of "+o.getClass()+" instances"); } } protected void encode (final java.sql.Statement st, final Long workitemId, final StringMapAttribute smap) throws java.sql.SQLException, CodingException { final String sWhere = " WHERE "+WID+" = '"+workitemId+"'"; st.addBatch("DELETE FROM "+ATTRIBUTE_TABLE+sWhere); final java.util.Map params = AbstractSqlAttributeCoder.prepareParams (st, workitemId, 0, -1); Long lid = (Long)this.getAttributeCoder(smap) .encode(smap, params); log.debug ("encode() seem to have inserted "+(lid.longValue()+1)+ " attributes"); } protected void encode (final java.sql.Statement st, final Long workitemId, final FilterEntry filterEntry) throws java.sql.SQLException { final java.util.List values = new java.util.ArrayList(FILTER_ENTRY_COLS.length); values.add(workitemId.toString()); values.add(filterEntry.getFieldRegex()); values.add(filterEntry.getPermissions()); //values.add(filterEntry.getAttributeType()); values.add(""); // forget the attribute type for the moment, it // will perhaps be reactivated at a later time // (John) final String sInsert = SqlUtils.buildInsertString (FILTER_ENTRY_TABLE, FILTER_ENTRY_COLS, values); log.debug("addBatch() "+sInsert ); st.addBatch(sInsert); } protected void encode (final java.sql.Statement st, final Long workitemId, final Filter filter) throws java.sql.SQLException { final java.util.List values = new java.util.ArrayList(FILTER_COLS.length); values.add(workitemId.toString()); values.add(filter.getName()); if (filter.getType() == Filter.TYPE_OPEN) values.add("o"); else values.add("c"); if (filter.isAddAllowed()) values.add("t"); else values.add("f"); if (filter.isRemoveAllowed()) values.add("t"); else values.add("f"); final String sInsert = SqlUtils.buildInsertString (FILTER_TABLE, FILTER_COLS, values); log.debug("addBatch() "+sInsert ); st.addBatch(sInsert); java.util.Iterator it = filter.getEntries().iterator(); while (it.hasNext()) { FilterEntry fe = (FilterEntry)it.next(); encode(st, workitemId, fe); } } // // decoding protected InFlowWorkItem decode (final OwfeDataSource ds, final FlowExpressionId lastExpressionId, final long workitemId) throws java.sql.SQLException, CodingException { final String sWhere = WID + " = '" + workitemId + "'"; final String sQuery = SqlUtils.buildQueryString (WORKITEM_TABLE, WORKITEM_COLS, sWhere); final InFlowWorkItem wi = new InFlowWorkItem(); wi.setLastExpressionId(lastExpressionId); java.sql.Statement st = null; java.sql.ResultSet rs = null; try { st = ds.getConnection().createStatement(); rs = st.executeQuery(sQuery); if ( ! rs.next()) { throw new CodingException ("Didn't find any workitem with id "+workitemId+ " for "+lastExpressionId); } wi.setParticipantName(rs.getString(2)); wi.setDispatchTime(rs.getString(3)); wi.setLastModified(rs.getString(4)); } catch (java.sql.SQLException se) { ds.logSQLException( "decode", log, se ); throw new CodingException( "Could not decode() workitemId " + workitemId ); } finally { SqlUtils.closeStatement(st, rs); } //decodeFlowStack(ds, wi, workitemId); decodeAttributes(ds, wi, workitemId); decodeHistory(ds, wi, workitemId); decodeFilter(ds, wi, workitemId); return wi; } /* protected void decodeFlowStack (final OwfeDataSource ds, final InFlowWorkItem wi, final long workitemId) throws java.sql.SQLException, CodingException { log.debug("decodeFlowStack()"); final String sWhere = WID + " = '" + workitemId + "' AND " + "stack_index >= 0"; final String sOrder = "stack_index"; final String sQuery = SqlUtils.buildQueryString (FEI_TABLE, FEI_COLS, sWhere, sOrder); java.sql.Statement st = null; java.sql.ResultSet rs = null; try { final java.util.List flowStack = new java.util.ArrayList(14); st = ds.getConnection().createStatement(); rs = st.executeQuery(sQuery); while (rs.next()) flowStack.add(extractFlowExpressionId(rs)); wi.setFlowStack(flowStack); } catch (java.sql.SQLException se) { ds.logSQLException( "decodeFlowStack", log, se ); throw new CodingException( "Could not decodeFlowStack() flowStack for workitemId " + workitemId ); } finally { SqlUtils.closeStatement(st, rs); } } */ protected void decodeAttributes (final OwfeDataSource ds, final InFlowWorkItem wi, final long workitemId) throws java.sql.SQLException, CodingException { log.debug("decodeAttributes()"); final String sWhere = WID + " = '" + workitemId + "'"; final String sOrder = "id"; final String sQuery = SqlUtils.buildQueryString (ATTRIBUTE_TABLE, ATTRIBUTE_COLS, sWhere, sOrder); java.sql.Statement st = null; java.sql.ResultSet rs = null; try { st = ds.getConnection().createStatement(); rs = st.executeQuery(sQuery); final java.util.List result = new java.util.ArrayList(49); while (rs.next()) result.add(new AttributeRecord(rs)); java.util.Map args = new java.util.HashMap(1); args.put(AbstractSqlAttributeCoder.ARG_ATT_RECORD_LIST, result); // // decode attribute whose id is 0 (root smap) wi.setAttributes ((StringMapAttribute)getAttributeCoder(StringMapAttribute.class) .decode(new Long(0), args)); } catch (java.sql.SQLException se) { ds.logSQLException( "decodeAttributes", log, se ); throw new CodingException( "Could not decodeAttributes() attributes for workitemId " + workitemId ); } finally { SqlUtils.closeStatement(st, rs); } } protected void decodeHistory (final OwfeDataSource ds, final InFlowWorkItem wi, final long workitemId) throws java.sql.SQLException, CodingException { log.debug("decodeHistory()"); final String sWhere = "workitem_id = '" + workitemId + "'"; final String sOrder = "id"; final String sQuery = SqlUtils.buildQueryString (HISTORY_TABLE, HISTORY_COLS, sWhere, sOrder); java.sql.Statement st = null; java.sql.ResultSet rs = null; try { st = ds.getConnection().createStatement(); rs = st.executeQuery(sQuery); final java.util.List history = new java.util.ArrayList(49); while (rs.next()) history.add(extractHistoryItem(rs)); wi.setHistory(history); } catch (java.sql.SQLException se) { ds.logSQLException( "decodeHistory", log, se ); throw new CodingException( "Could not decode() history for workitemId " + workitemId ); } finally { SqlUtils.closeStatement(st, rs); } } protected void decodeFilter (final OwfeDataSource ds, final InFlowWorkItem wi, final long workitemId) throws java.sql.SQLException, CodingException { log.debug("decodeFilter()"); java.sql.Statement st = null; java.sql.ResultSet rs = null; try { // // extract filter itself (if any) final String sWhere = WID + " = '" + workitemId + "'"; String sQuery = SqlUtils.buildQueryString (FILTER_TABLE, FILTER_COLS, sWhere); st = ds.getConnection().createStatement(); rs = st.executeQuery(sQuery); if ( ! rs.next()) return; // no filter for this workitem final Filter filter = extractFilter(rs); try { rs.close(); } catch (java.sql.SQLException se) { // ignore } // // extract filter entries sQuery = SqlUtils.buildQueryString (FILTER_ENTRY_TABLE, FILTER_ENTRY_COLS, sWhere); rs = st.executeQuery(sQuery); final java.util.List entries = new java.util.ArrayList(49); while (rs.next()) entries.add(extractFilterEntry(rs)); filter.setEntries(entries); wi.setFilter(filter); } catch (java.sql.SQLException se) { ds.logSQLException( "decodeFilter", log, se ); throw new CodingException( "Could not decode() filters for workitemId " + workitemId ); } finally { SqlUtils.closeStatement(st, rs); } } // // STATIC METHODS protected static Filter extractFilter (final java.sql.ResultSet rs) throws java.sql.SQLException { final Filter f = new Filter(); int i = 2; f.setName(rs.getString(i++)); final char cType = rs.getString(i++).toLowerCase().charAt(0); if (cType == 'o') f.setType(Filter.TYPE_OPEN); else f.setType(Filter.TYPE_CLOSED); final char cAddAllowed = rs.getString(i++).toLowerCase().charAt(0); f.setAddAllowed(cAddAllowed == 't'); final char cRemoveAllowed = rs.getString(i++).toLowerCase().charAt(0); f.setRemoveAllowed(cRemoveAllowed == 't'); return f; } protected static FilterEntry extractFilterEntry (final java.sql.ResultSet rs) throws java.sql.SQLException { final FilterEntry fe = new FilterEntry(); int i = 2; fe.setFieldRegex(rs.getString(i++)); fe.setPermissions(rs.getString(i++)); //fe.setAttributeType(rs.getString(i++)); // forget it for the moment, it will perhaps be // reactivated at a later time // (John) return fe; } protected static HistoryItem extractHistoryItem (final java.sql.ResultSet rs) throws java.sql.SQLException { final HistoryItem hi = new HistoryItem(); int i = 3; hi.setDate(rs.getString(i++)); hi.setAuthor(rs.getString(i++)); hi.setHost(rs.getString(i++)); hi.setText(rs.getString(i++)); hi.setWorkflowDefinitionName(rs.getString(i++)); hi.setWorkflowDefinitionRevision(rs.getString(i++)); hi.setWorkflowInstanceId(rs.getString(i++)); return hi; } protected static FlowExpressionId extractFlowExpressionId (final java.sql.ResultSet rs) throws java.sql.SQLException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -