import javax.sql.rowset.CachedRowSet;
import org.apache.tomcat.jdbc.pool.PooledConnection;
-import org.apache.tomcat.jdbc.pool.ProxyConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public boolean lockTable(String tablename) {
this.tableName = tablename;
- return locked = dataSource.lockTable(connection, tableName);
+ locked = dataSource.lockTable(connection, tableName);
+ return locked;
}
public void resetInactivityTimer() {
public boolean unlock() {
dataSource.unlockTable(connection);
- return locked = false;
+ locked = false;
+ return locked;
}
public boolean writeData(String statement, ArrayList<String> arguments) throws SQLException, Throwable
{
- ArrayList<Object> newList=new ArrayList<Object>();
+ ArrayList<Object> newList= new ArrayList<>();
if(arguments != null && !arguments.isEmpty()) {
newList.addAll(arguments);
}
public CachedRowSet getData(String statement, ArrayList<String> arguments) throws SQLException, Throwable
{
- ArrayList<Object> newList=new ArrayList<Object>();
+ ArrayList<Object> newList= new ArrayList<>();
if(arguments != null && !arguments.isEmpty()) {
newList.addAll(arguments);
}
import java.util.Properties;
import java.util.Queue;
import java.util.Set;
-import java.util.Timer;
import java.util.TimerTask;
-import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.sql.DataSource;
protected final AtomicBoolean dsSelector = new AtomicBoolean();
// Queue<CachedDataSource> dsQueue = new ConcurrentLinkedQueue<CachedDataSource>();
- Queue<CachedDataSource> dsQueue = new PriorityQueue<CachedDataSource>(4, new Comparator<CachedDataSource>(){
-
+ Queue<CachedDataSource> dsQueue = new PriorityQueue<>(4, new Comparator<CachedDataSource>() {
@Override
public int compare(CachedDataSource left, CachedDataSource right) {
try {
- if(!left.isSlave())
+ if (!left.isSlave()) {
return -1;
- if(!right.isSlave())
+ }
+ if (!right.isSlave()) {
return 1;
-
+ }
} catch (Throwable e) {
LOGGER.warn("", e);
}
return 0;
}
-
- });
+ });
protected final Set<CachedDataSource> broken = Collections.synchronizedSet(new HashSet<CachedDataSource>());
protected final Object monitor = new Object();
protected final Properties configProps;
class RecoveryMgr extends Thread {
+ @Override
public void run() {
while(!terminating)
{
*/
@Override
public CachedRowSet getData(String statement, ArrayList<String> arguments, String preferredDS) throws SQLException {
- ArrayList<Object> newList=new ArrayList<Object>();
+ ArrayList<Object> newList= new ArrayList<>();
if(arguments != null && !arguments.isEmpty()) {
newList.addAll(arguments);
}
CachedDataSource active = null;
// test if there are any connection pools available
- LinkedList<CachedDataSource> sources = new LinkedList<CachedDataSource>(this.dsQueue);
+ LinkedList<CachedDataSource> sources = new LinkedList<>(this.dsQueue);
if(sources.isEmpty()){
LOGGER.error("Generated alarm: DBResourceManager.getData - No active DB connection pools are available.");
throw new DBLibException("No active DB connection pools are available in RequestDataWithRecovery call.");
handleGetConnectionException(active, exc);
} finally {
if(LOGGER.isDebugEnabled()){
- time = (System.currentTimeMillis() - time);
+ time = System.currentTimeMillis() - time;
LOGGER.debug("getData processing time : "+ active.getDbConnectionName()+" "+time+" miliseconds.");
}
}
}
} finally {
if(LOGGER.isDebugEnabled()){
- time = (System.currentTimeMillis() - time);
+ time = System.currentTimeMillis() - time;
LOGGER.debug(">> getData : "+ active.getDbConnectionName()+" "+time+" miliseconds.");
}
}
@Override
public boolean writeData(String statement, ArrayList<String> arguments, String preferredDS) throws SQLException
{
- ArrayList<Object> newList=new ArrayList<Object>();
+ ArrayList<Object> newList= new ArrayList<>();
if(arguments != null && !arguments.isEmpty()) {
newList.addAll(arguments);
}
}
} finally {
if(LOGGER.isDebugEnabled()){
- time = (System.currentTimeMillis() - time);
+ time = System.currentTimeMillis() - time;
LOGGER.debug("writeData processing time : "+ active.getDbConnectionName()+" "+time+" miliseconds.");
}
}
public String getDBStatus(boolean htmlFormat) {
StringBuilder buffer = new StringBuilder();
- ArrayList<CachedDataSource> list = new ArrayList<CachedDataSource>();
+ ArrayList<CachedDataSource> list = new ArrayList<>();
list.addAll(dsQueue);
list.addAll(broken);
if (htmlFormat)
public String getPreferredDataSourceName(AtomicBoolean flipper) {
- LinkedList<CachedDataSource> snapshot = new LinkedList<CachedDataSource>(dsQueue);
+ LinkedList<CachedDataSource> snapshot = new LinkedList<>(dsQueue);
if(snapshot.size() > 1){
CachedDataSource first = snapshot.getFirst();
CachedDataSource last = snapshot.getLast();