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.fukurou.db.Transaction; 019 import org.opengion.fukurou.db.TransactionImpl; 020 021 import java.io.ObjectOutputStream; 022 import java.io.ObjectInputStream; 023 import java.io.IOException; 024 025 /** 026 * コネクションを?有して、トランザクションを実現します? 027 * 028 * 通常のタグでは、コネクションプ?ルより、その時?のコネクションを取り?して利用するため? 029 * タグごとに異なるコネクションで処?れます? 030 * また?commit ?rollback などもそれぞれ?タグで行われるため??続??にエラー? 031 * 発生しても?中途半端な状態になります? 032 * ここでは、各 DBID 単位にコネクションを?有し、このタグの間?、同じオブジェクトを 033 * commit ??rollback せずに使?わすようにします? 034 * これにより、?タグ間?トランザクション??異な?DBID 間?トランザクション? 035 * 実現します? 036 * 037 * こ?タグは、doEndTag() メソ?が正常に呼び出されることで、トランザクションが?立します? 038 * つまり?途中で、JSP出力が、SKIP_PAGE された?合?、commit もされません? 039 * これは、データベ?スエラー以外?エラーでも?トランザクション処?れることを意味します? 040 * 041 * @og.formSample 042 * ●形式?lt;og:transaction > ... </og:transaction > 043 * ●body?あ?EVAL_BODY_INCLUDE:BODYをインクルードし、{@XXXX} は解析しません) 044 * 045 * ●Tag定義?? 046 * <og:transaction 047 * debug 【TAG】デバッグ??を?力するかど?[true/false]を指定しま?初期値:false) 048 * > ... Body ... 049 * </og:transaction> 050 * 051 * ●使用? 052 * <og:transaction > 053 * <og:query command="NEW" dbid="SERVER1" > 054 * insert into XX01 (aa,bb,cc) values ('AA','BB','CC') /> 055 * </og:query > 056 * <og:query command="NEW" dbid="SERVER2" > 057 * update YY02 set aa='AA',bb='BB',cc='CC' where uniq='00001' /> 058 * </og:query > 059 * </og:transaction > 060 * 061 * @og.rev 5.1.9.0 (2010/08/01) 新規作? 062 * @og.group ??登録 063 * 064 * @version 5.0 065 * @author Kazuhiko Hasegawa 066 * @since JDK6.0, 067 */ 068 public class TransactionTag extends CommonTagSupport { 069 //* こ?プログラ??VERSION??を設定します? {@value} */ 070 private static final String VERSION = "5.1.9.0 (2010/08/01)" ; 071 private static final long serialVersionUID = 519020100801L ; 072 073 // TransactionTag では、Transaction インターフェースではなく?実?ラスで管?ます? 074 private TransactionImpl tran = null; 075 076 /** 077 * Taglibの開始タグが見つかったときに処??doStartTag() ?オーバ?ライドします? 078 * 079 * @return 後続????( EVAL_BODY_INCLUDE ) 080 */ 081 @Override 082 public int doStartTag() { 083 tran = new TransactionImpl( getApplicationInfo() ); 084 085 return( EVAL_BODY_INCLUDE ); // Body インクルー? extends TagSupport ? 086 } 087 088 /** 089 * Taglibの終?グが見つかったときに処??doEndTag() ?オーバ?ライドします? 090 * 091 * @return 後続???? 092 */ 093 @Override 094 public int doEndTag() { 095 debugPrint(); // 4.0.0 (2005/02/28) 096 097 // finish() は、TransactionImpl のメソ?です? 098 if( tran != null ) { tran.finish(); } 099 100 return(EVAL_PAGE); // ペ?ジの残りを評価する? 101 } 102 103 /** 104 * タグリブオブジェクトをリリースします? 105 * キャ?ュされて再利用される?で、フィールド?初期設定を行います? 106 * 107 */ 108 @Override 109 protected void release2() { 110 super.release2(); 111 112 // realClose() は、TransactionImpl のメソ?です? 113 if( tran != null ) { tran.realClose(); } 114 tran = null; 115 } 116 117 /** 118 * Transactionオブジェクトを返します? 119 * 120 * @return Transactionオブジェク? 121 */ 122 protected Transaction getTransaction() { 123 return tran ; 124 } 125 126 /** 127 * シリアライズ用のカスタ?リアライズ書き込みメソ? 128 * 129 * @og.rev 4.0.0.0 (2006/09/31) 新規追? 130 * @serialData ?のオブジェクト?、シリアライズされません? 131 * 132 * @param strm ObjectOutputStreamオブジェク? 133 * @throws IOException 入出力エラーが発生した?? 134 */ 135 private void writeObject( final ObjectOutputStream strm ) throws IOException { 136 strm.defaultWriteObject(); 137 } 138 139 /** 140 * シリアライズ用のカスタ?リアライズ読み込みメソ? 141 * 142 * ここでは、transient 宣?れた?変数の??初期化が?なフィールド?み設定します? 143 * 144 * @og.rev 4.0.0.0 (2006/09/31) 新規追? 145 * @serialData ?のオブジェクト?、シリアライズされません? 146 * 147 * @param strm ObjectInputStreamオブジェク? 148 * @see #release2() 149 * @throws IOException シリアライズに関する入出力エラーが発生した?? 150 * @throws ClassNotFoundException クラスを見つけることができなかった?? 151 */ 152 private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException { 153 strm.defaultReadObject(); 154 } 155 156 /** 157 * こ?オブジェクト???表現を返します? 158 * 基本???目?使用します? 159 * 160 * @return こ?クラスの??表現 161 */ 162 @Override 163 public String toString() { 164 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() ) 165 .println( "VERSION" ,VERSION ) 166 .println( "Other..." ,getAttributes().getAttribute() ) 167 .fixForm().toString() ; 168 } 169 }