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     */
016    package org.opengion.hayabusa.taglib;
017    
018    import org.opengion.hayabusa.common.HybsSystem;
019    import org.opengion.hayabusa.common.HybsSystemException;
020    import org.opengion.hayabusa.resource.ResourceManager;
021    import org.opengion.hayabusa.resource.GUIInfo;
022    import org.opengion.hayabusa.db.DBColumn;
023    import org.opengion.fukurou.db.Transaction;
024    import org.opengion.fukurou.db.TransactionReal;
025    import org.opengion.fukurou.util.FileUtil;
026    import org.opengion.fukurou.util.ErrorMessage;
027    import org.opengion.fukurou.util.StringUtil;
028    import org.opengion.fukurou.util.Closer ;
029    import org.opengion.fukurou.model.Formatter;
030    import org.opengion.fukurou.model.ArrayDataModel;
031    
032    import static org.opengion.fukurou.util.StringUtil.nval ;
033    
034    import java.sql.Connection;
035    import java.sql.PreparedStatement;
036    import java.sql.SQLException;
037    
038    import java.io.File;
039    import java.io.BufferedReader;
040    import java.io.IOException;
041    
042    /**
043     * æŒ?®šã?ファイルを直接ãƒ??タベã?スã«ç™»éŒ²ã™ã‚‹ãƒ??タ入力タグã§ã™ã?
044     *
045     * 通常㮠readTable ãªã©ã¯ã€DBTableModelオブジェクトを介ã—ã¦å…¨ä»¶ãƒ¡ãƒ¢ãƒªã«
046     * ロードã—ã¦ã‹ã‚‰è¡¨ç¤ºã•ã›ã‚‹ç‚ºã€å¤§é‡ãƒ‡ãƒ¼ã‚¿å‡¦ç?Œã§ãã¾ã›ã‚“ã€?
047     * ã“ã?ã‚¿ã‚°ã§ã¯ã€ç›´æŽ¥ãƒ•ァイルを読ã¿å–りãªãŒã‚‰ãƒ??タベã?ス登録ã™ã‚‹ã®ã§
048     * 大é‡ãƒ‡ãƒ¼ã‚¿ã‚’ãƒãƒ?ƒçš?«ç™»éŒ²ã™ã‚‹å ´åˆã«ä½¿ç”¨ã—ã¾ã™ã?
049     *
050     * 読ã¿å–るファイルã¯ã€å?é ­(ã¾ãŸã?実データãŒç¾ã‚Œã‚‹ã¾ã§ã«) #NAME 行ãŒå¿?¦ã§ã™ã?
051     * ã“れã¯ã€ãƒ•ァイルãƒ??ã‚¿ã®ã‚«ãƒ©ãƒ?を指定ã—ã¦ã?¾ã™ã?ã¾ãŸã?columns 属æ?を使用ã™ã‚Œã°ã€?
052     * ファイルã®#NAME 行より優先ã—ã¦(ã¤ã¾ã‚Šå­˜åœ¨ã—ã¦ã?ªãã¦ã‚‚良ã?ãƒ??ã‚¿ã®ã‚«ãƒ©ãƒ?ã‚?
053     * æŒ?®šã™ã‚‹ã“ã¨ãŒå?æ¥ã¾ã™ã?
054     * ã“ã?#NAME 行ã?ã€ãƒ•ァイルã®ã‚»ãƒ‘レータã¨ç„¡é–¢ä¿‚ã«å¿?šã‚¿ãƒ–区åˆ?‚Šã§ç”¨æ„ã•れã¦ã?¾ã™ã?
055     * ã‚¿ã‚°ã®BODY部ã«ã€å®Ÿè¡Œã™ã‚‹SQLæ–?‚’記述ã—ã¾ã™ã?
056     * ã“ã?SQLæ–??ã€?
057     * INSERT INTO GE41 (CLM,NAME_JA,SYSTEM_ID,FGJ,DYSET)
058     * VALUES ([CLM],[NAME_JA],[SYSTEM_ID],'1','{@USER.YMDH}')
059     * ã¨ã€ã„ã?„Ÿã˜ã§ã€ãƒ•ァイルã‹ã‚‰èª­ã¿è¾¼ã‚“ã å€¤ã¯ã€[カラãƒ?]ã«å‰²ã‚Šå½“ã¦ã‚‰ã‚Œã¾ã™ã?
060     * ã‚‚ã¡ã‚ã‚“ã€??常ã®å›ºå®šå?(FGJã«'1'ã‚’ã‚»ãƒ?ƒˆ)ã‚??リクエスト変数(DYSETã®{@USER.YMDH})
061     * ãªã©ã‚‚使用ã§ãã¾ã™ã?
062     *
063     * ※ ã“ã?ã‚¿ã‚°ã¯ã€Transaction ã‚¿ã‚°ã®å¯¾è±¡ã§ã™ã?
064     *
065     * @og.formSample
066     * â—å½¢å¼ï¼?lt;og:directTableInsert filename="[?¥?¥?¥]" ?¥?¥?¥ >INSERT INTO ?¥?¥?¥ </og:directTableInsert >
067     * â—body?šã‚ã‚?
068     *
069     * â—Tag定義??
070     *   <og:directTableInsert
071     *       fileURL            ã€TAG】読ã¿å–りå…?ƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªåã‚’æŒ?®šã—ã¾ã?(åˆæœŸå€¤:FILE_URL[=filetemp/])
072     *       filename           ã€TAG】ファイルを作æ?ã™ã‚‹ã¨ãã?ファイルåã‚’ã‚»ãƒ?ƒˆã—ã¾ã?(åˆæœŸå€¤:FILE_FILENAME[=file.xls])
073     *       encode             ã€TAG】ファイルを作æ?ã™ã‚‹ã¨ãã?ファイルエンコーãƒ?‚£ãƒ³ã‚°åã‚’ã‚»ãƒ?ƒˆã—ã¾ã?(åˆæœŸå€¤:FILE_ENCODE[=UnicodeLittle])
074     *       separator          ã€TAG】å¯å¤‰é•·ãƒ•ァイルを作æ?ã™ã‚‹ã¨ãã?é ?›®åŒºåˆ?‚Šæ–?­—ã‚’ã‚»ãƒ?ƒˆã—ã¾ã?åˆæœŸå€¤:ã‚¿ãƒ?
075     *       displayMsg         ã€TAG】query ã®çµæžœã‚’ç”»é¢ä¸Šã«è¡¨ç¤ºã™ã‚‹ãƒ¡ãƒ?‚»ãƒ¼ã‚¸IDを指定ã—ã¾ã?åˆæœŸå€¤:MSG0040[ã€?»¶ç™»éŒ²ã—ã¾ã—ãŸ])
076     *       columns            ã€TAGã€?NAME 属æ?ã®ä»£ã‚りã¨ãªã‚‹ãƒ•ァイルã®ã‚«ãƒ©ãƒ?ã‚?CSVå½¢å¼ã§æŒ?®šã—ã¾ã?
077     *       commitBatch        ã€TAG】指定数毎ã«ã‚³ãƒŸãƒƒãƒˆã‚’発行ã—ã¾ã?åˆæœŸå€¤:0 終äº?¾ã§ã‚³ãƒŸãƒƒãƒˆã—ã¾ã›ã‚“)
078     *       useColumnAdjust    ã€TAG】カラãƒ?¤‰æ›(DBType変æ›)を行ã†ã‹ã©ã?‹ã‚’設定ã—ã¾ã?åˆæœŸå€¤:false)
079     *       useColumnCheck     ã€TAG】カラãƒ?ƒã‚§ãƒ?‚¯(DBTypeãƒã‚§ãƒ?‚¯)を行ã†ã‹ã©ã?‹ã‚’設定ã—ã¾ã?åˆæœŸå€¤:false)
080     *       nullCheck          ã€TAG】NULL ãƒã‚§ãƒ?‚¯ã™ã¹ãカラãƒ??をカンマ区åˆ?‚Š(CSVå½¢å¼?ã§æŒ?®šã—ã¾ã?
081     *       dbid               ã€TAGã€?通常ã¯ä½¿ã?¾ã›ã‚“)検索時ã?DB接続IDを指定ã—ã¾ã?åˆæœŸå€¤:DEFAULT)
082     *       skipRowCount       ã€TAG】データã®èª­ã¿é£›ã?ã—件数を設定ã—ã¾ã?åˆæœŸå€¤:0)
083     *       debug              ã€TAG】デãƒãƒƒã‚°æƒ??ã‚’å?力ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)
084     *   >   ... Body ...
085     *   </og:directTableInsert>
086     *
087     * â—使用ä¾?
088     *     <og:directTableInsert
089     *         dbid         = "ORCL"                接続データベã?スID(åˆæœŸå€¤:DEFAULT)
090     *         separator    = ","                   ファイルã®åŒºåˆ?‚Šæ–?­?åˆæœŸå€¤:ã‚¿ãƒ?
091     *         fileURL      = "{@USER.ID}"     読ã¿å–りå…?ƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªå?
092     *         filename     = "{@filename}"    読ã¿å–りå…?ƒ•ァイルå?
093     *         encode       = "Shift_JIS"           読ã¿å–りå…?ƒ•ァイルエンコードå
094     *         displayMsg   = "MSG0040"             登録完äº?¾Œã?メãƒ?‚»ãƒ¼ã‚¸
095     *         columns      = "CLM,NAME_JA,LABEL_NAME,KBSAKU,SYSTEM_ID,LANG"
096     *                                              #NAME ã®ä»£ã‚りã«ä½¿ç”¨ã™ã‚‹ã‚«ãƒ©ãƒ??å?
097     *         commitBatch  = "100"                 ã“ã?ä»¶æ•°ãšã¤ã‚³ãƒŸãƒƒãƒˆã‚’発è¡?åˆæœŸå€¤:無制é™?
098     *         useColumnCheck  = "true"             カラãƒ?ƒã‚§ãƒ?‚¯ã‚’行ã†ã‹ã©ã?‹(åˆæœŸå€¤:false)
099     *         useColumnAdjust = "true"             カラãƒ?¤‰æ›ã‚’行ã†ã‹ã©ã?‹(åˆæœŸå€¤:false)
100     *         nullCheck       = "CLM,SYSTEM_ID"    NULLãƒã‚§ãƒ?‚¯ã‚’実行ã—ã¾ã™ã?
101     *     >
102     *          INSERT INTO GE41
103     *              (CLM,NAME_JA,LABEL_NAME,KBSAKU,SYSTEM_ID,LANG,
104     *                 FGJ,DYSET,DYUPD,USRSET,USRUPD,PGUPD)
105     *          VALUES
106     *              ([CLM],[NAME_JA],[LABEL_NAME],[KBSAKU],[SYSTEM_ID],[LANG],
107     *                '1','{@USER.YMDH}','{@USER.YMDH}','{@USER.ID}','{@USER.ID}','{@GUI.KEY}')
108     *     </og:directTableInsert >
109     *
110     * @og.group ファイル入�
111     *
112     * @version  4.0
113     * @author   Kazuhiko Hasegawa
114     * @since    JDK5.0,
115     */
116    public class DirectTableInsertTag extends CommonTagSupport {
117            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
118            private static final String VERSION = "5.5.7.1 (2012/10/05)" ;
119    
120            private static final long serialVersionUID = 557120121005L ;
121    
122            private static final String TAB_SEPARATOR = "\t" ;
123    
124            // 4.0.0.0 (2007/10/10) dbid ã®åˆæœŸå€¤ã‚’ã?"DEFAULT" ã‹ã‚‰ null ã«å¤‰æ›´
125    //      private String    dbid                  = "DEFAULT";
126            private String    dbid                  = null;
127            private String    separator             = TAB_SEPARATOR;   // é ?›®åŒºåˆ?‚Šæ–?­?
128            private String    fileURL               = HybsSystem.sys( "FILE_URL" );         // 4.0.0 (2005/01/31)
129            private String    filename              = HybsSystem.sys( "FILE_FILENAME" );   // ファイルå?
130            private String    encode                = HybsSystem.sys( "FILE_ENCODE"   );   // ファイルエンコーãƒ?‚£ãƒ³ã‚°  "JISAutoDetect" ,"JIS", "EUC_JP", "MS932", "SJIS" , "Windows-31J" , "Shift_JIS"
131            private String    displayMsg    = "MSG0040";    // ã€?»¶ç™»éŒ²ã—ã¾ã—ãŸã€?
132            private String[]  columns               = null;
133            private String[]  clmKeys               = null;         // SQLæ–??[カラãƒ?]é…å?
134            private String    sql                   = null;
135            private int               commitBatch   = 0;            // コミットã™ã‚‹ã¾ã¨ã‚ä»¶æ•°
136            private boolean   useColumnCheck  = false;      // 3.6.0.2 (2004/10/04)
137            private boolean   useColumnAdjust = false;      // 3.6.0.2 (2004/10/04)
138            private String[]  nullCheck             = null;         // 3.8.0.2 (2005/06/30) nullãƒã‚§ãƒ?‚¯ç¢ºèª?
139            private long      dyStart               = 0;    // 実行時間測定用ã®DIVè¦ç´?‚’出力ã—ã¾ã™ã?
140            private int       skipRowCount  = 0;    // 5.5.7.1 (2012/10/01)
141    
142            /**
143             * Taglibã®é–‹å§‹ã‚¿ã‚°ãŒè¦‹ã¤ã‹ã£ãŸã¨ãã«å‡¦ç?™ã‚?doStartTag() ã‚?オーãƒã?ライドã—ã¾ã™ã?
144             *
145             * @return      後続å?ç??æŒ?¤º( EVAL_BODY_BUFFERED )
146             */
147            @Override
148            public int doStartTag() {
149                    dyStart = System.currentTimeMillis();           // 時間測定用
150                    return( EVAL_BODY_BUFFERED );   // Body を評価ã™ã‚‹ã€? extends BodyTagSupport æ™?
151            }
152    
153            /**
154             * Taglibã®ã‚¿ã‚°æœ¬ä½“を処ç?™ã‚?doAfterBody() ã‚?オーãƒã?ライドã—ã¾ã™ã?
155             *
156             * @og.rev 3.6.0.2 (2004/10/04) SQLæ–?? [カラãƒ? 対応ã¨ãƒ‘ã?サー機è?追åŠ?
157             * @og.rev 3.8.6.3 (2006/11/30) SQL æ–??å‰å¾Œã?スペã?スをå–り除ãã¾ã™ã?
158             *
159             * @return      後続å?ç??æŒ?¤º(SKIP_BODY)
160             */
161            @Override
162            public int doAfterBody() {
163                    sql = getBodyString();
164                    if( sql == null || sql.length() == 0 ) {
165                            String errMsg = "BODY 部ã®ç™»éŒ²ç”¨ Insert/Updateæ–??ã€å¿??ã§ã™ã?";
166                            throw new HybsSystemException( errMsg );
167                    }
168                    // 3.6.0.2 (2004/10/04) SQLæ–?? [カラãƒ? 対応ã¨ãƒ‘ã?サー機è?追åŠ?
169    //              sql = makeFormat( sql.trim() );         // ã“ã“ã§ã€clmLeys é…å?ã‚‚ã‚»ãƒ?ƒˆã•れるã?
170    
171                    return(SKIP_BODY);                              // Body を評価ã—ãªã?
172            }
173    
174            /**
175             * Taglibã®çµ‚äº?‚¿ã‚°ãŒè¦‹ã¤ã‹ã£ãŸã¨ãã«å‡¦ç?™ã‚?doEndTag() ã‚?オーãƒã?ライドã—ã¾ã™ã?
176             *
177             * @og.rev 4.0.0.0 (2007/10/18) メãƒ?‚»ãƒ¼ã‚¸ãƒªã‚½ãƒ¼ã‚¹çµ±å? getResource().getMessage > getResource().getLabel )
178             *
179             * @return      後続å?ç??æŒ?¤º
180             */
181            @Override
182            public int doEndTag() {
183                    debugPrint();           // 4.0.0 (2005/02/28)
184    
185                    BufferedReader pw = getBufferedReader();
186                    int executeCount = create( pw );
187                    Closer.ioClose( pw );           // 4.0.0 (2006/01/31) close 処ç?™‚ã® IOException ã‚’ç„¡è¦?
188    
189                    // 実行件数ã®è¡¨ç¤º
190                    // 4.0.0 (2005/11/30) 出力é?ã®å¤‰æ›´ã€‚ä¸?•ªæœ??ã«å‡ºåŠ›ã—ã¾ã™ã?
191                    if( displayMsg != null && displayMsg.length() > 0 ) {
192    //                      String status = executeCount + getResource().getMessage( displayMsg ) ;
193                            String status = executeCount + getResource().getLabel( displayMsg ) ;
194                            jspPrint( status + HybsSystem.BR );
195                    }
196    
197                    // 時間測定用㮠DIV è¦ç´?‚’出åŠ?
198                    long dyTime = System.currentTimeMillis()-dyStart;
199                    jspPrint( "<div id=\"queryTime\" value=\"" + (dyTime) + "\"></div>" );      // 3.5.6.3 (2004/07/12)
200    
201                    // 4.0.0 (2005/01/31) セキュリãƒ?‚£ãƒã‚§ãƒ?‚¯(ãƒ??タアクセス件数登録)
202                    GUIInfo guiInfo = (GUIInfo)getSessionAttribute( HybsSystem.GUIINFO_KEY );
203                    if( guiInfo != null ) { guiInfo.addWriteCount( executeCount,dyTime,sql ); }
204    
205                    return(EVAL_PAGE);
206            }
207    
208            /**
209             * タグリブオブジェクトをリリースã—ã¾ã™ã?
210             * キャãƒ?‚·ãƒ¥ã•れã¦å†åˆ©ç”¨ã•れるã?ã§ã€ãƒ•ィールドã?åˆæœŸè¨­å®šã‚’行ã„ã¾ã™ã?
211             *
212             * @og.rev 3.6.0.2 (2004/10/04) useColumnCheck,useColumnAdjust 属æ?追åŠ?
213             * @og.rev 3.8.0.2 (2005/06/30) nullCheck 属æ?追åŠ?
214             * @og.rev 4.0.0.0 (2007/10/10) dbid ã®åˆæœŸå€¤ã‚’ã?"DEFAULT" ã‹ã‚‰ null ã«å¤‰æ›´
215             * @og.rev 5.5.7.1 (2012/10/05) skipRowCount追�
216             */
217            @Override
218            protected void release2() {
219                    super.release2();
220                    dbid                    = null;
221                    separator               = TAB_SEPARATOR;   // é ?›®åŒºåˆ?‚Šæ–?­?
222                    fileURL                 = HybsSystem.sys( "FILE_URL" );         // 4.0.0 (2005/01/31)
223                    filename                = HybsSystem.sys( "FILE_FILENAME"        );   // ファイルå?
224                    encode                  = HybsSystem.sys( "FILE_ENCODE"          );   // ファイルエンコーãƒ?‚£ãƒ³ã‚°  "JISAutoDetect" ,"JIS", "EUC_JP", "MS932", "SJIS" , "Windows-31J" , "Shift_JIS"
225                    displayMsg              = "MSG0040";    // ã€?»¶ç™»éŒ²ã—ã¾ã—ãŸã€?
226                    columns                 = null;         // 3.5.4.5 (2004/01/23)
227                    useColumnCheck  = false;        // 3.6.0.2 (2004/10/04)
228                    useColumnAdjust = false;        // 3.6.0.2 (2004/10/04)
229                    nullCheck               = null;         // 3.8.0.2 (2005/06/30)
230                    skipRowCount    = 0;            // 5.5.7.1 (2012/10/05)
231            }
232    
233            /**
234             * BufferedReader より読ã¿è¾¼ã¿ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ã?ã‚¹ã«æ›¸ãè¾¼ã¿ã¾ã™ã?
235             *
236             * @og.rev 3.6.0.2 (2004/10/04) カラãƒ?‚ªãƒ–ジェクトã?DBType属æ?ã®æ•´åˆæ?ãƒã‚§ãƒ?‚¯
237             * @og.rev 3.8.0.2 (2005/06/30) nullãƒã‚§ãƒ?‚¯ç¢ºèª?
238             * @og.rev 3.8.5.1 (2006/05/08) å–è¾¼ãƒ??ã‚¿ã?name 列より少ãªã??åˆã?対応を追åŠ?
239             * @og.rev 3.8.7.0 (2006/12/15) アクセスログå–å¾—ã?為,ApplicationInfoオブジェクトを設å®?
240             * @og.rev 4.0.0.0 (2005/01/31) CheckColumnDataクラス static 化ã?引数ã«ResourceManager追åŠ?
241             * @og.rev 4.0.0.1 (2007/12/03) try ??catch ??finally ã‚’ãã¡ã‚“ã¨è¡Œã†ã€?
242             * @og.rev 5.1.9.0 (2010/08/01) Transaction 対�
243             * @og.rev 5.2.2.0 (2010/11/01)) ""ã§å›²ã‚れã¦ã?‚‹ãƒ??ã‚¿ã«æ”¹è¡ŒãŒå…¥ã£ã¦ã?Ÿå ´åˆã?対å¿?
244             * @og.rev 5.3.7.0 (2011/07/01) TransactionReal ã®å¼•数変更
245             * @og.rev 5.3.8.0 (2011/08/01) pstmt.setObject ã§ã€useParamMetaData ã®åˆ¤å®šã‚’é¿ã‘ã‚‹ãŸã‚ã€pstmt.setString ã§ä»£ç”¨(PostgreSQL対å¿?
246             * @og.rev 5.5.7.1 (2012/10/05) omitFirstLine対�
247             *
248             * @param   reader BufferedReaderオブジェク�
249             *
250             * @return  å–り込ã¿ä»¶æ•°
251             */
252            private int create( final BufferedReader reader )  {
253    
254                    String[] names = readName( reader );    // ファイルã®ã‚«ãƒ©ãƒ?
255                    int   nameLen = names.length ;                  // 3.8.5.1 (2006/05/08) 追�
256    //              int[] clmNos = getColumnNos( names, clmKeys );  // ãƒã‚¤ãƒ³ãƒ‰å¤‰æ•°ã®ã‚¢ãƒ‰ãƒ¬ã‚¹æ±‚ã‚
257    //              int   clmNosLen = clmNos.length ;
258    
259                    ArrayDataModel nmdata = new ArrayDataModel( names );
260                    Formatter format = new Formatter( nmdata );
261                    format.setFormat( sql.trim() );
262                    sql = format.getQueryFormatString();
263                    int[] clmNos = format.getClmNos();
264                    int   clmNosLen = clmNos.length ;
265                    clmKeys = format.getClmKeys();
266    
267                    CheckColumnData checkClass = new CheckColumnData( clmNos,clmKeys,getResource() );
268    
269                    ArrayDataModel nullData = new ArrayDataModel( names );
270                    int[] nullClmNos = nullData.getColumnNos( nullCheck );  // ãƒã‚¤ãƒ³ãƒ‰å¤‰æ•°ã®ã‚¢ãƒ‰ãƒ¬ã‚¹æ±‚ã‚
271    
272                    // 3.8.0.2 (2005/06/30) nullãƒã‚§ãƒ?‚¯ç¢ºèª?
273    //              int[] nullClmNos = getColumnNos( names, nullCheck );    // ãƒã‚¤ãƒ³ãƒ‰å¤‰æ•°ã®ã‚¢ãƒ‰ãƒ¬ã‚¹æ±‚ã‚
274                    int   nullClmNosLen = nullClmNos.length ;
275    
276                    int    executeCount = 0;
277                    int    commitCount  = 0;
278                    char   sep  = separator.charAt(0);
279                    boolean errFlag  = true;
280    //              Connection  conn = null;
281                    Transaction tran = null;        // 5.1.9.0 (2010/08/01) Transaction 対�
282                    PreparedStatement pstmt = null ;
283                    String[] data   = null ;
284                    int skip = skipRowCount; // 5.5.7.1 (2012/10/05)
285                    try {
286                            // 5.1.9.0 (2010/08/01) Transaction 対�
287                            TransactionTag tranTag = (TransactionTag)findAncestorWithClass( this,TransactionTag.class );
288                            if( tranTag == null ) {
289    //                              tran = new TransactionReal( dbid,getApplicationInfo() );
290                                    tran = new TransactionReal( getApplicationInfo() );             // 5.3.7.0 (2011/07/01) 引数変更
291                            }
292                            else {
293                                    tran = tranTag.getTransaction();
294                            }
295    //                      conn = ConnectionFactory.connection( dbid,getApplicationInfo() );       // 3.8.7.0 (2006/12/15)
296    
297    //                      try {
298                                    Connection conn = tran.getConnection( dbid );           // 5.1.9.0 (2010/08/01) Transaction 対�
299                                    pstmt = conn.prepareStatement( sql );
300                                    String line ;
301                                    while((line = reader.readLine()) != null) {
302                                            if( line.length() == 0 || line.charAt( 0 ) == '#' ) { continue; }
303                                            else if( skip > 0 ){ skip--; continue;} // 5.5.7.1 (2012/10/05) 
304                                            else {
305                                                    // 5.2.2.0 (2010/11/01) ""ã§å›²ã‚れã¦ã?‚‹ãƒ??ã‚¿ã«æ”¹è¡ŒãŒå…¥ã£ã¦ã?Ÿå ´åˆã?対å¿?
306                                                    int quotCount = StringUtil.countChar( line, '"' );
307                                                    if( quotCount % 2 != 0 ) {
308                                                            String addLine = null;
309                                                            StringBuilder buf = new StringBuilder( line );
310                                                            while(quotCount % 2 != 0 && (addLine = reader.readLine()) != null) {
311                                                                    if( line.length() == 0 || line.charAt( 0 ) == '#' ) { continue; }
312                                                                    buf.append( HybsSystem.CR ).append( addLine );
313                                                                    quotCount += StringUtil.countChar( addLine, '"' );
314                                                            }
315                                                            line = buf.toString();
316                                                    }
317    
318                                                    // 3.8.5.1 (2006/05/08) å–è¾¼ãƒ??ã‚¿ã?name 列より少ãªã??åˆã?対応を追åŠ?
319                                                    data = StringUtil.csv2Array( line , sep , nameLen );
320    
321                                                    // 3.6.0.2 (2004/10/04) カラãƒ?¤‰æ›
322                                                    if( useColumnAdjust ) {
323                                                            data = checkClass.adjustData( data );
324                                                    }
325    
326                                                    // 3.6.0.2 (2004/10/04) カラãƒ?ƒã‚§ãƒ?‚¯
327                                                    if( useColumnCheck ) {
328                                                            ErrorMessage errMsg = checkClass.checkData( executeCount, data );
329                                                            if( !errMsg.isOK() ) {
330    //                                                              conn.rollback();
331                                                                    tran.rollback();                        // 5.1.9.0 (2010/08/01) Transaction 対�
332                                                                    jspPrint( TaglibUtil.makeHTMLErrorTable( errMsg,getResource() ) );
333                                                                    return commitCount;
334                                                            }
335                                                    }
336    
337                                                    // 3.8.0.2 (2005/06/30) nullãƒã‚§ãƒ?‚¯ç¢ºèª?
338                                                    if( nullClmNosLen > 0 ) {
339                                                            ErrorMessage errMsg = new ErrorMessage( "Null Check Columns Error!" );
340    
341                                                            for( int i=0; i<nullClmNosLen; i++ ) {
342                                                                    int clm = nullClmNos[i];
343                                                                    if( data[clm] == null || data[clm].length() == 0 ) {
344                                                                            String label = getResource().getLabel( nullCheck[i] );
345                                                                            // ERR0012 : æŒ?®šã?ãƒ??ã‚¿ãŒã‚»ãƒ?ƒˆã•れã¦ã?¾ã›ã‚“ã€?NULLエラー)。key={0}
346                                                                            errMsg.addMessage( executeCount+1,ErrorMessage.NG,"ERR0012",label );
347                                                                    }
348                                                            }
349                                                            if( !errMsg.isOK() ) {
350    //                                                              conn.rollback();
351                                                                    tran.rollback();                        // 5.1.9.0 (2010/08/01) Transaction 対�
352                                                                    jspPrint( TaglibUtil.makeHTMLErrorTable( errMsg,getResource() ) );
353                                                                    return commitCount;
354                                                            }
355                                                    }
356    
357                                                    for( int i=0; i<clmNosLen; i++ ) {
358                                                            String val = data[clmNos[i]];
359                                                            if( val != null && val.startsWith( "'0" ) ) {
360                                                                    val = val.substring( 1 );
361                                                            }
362    //                                                      pstmt.setObject( i+1,val );             // 5.3.8.0 (2011/08/01) 処ç??ç°¡ç´?Œ–
363                                                            pstmt.setString( i+1,val );
364                                                    }
365    
366                                                    pstmt.execute();
367                                                    if( commitBatch > 0 && ( executeCount%commitBatch == 0 ) ) {
368    //                                                      conn.commit();
369                                                            tran.commit();                  // 5.1.9.0 (2010/08/01) Transaction 対�
370                                                            commitCount = executeCount;
371                                                    }
372                                                    executeCount++ ;
373                                            }
374                                    }
375    //                              conn.commit();
376                                    tran.commit();                  // 5.1.9.0 (2010/08/01) Transaction 対�
377                                    commitCount = executeCount ;
378                                    errFlag = false;                // エラーã§ã¯ãªã?
379    //                      }
380    //                      finally {
381    //                              Closer.stmtClose( pstmt );
382    //                      }
383                    }
384                    catch (IOException ex) {
385                            String errMsg = "ファイル読込ã¿ã‚¨ãƒ©ãƒ¼[" + reader.toString() + "]"
386                                                    + " 行番å·=[" + executeCount +"]"
387                                                    + " 登録件数=[" + commitCount + "]"  ;
388                            throw new HybsSystemException( errMsg,ex );
389                    }
390                    catch (SQLException ex) {
391                            String errMsg = "sql=[" + sql + "]" + HybsSystem.CR
392                                                    +       "names=[" + StringUtil.array2csv( names ) + "]" + HybsSystem.CR
393                                                    +       "vals =[" + StringUtil.array2csv( data ) + "]" + HybsSystem.CR
394                                                    + " 行番å·=[" + executeCount +"]"
395                                                    + " 登録件数=[" + commitCount + "]"  + HybsSystem.CR
396                                                    + " errorCode=[" + ex.getErrorCode() + "] State=[" +
397                                                    ex.getSQLState() + "]" + HybsSystem.CR ;
398                            throw new HybsSystemException( errMsg,ex );
399                    }
400                    finally {
401                            Closer.stmtClose( pstmt );
402    //                      tran.close( errFlag );                  // 5.1.9.0 (2010/08/01) Transaction 対�
403                            if( tran != null ) {                            // 5.5.2.6 (2012/05/25) findbugs対�
404                                    tran.close( errFlag );                  // 5.1.9.0 (2010/08/01) Transaction 対�
405                            }
406    //                      if( errFlag ) { ConnectionFactory.remove( conn,dbid ); }        // 削除
407    //                      else {                  ConnectionFactory.close( conn,dbid );  }        // è¿”å´
408    //                      conn = null;
409                    }
410    
411                    return commitCount;
412            }
413    
414            /**
415             * BufferedReader よりã€?NAME 行ã?é ?›®å情報を読ã¿å–りã¾ã™ã?
416             * ãƒ??タカラãƒ?‚ˆã‚Šå‰ã«ã€??ç›®åæƒ…報を示ã?"#Name" ãŒå­˜åœ¨ã™ã‚‹ä»®å®šã§å–り込ã¿ã¾ã™ã?
417             * ã“ã?行ã?ã€ãƒ•ァイルã®å½¢å¼ã«ç„¡é–¢ä¿‚ã«ã€TAB ã§åŒºåˆ?‚‰ã‚Œã¦ã?¾ã™ã?
418             * #NAME é…å?ã®å…ˆé?(行番å·ã«ã‚ãŸã‚‹å?æ‰?ã¯ã€ROW_NO ã¨ã?†ã‚­ãƒ¼ã‚’割り当ã¦ã¾ã™ã?
419             * columns ãŒè¨­å®šã•れã¦ã?‚‹å ´åˆã?ã€?NAME 行ã§ã¯ãªãã?columns を優先ã—ã¾ã™ã?
420             *
421             * @og.rev 3.6.0.0 (2004/09/22) #NAME 行ãŒè¦‹ã¤ã‹ã‚‰ãªã??åˆã?ã€ã‚¨ãƒ©ãƒ¼ã¨ã—ã¾ã™ã?
422             * @og.rev 3.6.0.2 (2004/10/04) columns ãŒè¨­å®šã•れã¦ã?‚‹å ´åˆã?ã€ãれを返ã—ã¾ã™ã?
423             *
424             * @param       reader PrintWriterオブジェク�
425             *
426             * @return      カラãƒ?é…å?
427             */
428            private String[] readName( final BufferedReader reader ) {
429                    if( columns != null && columns.length > 0 ) {
430                            return columns ;
431                    }
432    
433                    try {
434                            String line;
435                            while((line = reader.readLine()) != null) {
436                                    if( line.length() == 0 ) { continue; }
437                                    if( line.charAt(0) == '#' ) {
438                                            if( line.length() >= 5 &&
439                                                    "#NAME".equalsIgnoreCase( line.substring( 0,5 ) ) ) {
440                                                    String[] rtn = StringUtil.csv2Array( line ,TAB_SEPARATOR.charAt(0) );
441                                                    rtn[0] = "ROW_NO";      // å…ˆé?カラãƒ?«ã‚«ãƒ©ãƒ?を与ãˆã‚‹ã?
442                                                    return rtn ;
443                                            }
444                                            else { continue; }
445                                    }
446                                    else {
447                                            String errMsg = "#NAME ãŒè¦‹ã¤ã‹ã‚‹å‰ã«ãƒ??ã‚¿ãŒè¦‹ã¤ã‹ã‚Šã¾ã—ãŸã€? + HybsSystem.CR
448                                                            + " LINE=" + line;                      // 5.1.8.0 (2010/07/01) errMsg 修正
449                                            throw new HybsSystemException( errMsg );
450                                    }
451                            }
452                    }
453                    catch (IOException ex) {
454                            String errMsg = "ファイル読込ã¿ã‚¨ãƒ©ãƒ¼[" + reader.toString() + "]"  ;
455                            throw new HybsSystemException( errMsg,ex );
456                    }
457    
458                    String errMsg = "#NAME ãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“ã§ã—ãŸã€?;
459                    throw new HybsSystemException( errMsg );
460            }
461    
462            /**
463             * SQLã«ãƒã‚¤ãƒ³ãƒ‰ã•れる変数ã®ãƒ•ァイルã«å¯¾ã™ã‚‹ã‚¢ãƒ‰ãƒ¬ã‚¹ã®é…å?ã‚’è¿”ã—ã¾ã™ã?
464             *
465             * @og.rev 3.6.0.2 (2004/10/04) 処ç?ƒ­ã‚¸ãƒ?‚¯å¤‰æ›´
466             * @og.rev 3.8.0.2 (2005/06/30) clms 㮠null時対�
467             *
468             * @param       names   ファイルヘッãƒ??ã®åç§°é…å?
469             * @param       clms    SQLã«ãƒã‚¤ãƒ³ãƒ‰ã•れるåç§°ã®CSVæ–?­—å?
470             *
471             * @return  int[] SQLã«ãƒã‚¤ãƒ³ãƒ‰ã•れる変数ã®ãƒ•ァイルã«å¯¾ã™ã‚‹ã‚¢ãƒ‰ãƒ¬ã‚¹ã®é…å?
472             */
473    //      private int[] getColumnNos( final String[] names,final String[] clms ) {
474    //              int[] clmNos = new int[0];
475    //
476    //              if( clms != null ) {
477    //                      clmNos = new int[clms.length];
478    //                      for( int i=0; i<clms.length; i++ ) {
479    //                              boolean flag = true;
480    //                              for( int j=0; flag && j<names.length; j++ ) {
481    //                                      if( clms[i].equalsIgnoreCase( names[j] ) ) {
482    //                                              clmNos[i] = j;
483    //                                              flag = false;
484    //                                      }
485    //                              }
486    //                              // 見ã¤ã‹ã‚‰ãªã??åˆã?エラー
487    //                              if( flag ) {
488    //                                      String errMsg = "æŒ?®šã?カラãƒ?ã¯ã€ãƒ•ァイルã®ã‚«ãƒ©ãƒ??ã«ä¸??ã—ã¾ã›ã‚“ã€?
489    //                                                              + " カラ�[" + clms[i] + "]"
490    //                                                              + " カラ�?=[" + StringUtil.array2csv( names ) + "]" ;
491    //                                      throw new HybsSystemException( errMsg );
492    //                              }
493    //                      }
494    //              }
495    //              return clmNos;
496    //      }
497    
498            /**
499             * BufferedReader ã‚’å–å¾—ã—ã¾ã™ã?
500             *
501             * ã“ã“ã§ã¯ã€ä¸?ˆ¬çš?ªãƒ•ァイル出力をè€??ã—㟠BufferedReader を作æ?ã—ã¾ã™ã?
502             *
503             * @return      æŒ?®šã?読ã¿å–り用BufferedReaderオブジェクãƒ?
504             */
505            private BufferedReader getBufferedReader() {
506                    if( filename == null ) {
507                            String errMsg = "ファイルåãŒã‚»ãƒ?ƒˆã•れã¦ã?¾ã›ã‚“ã€?;
508                            throw new HybsSystemException( errMsg );
509                    }
510                    String directory = HybsSystem.url2dir( fileURL );
511                    File file = new File( StringUtil.urlAppend( directory,filename ) );
512    
513                    BufferedReader out = FileUtil.getBufferedReader( file,encode );
514    
515                    return out ;
516            }
517    
518            /**
519             * フォーマットをセãƒ?ƒˆã—ã¾ã™ã?
520             * UPDATE GExx SET CLMA = [CLMA] WHERE KEY1 = [KEY1] å½¢å¼ã‚ˆã‚Šã?
521             * [CLMA]ã€[KEY1] ã‚’é?ã«ã€clmKeys é…å?ã«æ ¼ç´ã—ã¾ã™ã?
522             * ã¾ãŸã?入力フォーマットã?ã¯ã€[カラãƒ?]ã®å€‹æ‰€ã‚?? ã«ç½®ãæ›ãˆãŸ
523             * 値をã?è¿”ã—ã¾ã™ã?ã“ã?SQLæ–??ã€ãã®ã¾ã¾ PreparedStatement ã«æ¸¡ã—ã¾ã™ã?
524             * å…ˆã?SQLæ–?ªã‚‰ã?UPDATE GExx SET CLMA = ? WHERE KEY1 = ? ã«ã€å¤‰æ›ã—ã¾ã™ã?
525             *
526             * @og.rev 3.6.0.2 (2004/10/04) æ–°è¦è¿½åŠ?
527             *
528             * @param       fmt  [カラãƒ?] å½¢å¼ã?フォーマットデータ
529             *
530             * @return       [カラãƒ?]  ã‚?? ã«ç½®ãæ›ãˆãŸæ–?­—å?
531             */
532    //      private String makeFormat( final String fmt ) {
533    //              StringBuilder buf = new StringBuilder( fmt.length() );
534    //
535    //              String fmt2 = fmt.replace( '[',']' );
536    //              CSVTokenizer token = new CSVTokenizer( fmt2,']',false );
537    //              int count = token.countTokens() / 2 ;
538    //              clmKeys = new String[ count ];
539    //
540    ////            String format = null;
541    //              for( int i=0; i<count; i++ ) {
542    ////                    format = token.nextToken();
543    ////                    buf.append( format);
544    //                      buf.append( token.nextToken() );        // format
545    //                      clmKeys[i] = token.nextToken();
546    //                      buf.append( "?" );              // [カラãƒ? ã‚?? ã«ç½®ãæ›ã?
547    //              }
548    ////            format = token.nextToken();
549    ////            buf.append( format );
550    //              buf.append( token.nextToken() );        // format
551    //
552    //              return buf.toString();
553    //      }
554    
555            /**
556             * ã€TAGã€?通常ã¯ä½¿ã?¾ã›ã‚“)検索時ã?DB接続IDを指定ã—ã¾ã?åˆæœŸå€¤:DEFAULT)ã€?
557             *
558             * @og.tag
559             *   検索時ã?DB接続IDを指定ã—ã¾ã™ã?åˆæœŸå€¤ã¯ã€DEFAULT ã§ã™ã?
560             *
561             * @param       id ãƒ??タベã?ス接続ID
562             */
563            public void setDbid( final String id ) {
564                    dbid = nval( getRequestParameter( id ),dbid );
565            }
566    
567            /**
568             * ã€TAG】å¯å¤‰é•·ãƒ•ァイルを作æ?ã™ã‚‹ã¨ãã?é ?›®åŒºåˆ?‚Šæ–?­—ã‚’ã‚»ãƒ?ƒˆã—ã¾ã?åˆæœŸå€¤:ã‚¿ãƒ?ã€?
569             *
570             * @og.tag å¯å¤‰é•·ãƒ•ァイルを作æ?ã™ã‚‹ã¨ãã?é ?›®åŒºåˆ?‚Šæ–?­—ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?
571             *
572             * @param   separator é ?›®åŒºåˆ?‚Šæ–?­?
573             */
574            public void setSeparator( final String separator ) {
575                    this.separator = nval( getRequestParameter( separator ),this.separator );
576            }
577    
578            /**
579             * ã€TAG】読ã¿å–りå…?ƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªåã‚’æŒ?®šã—ã¾ã?
580             *              (åˆæœŸå€¤:FILE_URL[={@og.value org.opengion.hayabusa.common.SystemData#FILE_URL}])ã€?
581             *
582             * @og.tag
583             * ã“ã?属æ?ã§æŒ?®šã•れるãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚ˆã‚Šã€ãƒ•ァイルを読ã¿å–りã¾ã™ã?
584             * æŒ?®šæ–¹æ³•ã?ã€??常㮠fileURL 属æ?ã¨åŒæ§˜ã«ã€å?é ­ãŒã?'/' (UNIX) ã¾ãŸã?ã€?¼’文字目ãŒã?
585             * ":" (Windows)ã®å ´åˆã?ã€æŒ‡å®šã?URLãã?ã¾ã¾ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã«ã€ãã?§ãªã??åˆã?ã€?
586             * fileURL = "{&#064;USER.ID}" ã¨æŒ?®šã™ã‚‹ã¨ã€FILE_URL 属æ?ã§æŒ?®šã?フォルãƒ??下ã«ã€?
587             * ã•らã«ã€å„個人ID別ã®ãƒ•ォルãƒ??下よりã?読ã¿å–りã¾ã™ã?
588             * (åˆæœŸå€¤:シスãƒ?ƒ å®šæ•°ã®FILE_URL[={@og.value org.opengion.hayabusa.common.SystemData#FILE_URL}])ã€?
589             *
590             * @og.rev 4.0.0.0 (2005/01/31) StringUtil.urlAppend メソãƒ?ƒ‰ã®åˆ©ç”¨
591             * @og.rev 4.0.0.0 (2007/11/20) æŒ?®šã•れãŸãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªåã?æœ?¾ŒãŒ"\"or"/"ã§çµ‚ã‚ã£ã¦ã?ªã??åˆã«ã€?/"を付加ã™ã‚‹ã€?
592             *
593             * @param       url ファイルURL
594             * @see         org.opengion.hayabusa.common.SystemData#FILE_URL
595             */
596            public void setFileURL( final String url ) {
597                    String furl = nval( getRequestParameter( url ),null );
598                    if( furl != null ) {
599                            char ch = furl.charAt( furl.length()-1 );
600                            if( ch != '/' && ch != '\\' ) { furl = furl + "/"; }
601                            fileURL = StringUtil.urlAppend( fileURL,furl );
602                    }
603            }
604    
605            /**
606             * ã€TAG】ファイルを作æ?ã™ã‚‹ã¨ãã?ファイルåã‚’ã‚»ãƒ?ƒˆã—ã¾ã?
607             *              (åˆæœŸå€¤:FILE_FILENAME[={@og.value org.opengion.hayabusa.common.SystemData#FILE_FILENAME}])ã€?
608             *
609             * @og.tag
610             * ファイルを作æ?ã™ã‚‹ã¨ãã?ファイルåã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?
611             * (åˆæœŸå€¤:シスãƒ?ƒ å®šæ•°ã®FILE_FILENAME[={@og.value org.opengion.hayabusa.common.SystemData#FILE_FILENAME}])ã€?
612             *
613             * @param   filename ファイルå?
614             * @see         org.opengion.hayabusa.common.SystemData#FILE_FILENAME
615             */
616            public void setFilename( final String filename ) {
617                    this.filename = nval( getRequestParameter( filename ),this.filename );
618            }
619    
620            /**
621             * ã€TAG】ファイルを作æ?ã™ã‚‹ã¨ãã?ファイルエンコーãƒ?‚£ãƒ³ã‚°åã‚’ã‚»ãƒ?ƒˆã—ã¾ã?
622             *              (åˆæœŸå€¤:FILE_ENCODE[={@og.value org.opengion.hayabusa.common.SystemData#FILE_ENCODE}])ã€?
623             *
624             * @og.tag
625             * åˆæœŸå€¤ã¯ã€ã‚·ã‚¹ãƒ?ƒ ãƒ‘ラメータ ã® FILE_ENCODE 属æ?ã§ã€è¨­å®šã—ã¦ã?¾ã™ã?
626             * Shift_JIS,MS932,Windows-31J,UTF-8,ISO-8859-1,UnicodeLittle?¥?¥?¥
627             * (åˆæœŸå€¤:シスãƒ?ƒ å®šæ•°ã®FILE_ENCODE[={@og.value org.opengion.hayabusa.common.SystemData#FILE_ENCODE}])ã€?
628             *
629             * @param   enc ファイルエンコーãƒ?‚£ãƒ³ã‚°å?
630             * @see     <a href="http://www.iana.org/assignments/character-sets">IANA Charset Registry</a>
631             * @see         org.opengion.hayabusa.common.SystemData#FILE_ENCODE
632             */
633            public void setEncode( final String enc ) {
634                    encode = nval( getRequestParameter( enc ),encode );
635            }
636    
637            /**
638             * ã€TAG】query ã®çµæžœã‚’ç”»é¢ä¸Šã«è¡¨ç¤ºã™ã‚‹ãƒ¡ãƒ?‚»ãƒ¼ã‚¸IDを指定ã—ã¾ã?åˆæœŸå€¤:MSG0040[ã€?»¶ç™»éŒ²ã—ã¾ã—ãŸ])ã€?
639             *
640             * @og.tag
641             * ã“ã“ã§ã¯ã€æ¤œç´¢çµæžœã®ä»¶æ•°ã‚?™»éŒ²ã•れãŸä»¶æ•°ã‚’ã¾ãšå?力ã—ã€?
642             * ãã?次ã«ã€ã“ã“ã§æŒ?®šã—ãŸãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’リソースã‹ã‚‰å–å¾—ã—ã¦
643             * 表示ã—ã¾ã™ã?
644             * 表示ã•ã›ãŸããªã??åˆã?, displayMsg = "" ã‚’ã‚»ãƒ?ƒˆã—ã¦ãã ã•ã„ã€?
645             * åˆæœŸå€¤ã¯ã€æ¤œç´¢ä»¶æ•°ã‚’表示ã—ã¾ã™ã?
646             * ※ ã“ã?属æ?ã«ã¯ã€ãƒªã‚¯ã‚¨ã‚¹ãƒˆå¤‰æ•°({&#064;XXXX})ã¯ä½¿ç”¨ã§ãã¾ã›ã‚“ã€?
647             *
648             * @param   id ãƒ?‚£ã‚¹ãƒ—レイã«è¡¨ç¤ºã•ã›ã‚‹ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ ID
649             */
650            public void setDisplayMsg( final String id ) {
651                    if( id != null ) { displayMsg = id; }
652            }
653    
654            /**
655             * ã€TAGã€?NAME 属æ?ã®ä»£ã‚りã¨ãªã‚‹ãƒ•ァイルã®ã‚«ãƒ©ãƒ?ã‚?CSVå½¢å¼ã§æŒ?®šã—ã¾ã™ã?
656             *
657             * @og.tag
658             * ãƒ??タファイルã®å…ˆé?行ã«ã€?NAME 行ãŒã‚りã€èª­ã¿å–ã‚‹ã¹ãファイルã®
659             * カラãƒ?ãŒè¨˜è¿°ã•れã¦ã?¾ã™ã?通常ã¯ã€ã“ã®ã‚«ãƒ©ãƒ?ã‚’å–り込んã§ã€?
660             * å?ƒ‡ãƒ¼ã‚¿åˆ—ã?カラãƒ?‚’æŒ?®šã—ã¾ã™ã?
661             * ã“ã?属æ?ã¯ã€ãƒ•ァイルã«#NAME 行ãŒå­˜åœ¨ã—ãªã?他シスãƒ?ƒ ã‹ã‚‰ã®å…¥åŠ›ãƒ•ã‚¡ã‚¤ãƒ«ç­?
662             * å ´åˆã«ã€?NAME 属æ?ã®ä»£ã‚りã«ã€ã‚«ãƒ©ãƒ?を外部よりæŒ?®šã—ã¾ã™ã?
663             *
664             * @og.rev 3.8.5.1 (2006/05/08) getCSVParameter ã®ä½¿ç”¨ã‚’中止
665             *
666             * @param   clms ファイルã®ã‚«ãƒ©ãƒ?(カンマ区åˆ?‚Šæ–?­?
667             */
668            public void setColumns( final String clms ) {
669                    columns = StringUtil.csv2Array( nval( getRequestParameter( clms ),null ),',' );
670            }
671    
672            /**
673             * ã€TAG】指定数毎ã«ã‚³ãƒŸãƒƒãƒˆã‚’発行ã—ã¾ã?åˆæœŸå€¤:0 終äº?¾ã§ã‚³ãƒŸãƒƒãƒˆã—ã¾ã›ã‚“)ã€?
674             *
675             * @og.tag
676             * 通常ã¯ã€å?ã¦ã®å‡¦ç?Œæ­£å¸¸ã«çµ‚äº?™ã‚‹ã‹ã€ãªã«ã‚‚ã—ãªã?‹(トランザクション)
677             * を判断ã™ã¹ãã§ã€??中ã§ã®ã‚³ãƒŸãƒƒãƒˆã?ã—ã¾ã›ã‚“ã€?
678             * ã—ã‹ã—ã?å ´åˆã«ã‚ˆã£ã¦ã€ä»¶æ•°ãŒç•°å¸¸ã«å¤šã„å ´åˆã‚„ã€å?実行å¯èƒ½ãªå ´åˆã?ã€?
679             * 途中ã§ã‚³ãƒŸãƒƒãƒˆã—ã¦ã€??度ã€å?ç?§ãã‚‹ã‚‚ã?ã?‘ã‚’å?ç?—ã¦ã—ã¾ã?¨ã?†æ–¹æ³•ãŒã‚りã¾ã™ã?
680             * ã¾ãŸã?ロールãƒãƒƒã‚¯ã‚¨ãƒªã‚¢ã®é–¢ä¿‚ãªã©ã§ã€ãƒ‡ãƒ¼ã‚¿é‡ãŒå¤šã„å ´åˆã«ã€å?ç?™‚é–“ãŒç•°å¸¸ã«
681             * é•·ããªã‚‹äº‹ãŒã‚ã‚Šã€æŒ‡å®šä»¶æ•°ã”ã¨ã®ã‚³ãƒŸãƒƒãƒˆæ©Ÿè?を用æ„ã—ã¦ã?¾ã™ã?
682             * 0 ã«è¨­å®šã™ã‚‹ã¨ã€çµ‚äº?¾ã§ã‚³ãƒŸãƒƒãƒˆã—ã¾ã›ã‚“。å?期å?ã¯ã€? ã§ã™ã?
683             *
684             * @param   cmtBat æŒ?®šæ•°æ¯Žã«ã‚³ãƒŸãƒƒãƒˆã‚’発è¡?åˆæœŸå€¤:0)
685             */
686            public void setCommitBatch( final String cmtBat ) {
687                    commitBatch = nval( getRequestParameter( cmtBat ),commitBatch );
688            }
689    
690            /**
691             * ã€TAG】カラãƒ?ƒã‚§ãƒ?‚¯(DBTypeãƒã‚§ãƒ?‚¯)を行ã†ã‹ã©ã?‹ã‚’設定ã—ã¾ã?åˆæœŸå€¤:false)ã€?
692             *
693             * @og.tag
694             * カラãƒ??æ•´åˆæ?ãƒã‚§ãƒ?‚¯ã‚’行ã†å ´åˆã?ã“ã?属æ?を設å®?true)ã—ã¾ã™ã?
695             * åˆæœŸå€¤ã¯ã€è¡Œã‚ãªã?false)ã§ã™ã?
696             * ãƒã‚§ãƒ?‚¯ã™ã‚‹ã‚«ãƒ©ãƒ??ã€?NAME ã‚?columns ã§æŒ?®šã•れãŸã‚«ãƒ©ãƒ?§ã¯ãªãã?
697             * BODY部ã®SQLæ–?§æŒ?®šã•れãŸã‚«ãƒ©ãƒ?( [カラãƒ?] )ã§ã™ã?ã“れã¯ã€ç›´æŽ¥ã€SQLæ–?¸­ã«
698             * 記述ã—ã¦ã?‚‹å€¤ã‚??{&#064;XXXX}æ–?­—ç­‰ã?ã€ãƒã‚§ãƒ?‚¯å‡ºæ¥ãªã?‚ºã§ã™ã?
699             *
700             * @og.rev 3.6.0.2 (2004/10/04) æ–°è¦è¿½åŠ?å–ã‚Šè¾¼ã¿æ™‚å?ãƒã‚§ãƒ?‚¯
701             *
702             * @param   flag ãƒã‚§ãƒ?‚¯ã‚’行ã†ã‹ã©ã?‹(true:行ã†/false:行ã‚ãªã?
703             * @see     #setUseColumnAdjust( String )
704             */
705            public void setUseColumnCheck( final String flag ) {
706                    useColumnCheck = nval( getRequestParameter( flag ),useColumnCheck );
707            }
708    
709            /**
710             * ã€TAG】カラãƒ?¤‰æ›(DBType変æ›)を行ã†ã‹ã©ã?‹ã‚’設定ã—ã¾ã?åˆæœŸå€¤:false)ã€?
711             *
712             * @og.tag
713             * カラãƒ??変æ›ã‚’行ã†å ´åˆã?ã“ã?属æ?を設å®?true)ã—ã¾ã™ã?
714             * åˆæœŸå€¤ã¯ã€è¡Œã‚ãªã?false)ã§ã™ã?
715             * 変æ›ã™ã‚‹ã‚«ãƒ©ãƒ??ã€?NAME ã‚?columns ã§æŒ?®šã•れãŸã‚«ãƒ©ãƒ?§ã¯ãªãã?
716             * BODY部ã®SQLæ–?§æŒ?®šã•れãŸã‚«ãƒ©ãƒ?[カラãƒ?]ã§ã™ã?ã“れã¯ã€ç›´æŽ¥ã€SQLæ–?¸­ã«
717             * 記述ã—ã¦ã?‚‹å€¤ã‚??{&#064;XXXX}æ–?­—ç­‰ã?ã€å¤‰æ›å‡ºæ¥ãªã?‚ºã§ã™ã?
718             *
719             * @og.rev 3.6.0.2 (2004/10/04) æ–°è¦è¿½åŠ?å–ã‚Šè¾¼ã¿æ™‚変æ›
720             *
721             * @param   flag 変æ›ã‚’行ã†ã‹ã©ã?‹(true:行ã†/false:行ã‚ãªã?
722             * @see     #setUseColumnCheck( String )
723             */
724            public void setUseColumnAdjust( final String flag ) {
725                    useColumnAdjust = nval( getRequestParameter( flag ),useColumnAdjust );
726            }
727    
728            /**
729             * ã€TAG】NULL ãƒã‚§ãƒ?‚¯ã™ã¹ãカラãƒ??をカンマ区åˆ?‚Š(CSVå½¢å¼?ã§æŒ?®šã—ã¾ã™ã?
730             *
731             * @og.tag nullCheck="AAA,BBB,CCC,DDD"
732             * <del>å…ˆã«é…å?ã«åˆ?§£ã—ã¦ã‹ã‚‰ãƒªã‚¯ã‚¨ã‚¹ãƒˆå¤‰æ•°ã®å€¤ã‚’å–å¾—ã™ã‚‹ã‚ˆã?«ã—ã¾ã™ã?
733             * ã“ã†ã™ã‚‹äº‹ã§ã€ãƒªã‚¯ã‚¨ã‚¹ãƒˆã«ã‚«ãƒ³ãƒžåŒºåˆ?‚Šã®å€¤ã‚’設定ã§ãるよã†ã«ãªã‚Šã¾ã™ã?</del>
734             * åˆ?§£æ–¹æ³•ã?ã€??常ã®ãƒ‘ラメータå–得後ã«ã€CSVåˆ?§£ã—ã¾ã™ã?
735             *
736             * @og.rev 3.8.0.2 (2005/06/30) æ–°è¦è¿½åŠ?
737             * @og.rev 3.8.8.5 (2007/03/09) 通常ã®ãƒ‘ラメータå–得後ã«ã€CSVåˆ?§£ã«æˆ»ã—ã¾ã™ã?
738             *
739             * @param   clms カラ�?(CSV形�
740             */
741            public void setNullCheck( final String clms ) {
742                    nullCheck = StringUtil.csv2Array( getRequestParameter( clms ) );
743                    if( nullCheck.length == 0 ) { nullCheck = null; }
744            }
745            
746            /**
747             * ã€TAG】å–ã‚Šè¾¼ã¿æ™‚ã«é™¤å¤–ã™ã‚‹è¡Œã‚’æŒ?®šã—ã¾ã?åˆæœŸå€¤:0)ã€?
748             *
749             * @og.tag
750             * TAB区åˆ?‚Šãƒ?‚­ã‚¹ãƒˆã‚„EXCELç­‰ã?ãƒ??ã‚¿ã®èª­ã¿å§‹ã‚ã®åˆæœŸå€¤ã‚’指定ã—ã¾ã™ã?
751             * ファイルã®å…ˆé?行ãŒã€?¼è¡Œã¨ã—ã¦ã‚«ã‚¦ãƒ³ãƒˆã—ã¾ã™ã?ã§ã€è¨­å®šå?ã¯ã€èª­ã¿é£›ã?ã?
752             * ä»¶æ•°ã«ãªã‚Šã¾ã™ã?(?‘ã¨æŒ?®šã™ã‚‹ã¨ã€?¼‘件読ã¿é£›ã?ã—ã??’行目ã‹ã‚‰èª­ã¿è¾¼ã¿ã¾ã™ã?)
753             * 読ã¿é£›ã?ã—ã?ã€ã‚³ãƒ¡ãƒ³ãƒˆè¡Œãªã©ã¯ã€ç„¡è¦–ã—ã¾ã™ã?ã§ã€å®Ÿéš›ã®è¡Œæ•°åˆ?ª­ã¿é£›ã?ã—ã¾ã™ã?
754             * ?ƒNAME属æ?ã‚??columns 属æ?ã¯ã€æœ‰åйã§ã™ã?
755             *
756             * @og.rev 5.5.7.1 (2012/10/05) æ–°è¦è¿½åŠ?
757             *
758             * @param   count å…ˆé?行を無視ã™ã‚‹ã‹ã©ã?‹(true:無視ã™ã‚?false:無視ã—ãªã?
759             */
760            public void setSkipRowCount( final String count ) {
761                    skipRowCount = nval( getRequestParameter( count ),skipRowCount );
762            }
763    
764            /**
765             * カラãƒ?¤‰æ›ã€ã‚«ãƒ©ãƒ?ƒã‚§ãƒ?‚¯ã‚’行ã†å†?ƒ¨ã‚¯ãƒ©ã‚¹
766             *
767             * @og.rev 4.0.0.0 (2005/01/31) static クラス化ã?引数ã«ResourceManager追åŠ?
768             * @og.group ファイル入�
769             *
770             * @version  4.0
771             * @author   Kazuhiko Hasegawa
772             * @since    JDK5.0,
773             */
774            static class CheckColumnData {
775                    private final DBColumn[] dbClm    ;
776                    private final int[]      clmChkNo ;
777                    private final int        len      ;             // é•·ã•ï¼ã?時ã?ã€ãªã«ã‚‚ã—ãªã??
778                    private final ErrorMessage errMsg = new ErrorMessage( "Check Columns Error!" );
779    
780                    /**
781                     * コンストラクター
782                     *
783                     * @param       clmNo   カラãƒ?•ªå·é…å?
784                     * @param chkClm String[]
785                     * @param resource ResourceManager
786                     */
787                    CheckColumnData( final int[] clmNo, final String[] chkClm,final ResourceManager resource ) {
788                            if( clmNo  == null || clmNo.length  == 0 ||
789                                    chkClm == null || chkClm.length == 0 ) { // return; }   // 何もã—ãªã?
790    
791                                    dbClm    = null;
792                                    clmChkNo = null;
793                                    len      = 0;
794                            }
795                            else {
796                                    clmChkNo = clmNo ;
797                                    len = clmNo.length ;
798                                    dbClm = new DBColumn[len];
799                                    for( int i=0; i<len; i++ ) {
800                                            dbClm[i] = resource.makeDBColumn( chkClm[i] );  // 4.0.0 (2005/01/31)
801                                    }
802                            }
803                    }
804    
805                    /**
806                     * 引数ã®ãƒ??ã‚¿ã‚?DBColumn ã§æ­£è¦åŒ–(valueSetメソãƒ?ƒ‰çµŒç”±)ã—ã¾ã™ã?
807                     *
808                     * @param       data    ?‘行å?ã®ãƒ??ã‚¿é…å?
809                     * @return String[]
810                     * @see org.opengion.hayabusa.db.DBColumn#valueSet( String )
811                     */
812                    String[] adjustData( final String[] data ) {
813                            if( len == 0 ) { return data; }
814                            String[] ajstData = new String[len];
815                            for( int i=0; i<len; i++ ) {
816                                    String val = data[clmChkNo[i]];
817                                    ajstData[i] = dbClm[i].valueSet( val );
818                            }
819                            return ajstData ;
820                    }
821    
822                    /**
823                     * 引数ã®ãƒ??ã‚¿ã‚?DBColumn ã§æ­£è¦åŒ–(valueSetメソãƒ?ƒ‰çµŒç”±)ã—ã¾ã™ã?
824                     *
825                     * @param       row     行番å·
826                     * @param       data    ?‘行å?ã®ãƒ??ã‚¿é…å?
827                     * @return ErrorMessage
828                     * @see org.opengion.hayabusa.db.DBColumn#valueSet( String )
829                     */
830                    ErrorMessage checkData( final int row,final String[] data ) {
831                            for( int i=0; i<len; i++ ) {
832                                    String val = data[clmChkNo[i]];
833                                    errMsg.append( row+1,dbClm[i].valueCheck( val ) );
834                            }
835                            return errMsg ;
836                    }
837            }
838    
839            /**
840             * ã“ã?オブジェクトã?æ–?­—å?表ç¾ã‚’è¿”ã—ã¾ã™ã?
841             * 基本çš?«ãƒ?ƒãƒ?‚°ç›®çš?«ä½¿ç”¨ã—ã¾ã™ã?
842             *
843             * @return ã“ã?ã‚¯ãƒ©ã‚¹ã®æ–?­—å?表ç¾
844             */
845            @Override
846            public String toString() {
847                    return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
848                                    .println( "VERSION"                     ,VERSION                )
849                                    .println( "dbid"                        ,dbid                   )
850                                    .println( "separator"           ,separator              )
851                                    .println( "fileURL"                     ,fileURL                )
852                                    .println( "filename"            ,filename               )
853                                    .println( "encode"                      ,encode                 )
854                                    .println( "displayMsg"          ,displayMsg             )
855                                    .println( "columns"                     ,columns                )
856                                    .println( "clmKeys"                     ,clmKeys                )
857                                    .println( "sql"                         ,sql                    )
858                                    .println( "commitBatch"         ,commitBatch    )
859                                    .println( "useColumnCheck"      ,useColumnCheck )
860                                    .println( "useColumnAdjust"     ,useColumnAdjust)
861                                    .println( "nullCheck"           ,nullCheck              )
862                                    .println( "dyStart"                     ,dyStart                )
863                                    .println( "Other..."            ,getAttributes().getAttribute() )
864                                    .fixForm().toString() ;
865            }
866    }