/** 扩展基类的preDelete方法,对实际业务做删除前的检验 */ public int preDelete( SessionContext ctx, DatabaseConnection conn, FormInstance instance, ErrorMessages msgs, EventManager manager, SqlAssistor assistor) { String cltNo = ctx.getParameter("CLIENTNO"); String bmStr = "select * from bmtable where clientno='" + cltNo + "'"; RecordSet bmRs = conn.executeQuery(bmStr); if (bmRs.next()) { msgs.add("还有业务没有删除"); return -1; } RecordSet rs = conn.executeQuery("select id from CMINDVCLIENT where clientno='" + cltNo + "'"); if (!rs.next()) { msgs.add("取得id失败!"); return -1; } else { String id = rs.getString("ID"); String tempStr = "select * from bmguarantor where id='" + id + "'"; // System.out.println(tempStr); RecordSet tempRs = conn.executeQuery(tempStr); if (tempRs.next()) { msgs.add("还有担保的贷款,不能删除!"); return -1; } } String sql1[] = new String[4]; sql1[0] = "delete from CMINDVRELA where clientno='" + cltNo + "'"; sql1[1] = "delete from CMINDVASSET where clientno='" + cltNo + "'"; // sql1[2] = "delete from CMINDVDEBT where clientno='" + cltNo + "'"; // sql1[3] = "delete from CMINDVDEBTPAYMENT where clientno='" + cltNo + "'"; // String sql2 = ""; for (int i = 0; i < sql1.length; i++) { sql2 += sql1[i] + ";"; } sql2 = sql2.substring(0, sql2.length() - 1); // System.out.println(sql2); int ret = conn.executeUpdate(sql2); return ret; }
public static List<WikiMessage> upgrade070(List<WikiMessage> messages) throws WikiException { TransactionStatus status = null; try { status = DatabaseConnection.startTransaction(getTransactionDefinition()); Connection conn = DatabaseConnection.getConnection(); // add characters_changed column to jam_topic_version WikiBase.getDataHandler() .executeUpgradeUpdate("UPGRADE_070_ADD_TOPIC_VERSION_CHARACTERS_CHANGED", conn); messages.add( new WikiMessage( "upgrade.message.db.column.added", "characters_changed", "jam_topic_version")); // add characters_changed column to jam_recent_change WikiBase.getDataHandler() .executeUpgradeUpdate("UPGRADE_070_ADD_RECENT_CHANGE_CHARACTERS_CHANGED", conn); messages.add( new WikiMessage( "upgrade.message.db.column.added", "characters_changed", "jam_recent_change")); // copy columns from jam_wiki_user_info into jam_wiki_user WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_ADD_USER_EMAIL", conn); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_UPDATE_USER_EMAIL", conn); messages.add(new WikiMessage("upgrade.message.db.column.added", "email", "jam_wiki_user")); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_ADD_USER_EDITOR", conn); messages.add(new WikiMessage("upgrade.message.db.column.added", "editor", "jam_wiki_user")); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_ADD_USER_SIGNATURE", conn); messages.add( new WikiMessage("upgrade.message.db.column.added", "signature", "jam_wiki_user")); WikiBase.getDataHandler().executeUpgradeUpdate("STATEMENT_CREATE_USERS_TABLE", conn); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_INSERT_USERS", conn); messages.add(new WikiMessage("upgrade.message.db.table.added", "jam_users")); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_DROP_USER_REMEMBER_KEY", conn); messages.add( new WikiMessage("upgrade.message.db.column.dropped", "remember_key", "jam_wiki_user")); WikiBase.getDataHandler().executeUpgradeUpdate("STATEMENT_CREATE_AUTHORITIES_TABLE", conn); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_INSERT_AUTHORITIES", conn); messages.add(new WikiMessage("upgrade.message.db.table.added", "jam_authorities")); WikiBase.getDataHandler() .executeUpgradeUpdate("STATEMENT_CREATE_GROUP_AUTHORITIES_TABLE", conn); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_INSERT_GROUP_AUTHORITIES", conn); messages.add(new WikiMessage("upgrade.message.db.table.added", "jam_group_authorities")); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_DROP_ROLE_MAP", conn); messages.add(new WikiMessage("upgrade.message.db.table.dropped", "jam_role_map")); WikiBase.getDataHandler().executeUpgradeUpdate("STATEMENT_CREATE_GROUP_MEMBERS_TABLE", conn); // FIXME - avoid hard coding String sql = "select group_id from jam_group where group_name = '" + WikiGroup.GROUP_REGISTERED_USER + "'"; WikiResultSet rs = DatabaseConnection.executeQuery(sql, conn); int groupId = rs.getInt("group_id"); // FIXME - avoid hard coding sql = "select username from jam_users "; rs = DatabaseConnection.executeQuery(sql, conn); int id = 1; while (rs.next()) { // FIXME - avoid hard coding sql = "insert into jam_group_members ( " + "id, username, group_id " + ") values ( " + id + ", '" + StringEscapeUtils.escapeSql(rs.getString("username")) + "', " + groupId + ") "; DatabaseConnection.executeUpdate(sql, conn); id++; } messages.add(new WikiMessage("upgrade.message.db.table.added", "jam_group_members")); WikiBase.getDataHandler().executeUpgradeUpdate("UPGRADE_070_DROP_USER_INFO", conn); messages.add(new WikiMessage("upgrade.message.db.table.dropped", "jam_wiki_user_info")); } catch (SQLException e) { DatabaseConnection.rollbackOnException(status, e); try { DatabaseConnection.executeUpdate(AnsiQueryHandler.STATEMENT_DROP_GROUP_MEMBERS_TABLE); } catch (Exception ex) { } try { DatabaseConnection.executeUpdate(AnsiQueryHandler.STATEMENT_DROP_GROUP_AUTHORITIES_TABLE); } catch (Exception ex) { } try { DatabaseConnection.executeUpdate(AnsiQueryHandler.STATEMENT_DROP_AUTHORITIES_TABLE); } catch (Exception ex) { } try { DatabaseConnection.executeUpdate(AnsiQueryHandler.STATEMENT_DROP_USERS_TABLE); } catch (Exception ex) { } logger.severe("Database failure during upgrade", e); throw new WikiException(new WikiMessage("upgrade.error.fatal", e.getMessage())); } DatabaseConnection.commit(status); // for some reason HSQL hangs when populating the characters_changed column. since this step is // optional just skip it for HSQL. String dbType = Environment.getValue(Environment.PROP_DB_TYPE); if (!StringUtils.equals(dbType, DataHandler.DATA_HANDLER_HSQL)) { try { // perform a second transaction to populate the new columns. this code is in its own // transaction since if it fails the upgrade can still be considered successful. status = DatabaseConnection.startTransaction(getTransactionDefinition()); Connection conn = DatabaseConnection.getConnection(); WikiBase.getDataHandler() .executeUpgradeUpdate("UPGRADE_070_UPDATE_TOPIC_VERSION_CHARACTERS_CHANGED", conn); messages.add( new WikiMessage( "upgrade.message.db.column.populated", "characters_changed", "jam_topic_version")); } catch (SQLException e) { messages.add(new WikiMessage("upgrade.error.nonfatal", e.getMessage())); // do not throw this error and halt the upgrade process - populating the field // is not required for existing systems. logger.warning( "Failure while populating characters_changed colum in jam_topic_version. See UPGRADE.txt for instructions on how to manually complete this optional step.", e); try { DatabaseConnection.rollbackOnException(status, e); } catch (Exception ex) { // ignore } status = null; // so we do not try to commit } if (status != null) { DatabaseConnection.commit(status); } } return messages; }
public int postInsertOk( SessionContext ctx, DatabaseConnection conn, FormInstance instance, ErrorMessages msgs, EventManager manager) { if (this.isG) { return conn.executeUpdate( "delete from cmguarantor where id='" + ctx.getParameter("ID") + "'"); } if (this.initClientNo == null) { return 0; } MyDB.getInstance().addDBConn(conn); int ret = 0; try { UserManager um = (UserManager) ctx.getAttribute(SystemAttributeNames.USER_INFO_NAME); String OPERATOR = null; OPERATOR = um.getUserName(); String clientno = null; if (this.initClientNo != null) { if (currClientNo == null) { msgs.add("客户号码未发现,请重做交易!"); return -1; } else { ret = ClientMigration.clientMrig(initClientNo, currClientNo, OPERATOR); if (ret >= 0) { /** I comment following line temporarily to speed up perfomance JGO on 20040905 */ // ret = CMClientMan.updateClientCatAndType(currClientNo, OPERATOR); ret = 0; } if (ret < 0) { String msg = PropertyManager.getProperty("" + ret); if (msg == null) { msg = "" + ret; } ctx.setRequestAtrribute("title", "客户信息移行"); ctx.setRequestAtrribute("msg", "处理失败:" + msg); ctx.setRequestAtrribute("flag", "0"); ctx.setTarget("/showinfo.jsp"); } else { ctx.setRequestAtrribute("title", "客户信息移行"); ctx.setRequestAtrribute("msg", "处理成功完成!"); ctx.setRequestAtrribute("flag", "1"); ctx.setTarget("/showinfo.jsp"); } } } } catch (Exception e) { if (Debug.isDebugMode) { e.printStackTrace(); } ret = -1; } finally { MyDB.getInstance().releaseDBConn(); return ret; } }