/** * 中間テーブルを初期化します。 * * @param dbm DBマネージャ * @throws Exception 処理例外 */ public static void clearAccessSpace(IkenshoFirebirdDBManager dbm) throws Exception { try { // ローカルIPに該当するレコードを消去 StringBuffer sb = new StringBuffer(); sb.append(" WHERE"); sb.append("(RECEIPT_ACCESS_SPACE.LOCAL_IP='"); sb.append(getLocalIP()); sb.append("')"); String where = sb.toString(); sb = new StringBuffer(); sb.append("DELETE FROM"); sb.append(" RECEIPT_ACCESS_SPACE"); sb.append(where); dbm.executeUpdate(sb.toString()); sb = new StringBuffer(); sb.append("SELECT"); sb.append(" COUNT(*)"); sb.append(" FROM"); sb.append(" RECEIPT_ACCESS_SPACE"); sb.append(where); dbm.executeQuery(sb.toString()); } catch (Exception ex) { // 存在しなければ作成してみる StringBuffer sb = new StringBuffer(); sb.append("CREATE TABLE"); sb.append(" RECEIPT_ACCESS_SPACE"); sb.append(" ("); sb.append(" LOCAL_IP VARCHAR(30) NOT NULL"); sb.append(",SERIAL_ID INTEGER NOT NULL"); sb.append(",PTID VARCHAR(10)"); sb.append(",NAME VARCHAR(100)"); sb.append(",KANANAME VARCHAR(100)"); sb.append(",SEX CHAR(1)"); sb.append(",BIRTHDAY CHAR(8)"); sb.append(",HOME_POST VARCHAR(7)"); sb.append(",HOME_ADRS VARCHAR(200)"); sb.append(",HOME_BANTI VARCHAR(200)"); sb.append(",HOME_TEL1 VARCHAR(15)"); sb.append(",LAST_TIME TIMESTAMP"); sb.append(",PRIMARY KEY ("); sb.append(" LOCAL_IP"); sb.append(",SERIAL_ID"); sb.append(" )"); sb.append(")"); dbm.executeUpdate(sb.toString()); dbm.commitTransaction(); // コミットしないとCREATEが反映されない dbm.beginTransaction(); } }
/** * SELECT 文を発行する。 * * @param table テーブル名 * @param procedure 発行するプロシージャ名 * @param whereCondition WHERE句マップ * @param splash スプラッシュ * @return 実行結果 * @throws Exception 実行時例外 */ public int executeQuery(String table, String procedure, Map whereCondition, ACSplashable splash) throws Exception { if (!isConnected()) { if (connect() != STATUS_CODE_OK) { return -1; } } if (beginTransaction() != STATUS_CODE_OK) { return -2; } // カーソルを設定 HashMap map = execute(COMMAND_DBSELECT, table, procedure, whereCondition); int count = 1; IkenshoFirebirdDBManager dbm = null; try { dbm = new IkenshoFirebirdDBManager(); dbm.beginTransaction(); // 移行領域をいったんすべて初期化 clearAccessSpace(dbm); // 2006/02/11[Tozo Tanaka] : add begin // TODO canChange? boolean encode = false; String osName = System.getProperty("os.name"); // Mac以外であれば文字コード変換を行う。 if ((osName != null) && (osName.indexOf("Mac") < 0)) { encode = true; } // 2006/02/11[Tozo Tanaka] : add end String ip = getLocalIP(); // 1行ずつ取得 while (true) { map = execute(COMMAND_DBFETCH, table, procedure, whereCondition); if ((map == null) || (map.size() <= 0)) { break; } Object patientName = map.get("tbl_ptinf.NAME"); StringBuffer sb = new StringBuffer(); sb.append("INSERT INTO"); sb.append(" RECEIPT_ACCESS_SPACE"); sb.append(" ("); sb.append(" LOCAL_IP"); sb.append(",SERIAL_ID"); sb.append(",PTID"); sb.append(",NAME"); sb.append(",KANANAME"); sb.append(",SEX"); sb.append(",BIRTHDAY"); sb.append(",HOME_POST"); sb.append(",HOME_ADRS"); sb.append(",HOME_BANTI"); sb.append(",HOME_TEL1"); sb.append(",LAST_TIME"); sb.append(" )"); sb.append(" VALUES"); sb.append(" ("); sb.append("'" + ip + "'"); sb.append(","); sb.append(count++); sb.append(","); sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map.get("tbl_ptinf.PTID"))); sb.append(","); // 2006/02/11[Tozo Tanaka] : replace begin // TODO canChange? // sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(patientName)); // sb.append(","); // sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map // .get("tbl_ptinf.KANANAME"))); // sb.append(","); // sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map // .get("tbl_ptinf.SEX"))); // sb.append(","); // sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map // .get("tbl_ptinf.BIRTHDAY"))); // sb.append(","); // sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map // .get("tbl_ptinf.HOME_POST"))); // sb.append(","); // sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map // .get("tbl_ptinf.HOME_ADRS"))); // sb.append(","); // sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map // .get("tbl_ptinf.HOME_BANTI"))); sb.append( IkenshoConstants.FORMAT_PASSIVE_STRING.format( getORCADecodeString(patientName, encode))); sb.append(","); sb.append( IkenshoConstants.FORMAT_PASSIVE_STRING.format( getORCADecodeString(map.get("tbl_ptinf.KANANAME"), encode))); sb.append(","); sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map.get("tbl_ptinf.SEX"))); sb.append(","); sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map.get("tbl_ptinf.BIRTHDAY"))); sb.append(","); sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map.get("tbl_ptinf.HOME_POST"))); sb.append(","); sb.append( IkenshoConstants.FORMAT_PASSIVE_STRING.format( getORCADecodeString(map.get("tbl_ptinf.HOME_ADRS"), encode))); sb.append(","); sb.append( IkenshoConstants.FORMAT_PASSIVE_STRING.format( getORCADecodeString(map.get("tbl_ptinf.HOME_BANTI"), encode))); // 2006/02/11[Tozo Tanaka] : replace end sb.append(","); sb.append(IkenshoConstants.FORMAT_PASSIVE_STRING.format(map.get("tbl_ptinf.HOME_TEL1"))); sb.append(",CURRENT_TIMESTAMP"); sb.append(")"); dbm.executeUpdate(sb.toString()); if (splash instanceof ACSplash) { // 状況表示 String message = (count - 1) + " 件目"; if (patientName != null) { message += " / " + patientName; } ((ACSplash) splash).setMessage(message); if (splash instanceof ACStopButtonSplash) { if (((ACStopButtonSplash) splash).isStopRequested()) { // 停止要求を監視する break; } } } } dbm.commitTransaction(); } catch (Exception ex) { if (dbm != null) { dbm.rollbackTransaction(); } throw ex; } if (commitTransaction() != STATUS_CODE_OK) { return -3; } return count - 1; }
private void initComponent(VRMap affair) throws Exception { // ウィンドウのサイズ setSize(new Dimension(470, 110)); // ウィンドウを中央に配置 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } this.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); // 保険者一覧をDBから取得・コンボに設定する IkenshoFirebirdDBManager dbm = new IkenshoFirebirdDBManager(); StringBuffer sb = new StringBuffer(); sb.append(" SELECT"); sb.append(" INSURER_NO"); sb.append(" ,INSURER_NM"); sb.append(" FROM"); sb.append(" INSURER"); insurerData = (VRArrayList) dbm.executeQuery(sb.toString()); IkenshoCommon.applyComboModel( insurerNm, new VRHashMapArrayToConstKeyArrayAdapter(insurerData, "INSURER_NM")); // 渡りデータを取得し、各コンポーネントに設定する this.affair = affair; String actParam = String.valueOf(affair.getData("ACT")); if (actParam.equals("update")) { isUpdate = true; } else { isUpdate = false; } if (isUpdate) { submit.setText("更新(S)"); enteredData = (VRArrayList) affair.getData("DATA"); int selRow = Integer.parseInt(String.valueOf(affair.getData("SEL_ROW"))); VRMap row = (VRMap) enteredData.getData(selRow); // 保険者名 String insurerNmParam = String.valueOf(row.getData("INSURER_NM")); for (int i = 0; i < insurerNm.getItemCount(); i++) { if (insurerNm.getItemAt(i).toString().equals(insurerNmParam)) { insurerNm.setSelectedIndex(i); break; } } // 保険者番号 insurerNoOld = String.valueOf(row.getData("INSURER_NO")); insurerNoField.setText(insurerNoOld); // 事業所番号 jigyoushoNoField.setText(String.valueOf(row.getData("JIGYOUSHA_NO"))); } else { submit.setText("登録(S)"); } // スナップショット撮影 IkenshoSnapshot.getInstance().snapshot(); }