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 022/** 023 * TableFilter_SEQRESET は、TableFilter インターフェースを継承した、DBTableModel 処理用の 024 * 実装クラスです。 025 * 026 * ここでは、テーブルモデルのシーケンス項目の値を再セットしています。 027 * シーケンスの値は、通常10ずつ増加しますが、BREAK_CLMが指定されており、 028 * かつ、その項目の値がブレイクした場合は、100増加させます。 029 * また、CLEAR_CLMが指定されている場合、そのカラムの値がキーブレイクした場合は、 030 * シーケンス値を初期化(10)にします。 031 * 032 * パラメータは、tableFilterタグの keys, vals にそれぞれ記述するか、BODY 部にCSS形式で記述します。 033 * 【パラメータ】 034 * { 035 * SEQ_CLM : シーケンス項目 036 * BREAK_CLM : キーブレイク項目 (任意) 037 * CLEAR_CLM : シーケンス初期化項目 038 * INCREMENT : シーケンスの増分 (初期値:10) 039 * START_NO : シーケンスの初期値 (初期値:0) 040 * } 041 * 042 * @og.formSample 043 * ●形式: 044 * ① <og:tableFilter classId="SEQRESET" keys="SEQ_CLM,BREAK_CLM" vals="SEQNO,DAIBNRUI" /> 045 * 046 * ② <og:tableFilter classId="SEQRESET" > 047 * { 048 * SEQ_CLM : SEQNO ; 049 * BREAK_CLM : DAIBNRUI ; 050 * } 051 * </og:tableFilter> 052 * 053 * @og.rev 5.6.6.0 (2013/07/05) keys の整合性チェックを追加 054 * 055 * @version 0.9.0 2000/10/17 056 * @author Hiroki Nakamura 057 * @since JDK1.1, 058 */ 059public class TableFilter_SEQRESET extends AbstractTableFilter { 060 /** このプログラムのVERSION文字列を設定します。 {@value} */ 061 private static final String VERSION = "6.4.1.1 (2016/01/16)" ; 062 063 /** 064 * デフォルトコンストラクター 065 * 066 * @og.rev 6.4.1.1 (2016/01/16) keysMap を、サブクラスから設定させるように変更。 067 */ 068 public TableFilter_SEQRESET() { 069 super(); 070 initSet( "SEQ_CLM" , "シーケンス項目" ); 071 initSet( "BREAK_CLM" , "キーブレイク項目" ); 072 initSet( "CLEAR_CLM" , "シーケンス初期化項目" ); 073 initSet( "INCREMENT" , "シーケンスの増分(初期値:10)" ); 074 initSet( "START_NO" , "シーケンスの初期値(初期値:0)" ); 075 } 076 077 /** 078 * DBTableModel処理を実行します。 079 * 080 * @og.rev 4.3.7.0 (2009/06/01) 新規追加 081 * @og.rev 5.5.2.6 (2012/05/25) protected変数を、private化したため、getterメソッドで取得するように変更 082 * 083 * @return 処理後のテーブルモデル 084 */ 085 public DBTableModel execute() { 086 final DBTableModel table = getDBTableModel(); // 5.5.2.6 (2012/05/25) インターフェースにgetterメソッド追加 087 088 // 6.3.9.1 (2015/11/27) A method should have only one exit point, and that should be the last statement in the method.(PMD) 089 final int seqNo = table.getColumnNo( getValue( "SEQ_CLM" ),false ); 090 if( seqNo >= 0 ) { 091 final int breakNo = table.getColumnNo( getValue( "BREAK_CLM" ),false ); 092 final int clearNo = table.getColumnNo( getValue( "CLEAR_CLM" ),false ); 093 final int incNo = StringUtil.nval( getValue( "INCREMENT" ), 10 ); 094 final int startNo = StringUtil.nval( getValue( "START_NO" ), 0 ); 095 096 int seq = startNo; 097 String preKey = ""; 098 String cleKey = ""; 099 for( final int row : getParameterRows() ) { // 6.3.9.1 (2015/11/27) final int[] rowNo の処理 100 final String[] data = table.getValues( row ); // ※ 副作用で処理しているので、改善が必要。 101 102 if( clearNo >= 0 && cleKey != null && cleKey.length() > 0 && !cleKey.equals( data[clearNo] ) ) { 103 seq = startNo; 104 } 105 106 if( breakNo >= 0 && preKey != null && preKey.length() > 0 && !preKey.equals( data[breakNo] ) ) { 107 seq += incNo * 10; 108 } 109 else { 110 seq += incNo; 111 } 112 113 data[seqNo] = String.valueOf( seq ); 114 115 if( breakNo >= 0 ) { 116 preKey = data[breakNo]; 117 } 118 119 if( clearNo >= 0 ) { 120 cleKey = data[clearNo]; 121 } 122 } 123 } 124 return table; 125 } 126}