001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.plugin.table; 017 018import org.opengion.fukurou.util.StringUtil; 019import org.opengion.hayabusa.db.AbstractTableFilter; 020import org.opengion.hayabusa.db.DBTableModel; 021 022import java.util.Map; 023 024/** 025 * TableFilter_SEQRESET は、TableFilter インターフェースを継承した、DBTableModel 処理用の 026 * 実装クラスです。 027 * 028 * ここでは、テーブルモデルのシーケンス項目の値を再セットしています。 029 * シーケンスの値は、通常10ずつ増加しますが、BREAK_CLMが指定されており、 030 * かつ、その項目の値がブレイクした場合は、100増加させます。 031 * また、CLEAR_CLMが指定されている場合、そのカラムの値がキーブレイクした場合は、 032 * シーケンス値を初期化(10)にします。 033 * 034 * パラメータは、tableFilterタグの keys, vals にそれぞれ記述するか、BODY 部にCSS形式で記述します。 035 * 【パラメータ】 036 * { 037 * SEQ_CLM : シーケンス項目 038 * BREAK_CLM : キーブレイク項目 (任意) 039 * CLEAR_CLM : シーケンス初期化項目 040 * INCREMENT : シーケンスの増分 (初期値:10) 041 * START_NO : シーケンスの初期値 (初期値:0) 042 * } 043 * 044 * @og.formSample 045 * ●形式: 046 * @ <og:tableFilter classId="SEQRESET" keys="SEQ_CLM,BREAK_CLM" vals="SEQNO,DAIBNRUI" /> 047 * 048 * A <og:tableFilter classId="SEQRESET" > 049 * { 050 * SEQ_CLM : SEQNO ; 051 * BREAK_CLM : DAIBNRUI ; 052 * } 053 * </og:tableFilter> 054 * 055 * @og.rev 5.6.6.0 (2013/07/05) keys の整合性チェックを追加 056 * 057 * @version 0.9.0 2000/10/17 058 * @author Hiroki Nakamura 059 * @since JDK1.1, 060 */ 061public class TableFilter_SEQRESET extends AbstractTableFilter { 062 //* このプログラムのVERSION文字列を設定します。 {@value} */ 063 private static final String VERSION = "5.6.6.1 (2013/07/12)" ; 064 065 /** 066 * keys の整合性チェックを行うための初期設定を行います。 067 * 068 * @og.rev 5.6.6.1 (2013/07/12) keys の整合性チェック対応 069 * 070 * @param keysMap keys の整合性チェックを行うための Map 071 */ 072 @Override 073 protected void init( final Map<String,String> keysMap ) { 074 keysMap.put( "SEQ_CLM" , "シーケンス項目" ); 075 keysMap.put( "BREAK_CLM" , "キーブレイク項目" ); 076 keysMap.put( "CLEAR_CLM" , "シーケンス初期化項目" ); 077 keysMap.put( "INCREMENT" , "シーケンスの増分(初期値:10)" ); 078 keysMap.put( "START_NO" , "シーケンスの初期値(初期値:0)" ); 079 } 080 081 /** 082 * DBTableModel処理を実行します。 083 * 084 * @og.rev 4.3.7.0 (2009/06/01) 新規追加 085 * @og.rev 5.5.2.6 (2012/05/25) protected変数を、private化したため、getterメソッドで取得するように変更 086 * 087 * @return 処理後のテーブルモデル 088 */ 089 public DBTableModel execute() { 090 DBTableModel table = getDBTableModel(); // 5.5.2.6 (2012/05/25) インターフェースにgetterメソッド追加 091 092 int seqNo = table.getColumnNo( getValue( "SEQ_CLM" ),false ); 093 int breakNo = table.getColumnNo( getValue( "BREAK_CLM" ),false ); 094 int clearNo = table.getColumnNo( getValue( "CLEAR_CLM" ),false ); 095 String increment = getValue( "INCREMENT" ); 096 String start = getValue( "START_NO" ); 097 098 if( seqNo < 0 ){ return table; } 099 100 int seq = StringUtil.nval( start, 0 ); 101 int inc = StringUtil.nval( increment, 10 ); 102 String[] data = null; 103 String preKey = ""; 104 String cleKey = ""; 105 int[] rowNo = getParameterRows(); // 5.5.2.6 (2012/05/25) インターフェースにgetterメソッド追加 106 for( int row = 0; row < rowNo.length; row ++ ) { 107 data = table.getValues( rowNo[row] ); 108 109 if( clearNo >= 0 && cleKey != null && cleKey.length() > 0 && !cleKey.equals( data[clearNo] ) ) { 110 seq = StringUtil.nval( start, 0 ); 111 } 112 113 if( breakNo >= 0 && preKey != null && preKey.length() > 0 && !preKey.equals( data[breakNo] ) ) { 114 seq += inc * 10; 115 } 116 else { 117 seq += inc; 118 } 119 120 data[seqNo] = String.valueOf( seq ); 121 122 if( breakNo >= 0 ) { 123 preKey = data[breakNo]; 124 } 125 126 if( clearNo >= 0 ) { 127 cleKey = data[clearNo]; 128 } 129 } 130 return table; 131 } 132}