src/org/objectweb/cjdbc/controller/scheduler/singledb/SingleDBPessimisticTransactionLevelScheduler.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.controller.scheduler.singledb; 00026 00027 import java.sql.SQLException; 00028 00029 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest; 00030 import org.objectweb.cjdbc.common.sql.ParsingGranularities; 00031 import org.objectweb.cjdbc.common.sql.SelectRequest; 00032 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 00033 import org.objectweb.cjdbc.controller.requestmanager.RAIDbLevels; 00034 import org.objectweb.cjdbc.controller.scheduler.AbstractScheduler; 00035 import org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock; 00036 00045 public class SingleDBPessimisticTransactionLevelScheduler 00046 extends 00047 AbstractScheduler 00048 { 00049 00050 // 00051 // How the code is organized ? 00052 // 00053 // 1. Member variables 00054 // 2. Constructor 00055 // 3. Request handling 00056 // 4. Transaction management 00057 // 5. Debug/Monitoring 00058 // 00059 00060 private long requestId; 00061 TransactionExclusiveLock lock = new TransactionExclusiveLock(); 00062 00063 // 00064 // Constructor 00065 // 00066 00070 public SingleDBPessimisticTransactionLevelScheduler() 00071 { 00072 super(RAIDbLevels.SingleDB, ParsingGranularities.NO_PARSING); 00073 } 00074 00075 // 00076 // Request Handling 00077 // 00078 00085 public final synchronized void scheduleReadRequest(SelectRequest request) 00086 throws SQLException 00087 { 00088 request.setId(requestId++); 00089 } 00090 00094 public final void readCompletedNotify(SelectRequest request) 00095 { 00096 } 00097 00104 public void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request) 00105 throws SQLException 00106 { 00107 if (lock.acquire(request)) 00108 { 00109 synchronized (this) 00110 { 00111 request.setId(requestId++); 00112 } 00113 if (logger.isDebugEnabled()) 00114 logger.debug("Request " + request.getId() + " scheduled for write (" 00115 + getPendingWrites() + " pending writes)"); 00116 } 00117 else 00118 { 00119 if (logger.isWarnEnabled()) 00120 logger.warn("Request " + request.getId() + " timed out (" 00121 + request.getTimeout() + " s)"); 00122 throw new SQLException("Timeout (" + request.getTimeout() 00123 + ") for request: " + request.getId()); 00124 } 00125 } 00126 00130 public final synchronized void notifyWriteCompleted( 00131 AbstractWriteRequest request) 00132 { 00133 // Requests outside transaction delimiters must release the lock 00134 // as soon as they have executed 00135 if (request.isAutoCommit()) 00136 releaseLock(request.getTransactionId()); 00137 } 00138 00139 // 00140 // Transaction Management 00141 // 00142 00146 protected final void commitTransaction(long transactionId) 00147 { 00148 releaseLock(transactionId); 00149 } 00150 00154 protected final void rollbackTransaction(long transactionId) 00155 { 00156 releaseLock(transactionId); 00157 } 00158 00164 private void releaseLock(long transactionId) 00165 { 00166 // Are we the lock owner ? 00167 if (lock.isLocked()) 00168 { 00169 if (lock.getLocker() == transactionId) 00170 lock.release(); 00171 00172 // Note that the following warnings could be safely ignored if the 00173 // transaction 00174 // commiting/rolllbacking (releasing the lock) has not done any 00175 // conflicting write 00176 else if (logger.isDebugEnabled()) 00177 logger.debug("Transaction " + transactionId 00178 + " wants to release the lock held by transaction " 00179 + lock.getLocker()); 00180 } 00181 else if (logger.isDebugEnabled()) 00182 logger.warn("Transaction " + transactionId 00183 + " tries to release a lock that has not been acquired."); 00184 } 00185 00186 // 00187 // Debug/Monitoring 00188 // 00189 00193 public String getXmlImpl() 00194 { 00195 return "<" + DatabasesXmlTags.ELT_SingleDBScheduler + " " 00196 + DatabasesXmlTags.ATT_level + "=\"" 00197 + DatabasesXmlTags.VAL_pessimisticTransaction + "\"/>"; 00198 } 00199 00200 }

CJDBCversion1.0.4に対してTue Oct 12 15:16:04 2004に生成されました。 doxygen 1.3.8