1 16 17 package org.springframework.jdbc.datasource.lookup; 18 19 import org.springframework.core.Constants; 20 import org.springframework.transaction.TransactionDefinition; 21 import org.springframework.transaction.support.DefaultTransactionDefinition; 22 import org.springframework.transaction.support.TransactionSynchronizationManager; 23 24 92 public class IsolationLevelDataSourceRouter extends AbstractRoutingDataSource { 93 94 95 private static final Constants constants = new Constants(TransactionDefinition.class); 96 97 98 103 protected Object resolveSpecifiedLookupKey(Object lookupKey) { 104 if (lookupKey instanceof Integer ) { 105 return (Integer ) lookupKey; 106 } 107 else if (lookupKey instanceof String ) { 108 String constantName = (String ) lookupKey; 109 if (constantName == null || !constantName.startsWith(DefaultTransactionDefinition.PREFIX_ISOLATION)) { 110 throw new IllegalArgumentException ("Only isolation constants allowed"); 111 } 112 return constants.asNumber(constantName); 113 } 114 else { 115 throw new IllegalArgumentException ( 116 "Invalid lookup key - needs to be isolation level Integer or isolation level name String: " + lookupKey); 117 } 118 } 119 120 protected Object determineCurrentLookupKey() { 121 return TransactionSynchronizationManager.getCurrentTransactionIsolationLevel(); 122 } 123 124 } 125 | Popular Tags |