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.common; 017 018 import org.opengion.fukurou.xml.HybsXMLSave; 019 import org.opengion.fukurou.util.Closer ; 020 021 import java.sql.Connection; 022 import java.sql.SQLException; 023 024 import java.io.Reader; 025 import java.io.BufferedReader; 026 import java.io.InputStreamReader; 027 import java.io.FileInputStream; 028 import java.io.InputStream; 029 import java.io.IOException; 030 import java.io.File; 031 import java.io.UnsupportedEncodingException; 032 033 import java.util.List; 034 import java.util.ArrayList; 035 import java.util.Enumeration; 036 import java.util.jar.JarFile; 037 import java.util.jar.JarEntry; 038 import java.net.URL; 039 040 /** 041 * ORACLE XDK å½¢å¼ã?XMLファイルをèªã¿å–ã£ã¦ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ã?スã«ç™»éŒ²ã—ã¾ã™ã? 042 * èµ·å‹?実è¡?ã¯ã€ã‚³ãƒ³ãƒ?‚ストèªã¿å–り時ã?åˆå›žã®ã¿ã§ã™ã?GE12パラメータを変更ã—㟠043 * å ´åˆã?ã€ã‚³ãƒ³ãƒ?‚ストã?リãƒãƒ¼ãƒ‰ãŒå¿?¦ã§ã™ã? 044 * 登録ã®å®Ÿè¡Œæœ‰ç„¡ã®åˆ¤æ–ã¯ã€ãƒ•ã‚¡ã‚¤ãƒ«ã®æ›´æ–°æ™‚刻より判æ–ã—ã¾ã™ã?(useTimeStamp=true ã®å ´å? 045 * ã“れã¯ã€èªã¿å–ã‚Šãƒ•ã‚¡ã‚¤ãƒ«ã®æ›´æ–°æ™‚刻ãŒã??ã§ãªã??åˆã?èªã¿å–りを行ã„ã¾ã™ã? 046 * èªã¿å–りãŒå®Œäº?—ãŸå?åˆã?ã€æ›´æ–°æ™‚刻ã‚???ã«è¨å®šã—ã¾ã™ã? 047 * èªã¿å–るファイルã¯ã€ã‚¯ãƒ©ã‚¹ãƒãƒ¼ãƒ??ã®ãƒªã‚½ãƒ¼ã‚¹ã¨ã—ã¦å–å¾—ã•れã¾ã™ã?ã§ã€ã‚¯ãƒ©ã‚¹ãƒ‘スã? 048 * è¨å®šã•れã¦ã?‚‹å¿?¦ãŒã‚りã¾ã™ã?ã¾ãŸã?ファイルã¯ã€æ‹¡å¼µå㌠xml ã§ã€UTF-8ã§ã‚¨ãƒ³ã‚³ãƒ¼ãƒ? 049 * ã•れã¦ã?‚‹å¿?¦ãŒã‚りã¾ã™ã?通常ã¯ã€ãƒ•ァイルåãŒãƒ??ブルåã¨åŒä¸?«ã—ã¦ãŠãå¿?¦ãŒ 050 * ã‚りã¾ã™ãŒã€ROWSETã®table属æ?ã«ãƒ??ブルåã‚’ã‚»ãƒ?ƒˆã—ã¦ãŠãã“ã¨ã‚‚å¯èƒ½ã§ã™ã? 051 * ファイルã®ç™»éŒ²é ??ã€åŽŸå‰??クラスãƒãƒ¼ãƒ??ã®æ¤œç´¢é ?«ã€è¦‹ã¤ã‹ã£ãŸå?ã¦ã®ãƒ•ァイルã‚? 052 * 登録ã—ã¾ã™ã?ãƒ??ã‚¿ãã?ã‚‚ã?ã¯ã€INSERT ã®ã¿å¯¾å¿œã—ã¦ã?¾ã™ã?ã§ã€åŽŸå‰?™»éŒ²é ??無視ã•れã¾ã™ã? 053 * ãŸã ã—ã?æ‹¡å¼µXDK å½¢å¼ã§ã€EXEC_SQL タグを使用ã—ãŸå ´åˆã?ã€ç™»éŒ²é ?Œå½±éŸ¿ã™ã‚‹å¯èƒ½æ€§ãŒã‚りã¾ã™ã? 054 * 例:GE12.xml GE12 ãƒ??ブルã«ç™»éŒ²ã™ã‚‹XMLファイル 055 * 登録時ã«ã€æ—¢å˜ã?ãƒ??ã‚¿ã®ç ´æ£?Œå¿?¦ãªå ´åˆã?ã€æ‹¡å¼µXDK å½¢å¼ã?XMLファイルã‚? 056 * 作æ?ã—ã¦ãã ã•ã„。ã“れã?ã€EXEC_SQL ã‚¿ã‚°ã«æ›¸ã込んã SQLæ–?‚’実行ã—ã¾ã™ã? 057 * 詳細ã¯ã€{@link org.opengion.fukurou.xml.HybsXMLHandler HybsXMLHandler} クラスをå‚ç…§ã—ã¦ãã ã•ã„ã€? 058 * 059 * <ROWSET tableName="XX" > 060 * <EXEC_SQL> æœ??ã«è¨˜è¼‰ã—ã¦ã€å?期å?ç?ãƒ??タクリアç?を実行ã•ã›ã‚‹ã€? 061 * delete from GEXX where YYYYY 062 * </EXEC_SQL> 063 * <ROW num="1"> 064 * <カラãƒ?>値1</カラãƒ?> 065 * ?¥?¥?¥ 066 * <カラãƒ?>値n</カラãƒ?> 067 * </ROW> 068 * ?¥?¥?¥ 069 * <ROW num="n"> 070 * ?¥?¥?¥ 071 * </ROW> 072 * <EXEC_SQL> æœ?¾Œã«è¨˜è¼‰ã—ã¦ã€??ç›®ã®è¨å®?æ•´åˆæ?登録)を行ã†ã€? 073 * update GEXX set AA='XX' , BB='XX' where YYYYY 074 * </EXEC_SQL> 075 * <ROWSET> 076 * 077 * @og.rev 4.0.0.0 (2004/12/31) æ–°è¦ä½œæ? 078 * @og.group åˆæœŸåŒ? 079 * 080 * @version 4.0 081 * @author Kazuhiko Hasegawa 082 * @since JDK5.0, 083 */ 084 public final class InitFileLoader { 085 private final String CLASSPATH ; 086 private final Connection connection ; 087 private boolean fileCommit = false; // ファイル毎ã«ã‚³ãƒŸãƒƒãƒˆå?ç?‚’行ã†ã‹ã©ã?‹(true:行ã†/false:行ã‚ãªã? 088 089 /** 090 * コãƒã‚¯ã‚·ãƒ§ãƒ³ã‚’引数ã«ã™ã‚‹ã€ã‚³ãƒ³ã‚¹ãƒˆãƒ©ã‚¯ã‚¿ãƒ¼ã§ã™ã? 091 * classPath="resource" ã§åˆæœŸåŒ–ã•れ㟠InitFileLoader を作æ?ã—ã¾ã™ã? 092 * 093 * @param conn 登録用コãƒã‚¯ã‚·ãƒ§ãƒ³ 094 */ 095 public InitFileLoader( final Connection conn ) { 096 this( conn,"resource" ); 097 } 098 099 /** 100 * コãƒã‚¯ã‚·ãƒ§ãƒ³ã¨æ¤œç´¢ãƒ‘スを指定ã—ã¦æ§‹ç¯‰ã™ã‚‹ã?コンストラクターã§ã™ã? 101 * 対象ファイルã¯ã€classPath ã§æŒ?®šã•れãŸå ´æ‰?‚’ã€ã‚¯ãƒ©ã‚¹ãƒãƒ¼ãƒ??ã§æ¤œç´¢ã—ã¾ã™ã? 102 * ã“ã“ã§è¦‹ã¤ã‹ã£ãŸãƒ‘ス以下ã? XMLファイル(æ‹¡å¼µåã?å°æ–‡å—ã§ã€?xml )を検索 103 * ã—ã¾ã™ã?ã“ã?ファイルåã? ãƒ??ブルå?xml å½¢å¼ã§æ ¼ç´ã—ã¦ãŠãã¾ã™ã? 104 * 105 * @param conn 登録用コãƒã‚¯ã‚·ãƒ§ãƒ³ 106 * @param classPath 対象ã¨ãªã‚‹ãƒ•ァイル群を検索ã™ã‚‹ã€ã‚¯ãƒ©ã‚¹ãƒ‘ス 107 */ 108 public InitFileLoader( final Connection conn,final String classPath ) { 109 connection = conn ; 110 CLASSPATH = classPath; 111 } 112 113 /** 114 * ファイル毎ã«ã‚³ãƒŸãƒƒãƒˆå?ç?‚’行ã†ã‹ã©ã?‹æŒ?®šã—ã¾ã?åˆæœŸå€¤:false[行ã‚ãªã„])ã€? 115 * 対象ファイル毎ã«ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ã?スã¸ã®ç™»éŒ²ã‚’完äº?commit)ã™ã‚‹ã‹ã©ã?‹ã‚’指定ã—ã¾ã™ã? 116 * 通常ã€Connection ã¯ã€autoCommit ã‚?false ã«è¨å®šã—ã€?¼‘ä»¶ã”ã¨ã®å‡¦ç??行ã„ã¾ã›ã‚“ã€? 117 * ã•らã«ã€XMLファイルã«ã‚‚相互関連ãŒã‚ã‚‹å?åˆãŒã‚ã‚‹ãŸã‚ã€è¤?•°ãƒ•ァイルをå–り込ã‚??åˆã?ã€? 118 * ãれらをä¸?¾¤ã¨ã—ã¦å‡¦ç?—ãŸã„ケースもã‚りã¾ã™ã?ã¾ãŸã?å?ƒ•ァイルãŒç‹¬ç«‹ã—ã¦ã?‚‹ 119 * å ´åˆã?ã€ä»–ã?ファイルå–ã‚Šè¾¼ã¿æ™‚ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¦ã‚‚ã?ãれã¾ã§ã®åˆ??ã€å–り込ã¿ãŸã„ 120 * ケースãŒã‚りã¾ã™ã? 121 * ã“ã“ã§ã¯ã€ãƒ•ァイル毎ã«ã‚³ãƒŸãƒƒãƒˆã‚’発行ã™ã‚‹ã‹ã©ã?‹ã‚’指定ã§ãã¾ã™ã? 122 * åˆæœŸå€¤ã¯ã€false[行ã‚ãªã„]ã§ã™ã? 123 * ※ true ã«è¨å®šã—ãŸå?åˆã§ã‚‚ã?途ä¸ã§ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ãŸå?åˆã?ã€ãれ以é™ã?処ç??ã€? 124 * 継続ã—ã¾ã›ã‚“。ãれ以å‰ã?処ç?Œã€ç™»éŒ²ã•れã¦ã?‚‹ã?‘ã§ã™ã? 125 * 126 * @param fileCmt ファイル毎ã«ã‚³ãƒŸãƒƒãƒˆå?ç?‚’行ã†ã‹ã©ã?‹ [true:行ã†/false:行ã‚ãªã„] 127 */ 128 public void setFileCommit( final boolean fileCmt ) { 129 fileCommit = fileCmt ; 130 } 131 132 /** 133 * 対象ã¨ãªã‚‹ãƒ•ァイル群を検索ã—ã¾ã™ã? 134 * 対象ファイルã¯ã€resource フォルãƒ?« ãƒ??ブルå?xml å½¢å¼ã§æ ¼ç´ã—ã¦ãŠãã¾ã™ã? 135 * ã“ã?フォルãƒ??ファイルをピãƒ?‚¯ã‚¢ãƒ??ã—ã¾ã™ã? 136 * useTimeStamp 属æ?ã‚?true ã«è¨å®šã™ã‚‹ã¨ã€ã“ã®ãƒ•ァイルã®ã‚¿ã‚¤ãƒ?‚¹ã‚¿ãƒ³ãƒ—ã‚’ã€? 137 * シスãƒ?ƒ パラメータ定義(GE12) ã«ã‚»ãƒ?ƒˆã—ã¾ã™ã?ãれ以é™ã?ã“ã?タイãƒ?‚¹ã‚¿ãƒ³ãƒ—㨠138 * ファイルを比è¼?—ã¦ã€å¤‰æ›´ãŒãªã‘れã°ã€ç™»éŒ²å‡¦ç?‚’行ã„ã¾ã›ã‚“ã€? 139 * 140 * @og.rev 4.0.0.0 (2007/11/28) メソãƒ?ƒ‰ã®æˆ»ã‚Šå?ã‚’ãƒã‚§ãƒ?‚¯ã—ã¾ã™ã? 141 * @og.rev 5.3.6.0 (2011/06/01) 実フォルãƒ??å ´åˆã?フォルãƒ?šŽå±¤ã‚’下る処ç?‚’追åŠ? 142 * @og.rev 5.5.2.6 (2012/05/25) JarFile ã‚’ã?Closer#zipClose( ZipFile ) メソãƒ?ƒ‰ã‚’利用ã—ã¦ã€close ã—ã¾ã™ã? 143 * @og.rev 5.6.6.1 (2013/07/12) jarファイルã®å ´åˆã‚‚ã€ã‚¿ã‚¤ãƒ?‚¹ã‚¿ãƒ³ãƒ—管ç??対象ã¨ã—ã¾ã™ã? 144 * 145 * @param useTimeStamp タイãƒ?‚¹ã‚¿ãƒ³ãƒ—ã?管ç?‚’行ã†ã‹ã©ã?‹[true:行ã†/false:行ã‚ãªã„] 146 */ 147 public void loadInitFiles( final boolean useTimeStamp ) { 148 List<File> fileList = new ArrayList<File>(); 149 150 // 5.5.2.6 (2012/05/25) findbugs対å¿? 151 JarFile jarFile = null; 152 try { 153 // System.out.println( " ==========================" ); 154 155 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 156 Enumeration<URL> enume = loader.getResources( CLASSPATH ); // 4.3.3.6 (2008/11/15) Genericsè¦å‘Šå¯¾å¿? 157 while( enume.hasMoreElements() ) { 158 URL url = enume.nextElement(); // 4.3.3.6 (2008/11/15) Genericsè¦å‘Šå¯¾å¿? 159 // jar:file:/実ディレクトリ ã¾ãŸã?ã€file:/実ディレクトリ 160 System.out.println( " InitFileLoader Scan:[ " + url + " ]" ); // 5.6.6.1 (2013/07/12) メãƒ?‚»ãƒ¼ã‚¸å‡ºåŠ? 161 String dir = url.getFile(); 162 if( "jar".equals( url.getProtocol() ) ) { 163 // dir = file:/C:/webapps/gf/WEB-INF/lib/resource2.jar!/resource å½¢å¼ã§ã™ã? 164 String jar = dir.substring(dir.indexOf( ':' )+1,dir.lastIndexOf( '!' )); 165 // jar = /C:/webapps/gf/WEB-INF/lib/resource2.jar å½¢å¼ã«åˆ?‚Šå‡ºã—ã¾ã™ã? 166 167 // 5.6.6.1 (2013/07/12) jarファイルもã?タイãƒ?‚¹ã‚¿ãƒ³ãƒ—管ç??対象 168 File jarObj = new File( jar ); 169 if( useTimeStamp && jarObj.lastModified() <= 0 ) { // fileObj ã¯ã€jarファイルã®ã“㨠170 continue; 171 } 172 173 // JarFile jarFile = new JarFile( jar ); 174 jarFile = new JarFile( jar ); 175 Enumeration<JarEntry> flEnum = jarFile.entries() ; // 4.3.3.6 (2008/11/15) Genericsè¦å‘Šå¯¾å¿? 176 while( flEnum.hasMoreElements() ) { 177 JarEntry ent = flEnum.nextElement(); // 4.3.3.6 (2008/11/15) Genericsè¦å‘Šå¯¾å¿? 178 String file = ent.getName(); 179 if( ! ent.isDirectory() && file.endsWith( ".xml" ) ) { 180 // // 5.6.6.1 (2013/07/12) jarファイルã®ä¸èº«ã®ã‚¿ã‚¤ãƒ?‚¹ã‚¿ãƒ³ãƒ—ã?見ãªã?? 181 // if( ! useTimeStamp || ent.getTime() > 0 ) { 182 String table = file.substring( file.lastIndexOf('/')+1,file.lastIndexOf('.') ); 183 InputStream stream = null; 184 try { 185 // System.out.println( " " + url + file ); 186 System.out.println( " " + file ); // 5.6.6.1 (2013/07/12) メãƒ?‚»ãƒ¼ã‚¸å¤‰æ›´ 187 stream = jarFile.getInputStream( ent ) ; 188 loadXML( stream,connection,table ); 189 } 190 // catch( IOException ex ) { 191 // String errMsg = "jar ã® XMLファイルèªã¿å–り時ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€? 192 // + HybsSystem.CR + ex.getMessage(); 193 // throw new RuntimeException( errMsg,ex ); 194 // } 195 finally { 196 Closer.ioClose( stream ); 197 } 198 if( fileCommit ) { 199 connection.commit(); 200 } 201 // } 202 } 203 } 204 fileList.add( jarObj ); // 5.6.6.1 (2013/07/12) jarファイルもã?タイãƒ?‚¹ã‚¿ãƒ³ãƒ—管ç??対象 205 Closer.zipClose( jarFile ); // 5.5.2.6 (2012/05/25) findbugs対å¿? 206 jarFile = null; // æ£å¸¸çµ‚äº?™‚ã«ã€close() ãŒï¼’回呼ã°ã‚Œã‚‹ã®ã‚’防ããŸã‚ã? 207 } 208 else { 209 // // dir = /C:/webapps/gf/WEB-INF/classes/resource/ å½¢å¼ã§ã™ã? 210 // File fileObj = new File( dir ); 211 // File[] list = fileObj.listFiles(); 212 // for( int i=0; i<list.length; i++ ) { 213 // String file = list[i].getName() ; 214 // if( list[i].isFile() && file.endsWith( ".xml" ) ) { 215 // if( ! useTimeStamp || list[i].lastModified() > 0 ) { 216 // String table = file.substring( file.lastIndexOf('/')+1,file.lastIndexOf('.') ); 217 // InputStream stream = null; 218 // try { 219 // stream = new FileInputStream( list[i] ) ; 220 // System.out.println( " " + url + file ); 221 // loadXML( stream,connection,table ); 222 // } 223 // catch( IOException ex ) { 224 // String errMsg = "dir ã® XMLファイルèªã¿å–り時ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€? 225 // + HybsSystem.CR + ex.getMessage(); 226 // throw new RuntimeException( errMsg,ex ); 227 // } 228 // finally { 229 // Closer.ioClose( stream ); 230 // } 231 // if( fileCommit ) { 232 // connection.commit(); 233 // if( !list[i].setLastModified( 0L ) ) { 234 // String errMsg = "タイãƒ?‚¹ã‚¿ãƒ³ãƒ—ã?æ›¸ãæ›ãˆã«å¤±æ•—ã—ã¾ã—ãŸã€? 235 // + "file=" + file ; // 5.1.8.0 (2010/07/01) errMsg ä¿®æ£ 236 // System.out.println( errMsg ); 237 // } 238 // } 239 // else { 240 // fileList.add( list[i] ); 241 // } 242 // } 243 // } 244 // } 245 // 5.3.6.0 (2011/06/01) 実フォルãƒ??å ´åˆã?フォルãƒ?šŽå±¤ã‚’下る処ç?‚’追åŠ? 246 // dir = /C:/webapps/gf/WEB-INF/classes/resource/ å½¢å¼ã§ã™ã? 247 File fileObj = new File( dir ); 248 loadXMLDir( fileObj,useTimeStamp,fileList ); 249 } 250 } 251 connection.commit(); 252 // System.out.println( " ==========================" ); 253 } 254 catch( SQLException ex ) { 255 String errMsg = "SQL実行時ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€? 256 + HybsSystem.CR + ex.getMessage(); 257 Closer.rollback( connection ); 258 // if( connection != null ) { 259 // Closer.rollback( connection ); 260 // try { connection.rollback(); } 261 // catch( SQLException ex2 ) { errMsg += ex2.getMessage(); } 262 // } 263 throw new RuntimeException( errMsg,ex ); 264 } 265 catch( IOException ex ) { 266 String errMsg = "XMLファイルèªã¿å–り時ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€? 267 + HybsSystem.CR + ex.getMessage(); 268 throw new RuntimeException( errMsg,ex ); 269 } 270 finally { 271 Closer.zipClose( jarFile ); // 5.5.2.6 (2012/05/25) findbugs対å¿? 272 273 // 5.3.6.0 (2011/06/01) finally 処ç?§ã€ã‚¿ã‚¤ãƒ?‚¹ã‚¿ãƒ³ãƒ—ã?æ›¸ãæ›ãˆã‚’行ã†ã€? 274 275 // commit ãŒæ?功ã—ãŸå?åˆã?ã¿ã€ãƒ•ァイルã®ã‚¿ã‚¤ãƒ?‚¹ã‚¿ãƒ³ãƒ—ã?æ›¸ãæ›ãˆã‚’行ã†ã€? 276 // if( ! fileCommit ) { 277 // File[] files = fileList.toArray( new File[fileList.size()] ); 278 // for( int i=0; i<files.length; i++ ) { 279 // 5.6.6.1 (2013/07/12) useTimeStamp=true ã®å ´åˆã?ã¿ã€æ›¸ãæ›ãˆã¾ã™ã? 280 if( useTimeStamp ) { 281 for( File file : fileList ) { 282 if( !file.setLastModified( 0L ) ) { 283 String errMsg = "タイãƒ?‚¹ã‚¿ãƒ³ãƒ—ã?æ›¸ãæ›ãˆã«å¤±æ•—ã—ã¾ã—ãŸã€? 284 + "file=" + file ; // 5.1.8.0 (2010/07/01) errMsg ä¿®æ£ 285 System.out.println( errMsg ); 286 } 287 } 288 } 289 } 290 } 291 292 /** 293 * XMLフォルãƒ?ファイルをèªã¿å–りã€ãƒ‡ãƒ¼ã‚¿ãƒ™ã?スã«è¿½åŠ?INSERT)ã™ã‚‹ãƒ¡ã‚½ãƒ?ƒ‰ã‚’コールã—ã¾ã™ã? 294 * 295 * ã“ã“ã§ã¯ã€ãƒ•ォルãƒ?šŽå±¤ã‚’下るãŸã‚ã®å†èµ·å‡¦ç?‚’行ã£ã¦ã?¾ã™ã? 296 * XMLファイルã¯ã€ORACLE XDK拡張ファイルã§ã™ã?ãƒ??ブルåã‚’æŒ?®šã™ã‚‹ã“ã¨ã§ã€? 297 * XMLファイルをデータベã?スã«ç™»éŒ²ã™ã‚‹ã“ã¨ãŒå¯èƒ½ã§ã™ã? 298 * ORACLE XDK拡張ファイルã‚??EXEC_SQLã‚¿ã‚°ãªã©ã®è©³ç´°ã¯ã€{@link org.opengion.fukurou.xml.HybsXMLSave} 299 * ã‚’å‚照願ã„ã¾ã™ã? 300 * 301 * @og.rev 5.3.6.0 (2011/06/01) 実フォルãƒ??å ´åˆã?フォルãƒ?šŽå±¤ã‚’下る処ç?‚’追åŠ? 302 * 303 * @param fileObj èªå–å?ã®ãƒ•ァイルオブジェクãƒ? 304 * @param useTimeStamp タイãƒ?‚¹ã‚¿ãƒ³ãƒ—ã?管ç?‚’行ã†ã‹ã©ã?‹[true:行ã†/false:行ã‚ãªã„] 305 * @param fileList 処ç?—ãŸãƒ•ァイルをä¿ç®¡ã—ã¦ãŠãListオブジェクãƒ? 306 * @throws SQLException,IOException 307 */ 308 private void loadXMLDir( final File fileObj , final boolean useTimeStamp , final List<File> fileList ) 309 throws SQLException,IOException { 310 // dir = /C:/webapps/gf/WEB-INF/classes/resource/ å½¢å¼ã§ã™ã? 311 File[] list = fileObj.listFiles(); 312 // Arrays.sort( list ); 313 for( int i=0; i<list.length; i++ ) { 314 String file = list[i].getName() ; 315 if( list[i].isFile() && file.endsWith( ".xml" ) ) { 316 if( ! useTimeStamp || list[i].lastModified() > 0 ) { 317 String table = file.substring( file.lastIndexOf('/')+1,file.lastIndexOf('.') ); 318 InputStream stream = null; 319 try { 320 System.out.println( " " + list[i] ); 321 stream = new FileInputStream( list[i] ) ; 322 loadXML( stream,connection,table ); 323 } 324 // catch( IOException ex ) { 325 // String errMsg = "dir ã® XMLファイルèªã¿å–り時ã«ã‚¨ãƒ©ãƒ¼ãŒç™ºç”Ÿã—ã¾ã—ãŸã€? 326 // + HybsSystem.CR + ex.getMessage(); 327 // throw new RuntimeException( errMsg,ex ); 328 // } 329 finally { 330 Closer.ioClose( stream ); 331 } 332 if( fileCommit ) { 333 connection.commit(); 334 } 335 fileList.add( list[i] ); 336 } 337 } 338 else { 339 loadXMLDir( list[i],useTimeStamp,fileList ); 340 } 341 } 342 } 343 344 /** 345 * XMLファイルをèªã¿å–りã€ãƒ‡ãƒ¼ã‚¿ãƒ™ã?スã«è¿½åŠ?INSERT)ã—ã¾ã™ã? 346 * 347 * XMLファイルã¯ã€ORACLE XDK拡張ファイルã§ã™ã?ãƒ??ブルåã‚’æŒ?®šã™ã‚‹ã“ã¨ã§ã€? 348 * XMLファイルをデータベã?スã«ç™»éŒ²ã™ã‚‹ã“ã¨ãŒå¯èƒ½ã§ã™ã? 349 * ORACLE XDK拡張ファイルã‚??EXEC_SQLã‚¿ã‚°ãªã©ã®è©³ç´°ã¯ã€{@link org.opengion.fukurou.xml.HybsXMLSave} 350 * ã‚’å‚照願ã„ã¾ã™ã? 351 * 352 * @param stream èªã¿å–るストリーãƒ? 353 * @param conn DB接続ã?コãƒã‚¯ã‚·ãƒ§ãƒ³ 354 * @param table 追åŠ?™ã‚‹ãƒ†ãƒ¼ãƒ–ルå? 355 * 356 * @og.rev 5.6.6.1 (2013/07/12) 更新カウント数もå–å¾—ã—ã¾ã™ã? 357 * @og.rev 5.6.7.0 (2013/07/27) HybsXMLSave ã® DDL?ˆãƒ‡ãƒ¼ã‚¿å®šç¾©è¨?ªžï¼šData Definition Language?‰ã?処ç?»¶æ•°è¿½åŠ? 358 * @og.rev 5.6.9.2 (2013/10/18) EXEC_SQL ã®ã‚¨ãƒ©ãƒ¼æ™‚ã« Exception を発行ã—ãªã?? 359 * 360 * @return 追åŠ?•れãŸä»¶æ•° 361 * @see org.opengion.fukurou.xml.HybsXMLSave 362 */ 363 private int loadXML( final InputStream stream, final Connection conn,final String table ) 364 throws SQLException,UnsupportedEncodingException { 365 366 // InputStream よりã€XMLファイルをèªã¿å–りã€table ã«è¿½åŠ?INSERT)ã—ã¾ã™ã? 367 Reader reader = new BufferedReader( new InputStreamReader( stream,"UTF-8" ) ); 368 HybsXMLSave save = new HybsXMLSave( conn,table ); 369 save.onExecErrException( false ); // 5.6.9.2 (2013/10/18) EXEC_SQL ã®ã‚¨ãƒ©ãƒ¼æ™‚ã« Exception を発行ã—ãªã?? 370 save.insertXML( reader ); 371 int insCnt = save.getInsertCount(); 372 int delCnt = save.getDeleteCount(); 373 int updCnt = save.getUpdateCount(); // 5.6.6.1 (2013/07/12) 更新カウント数もå–å¾? 374 int ddlCnt = save.getDDLCount(); // 5.6.7.0 (2013/07/27) DDL処ç?»¶æ•°è¿½åŠ? 375 String tableName = save.getTableName() ; 376 377 // System.out.println( " TABLE=[" + tableName + "] DELETE=["+ delCnt +"] INSERT=[" + insCnt + "]" ); 378 // System.out.println( " TABLE=[" + tableName + "] DELETE=["+ delCnt +"] INSERT=[" + insCnt + "] UPDATE=[" + updCnt + "]" ); 379 System.out.println( " TABLE=[" + tableName + "] DELETE=["+ delCnt +"] INSERT=[" + insCnt + "] UPDATE=[" + updCnt + "] DDL=[" + ddlCnt + "]" ); 380 return insCnt; 381 } 382 }