src/org/objectweb/cjdbc/controller/scheduler/raidb1/RAIDb1PessimisticTransactionLevelScheduler.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.controller.scheduler.raidb1; 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.util.Constants; 00033 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 00034 import org.objectweb.cjdbc.controller.requestmanager.RAIDbLevels; 00035 import org.objectweb.cjdbc.controller.scheduler.AbstractScheduler; 00036 import org.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock; 00037 00046 public class RAIDb1PessimisticTransactionLevelScheduler 00047 extends 00048 AbstractScheduler 00049 { 00050 00051 // 00052 // How the code is organized ? 00053 // 00054 // 1. Member variables 00055 // 2. Constructor 00056 // 3. Request handling 00057 // 4. Transaction management 00058 // 5. Debug/Monitoring 00059 // 00060 00061 private long requestId; 00062 00063 TransactionExclusiveLock lock = new TransactionExclusiveLock(); 00064 00065 // 00066 // Constructor 00067 // 00068 00072 public RAIDb1PessimisticTransactionLevelScheduler() 00073 { 00074 super(RAIDbLevels.RAIDb1, ParsingGranularities.NO_PARSING); 00075 } 00076 00077 // 00078 // Request Handling 00079 // 00080 00087 public final void scheduleReadRequest(SelectRequest request) 00088 throws SQLException 00089 { 00090 synchronized (this) 00091 { 00092 request.setId(requestId++); 00093 } 00094 } 00095 00099 public final void readCompletedNotify(SelectRequest request) 00100 { 00101 } 00102 00108 public void scheduleNonSuspendedWriteRequest(AbstractWriteRequest request) 00109 throws SQLException 00110 { 00111 if (request.isCreate()) 00112 { 00113 synchronized (this) 00114 { 00115 request.setId(requestId++); 00116 } 00117 return; 00118 } 00119 00120 if (lock.acquire(request)) 00121 { 00122 synchronized (this) 00123 { 00124 request.setId(requestId++); 00125 } 00126 if (logger.isDebugEnabled()) 00127 logger.debug("Request " + request.getId() + " scheduled for write (" 00128 + getPendingWrites() + " pending writes)"); 00129 } 00130 else 00131 { 00132 if (logger.isWarnEnabled()) 00133 logger.warn("Request " + request.getId() + " timed out (" 00134 + request.getTimeout() + " s)"); 00135 throw new SQLException("Timeout (" + request.getTimeout() 00136 + ") for request: " 00137 + request.getSQLShortForm(Constants.SQL_SHORT_FORM_LENGTH)); 00138 } 00139 } 00140 00144 public final synchronized void notifyWriteCompleted( 00145 AbstractWriteRequest request) 00146 { 00147 // Requests outside transaction delimiters must release the lock 00148 // as soon as they have executed 00149 if (request.isAutoCommit() && (!request.isCreate())) 00150 releaseLock(request.getTransactionId()); 00151 } 00152 00153 // 00154 // Transaction Management 00155 // 00156 00160 protected final void commitTransaction(long transactionId) 00161 { 00162 releaseLock(transactionId); 00163 } 00164 00168 protected final void rollbackTransaction(long transactionId) 00169 { 00170 releaseLock(transactionId); 00171 } 00172 00178 private void releaseLock(long transactionId) 00179 { 00180 // Are we the lock owner ? 00181 if (lock.isLocked()) 00182 { 00183 if (lock.getLocker() == transactionId) 00184 lock.release(); 00185 00186 // Note that the following warnings could be safely ignored if the 00187 // transaction commiting/rollbacking (releasing the lock) has not done any 00188 // conflicting write 00189 else if (logger.isDebugEnabled()) 00190 logger.debug("Transaction " + transactionId 00191 + " wants to release the lock held by transaction " 00192 + lock.getLocker()); 00193 } 00194 else if (logger.isDebugEnabled()) 00195 logger.warn("Transaction " + transactionId 00196 + " tries to release a lock that has not been acquired."); 00197 } 00198 00199 // 00200 // Debug/Monitoring 00201 // 00205 public String getXmlImpl() 00206 { 00207 return "<" + DatabasesXmlTags.ELT_RAIDb1Scheduler + " " 00208 + DatabasesXmlTags.ATT_level + "=\"" 00209 + DatabasesXmlTags.VAL_pessimisticTransaction + "\"/>"; 00210 } 00211 00212 }

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