Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to set eclipselink reconnect atampts to one

 
mjwaa keeelldd
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to set eclipselink reconnect atampts to one .because when swing code executes a query if database is down then the gui will hang or freeze for some times its not a good idea to do.
are there any other ways to throw the exception and inside try catch just show it to user?

i went trougheclipselink sourc code,
this is a snapshot from .
class DatabaseLogin extends DatasourceLogin{

public DatabaseLogin(DatabasePlatform databasePlatform) {
super(databasePlatform);
this.useDefaultDriverConnect();
this.delayBetweenConnectionAttempts = 5000;
this.queryRetryAttemptCount = 3;
this.connectionHealthValidatedOnError = true;
}
}



this is a snapshot from AbstractSession .java


protected void basicBeginTransaction(int retryCount, Accessor accessor) throws DatabaseException {
try {
accessor.beginTransaction(this);
} catch (DatabaseException databaseException) {
// Retry if the failure was communication based? (i.e. timeout, database down, can no longer ping)
if ((!getDatasourceLogin().shouldUseExternalTransactionController()) && databaseException.isCommunicationFailure()) {
DatabaseException exceptionToThrow = databaseException;
log(SessionLog.INFO, "communication_failure_attempting_query_retry", (Object[])null, null);
// Attempt to reconnect connection.
while (retryCount < getLogin().getQueryRetryAttemptCount()) {
try {
// if database session then re-establish
// connection
// else the session will just get a new
// connection from the pool
databaseException.getAccessor().reestablishConnection(this);
break;
} catch (DatabaseException ex) {
// failed to get connection because of
// database error.
++retryCount;
try {
// Give the failover time to recover.
Thread.currentThread().sleep(getLogin().getDelayBetweenConnectionAttempts());
log(SessionLog.INFO, "communication_failure_attempting_begintransaction_retry", (Object[])null, null);
} catch (InterruptedException intEx) {
break;
}
}
}
//retry
if (retryCount <= getLogin().getQueryRetryAttemptCount()) {
try {
// attempt to reconnect for a certain number of times.
// servers may take some time to recover.
++retryCount;
try {
//passing the retry count will prevent a runaway retry where
// we can acquire connections but are unable to execute any queries
if (retryCount > 1){
// We are retrying more than once lets wait to give connection time to restart.
//Give the failover time to recover.
Thread.currentThread().sleep(getLogin().getDelayBetweenConnectionAttempts());
}
basicBeginTransaction(retryCount, accessor);
return;
} catch (DatabaseException ex){
//replace original exception with last exception thrown
//this exception could be a data based exception as opposed
//to a connection exception that needs to go back to the customer.
exceptionToThrow = ex;
}
} catch (InterruptedException ex) {
//Ignore interrupted exception.
}
}
handleException(exceptionToThrow);
} else {
handleException(databaseException);
}
} catch (RuntimeException exception) {
handleException(exception);
}
}
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can be configured on your Session's DatabaseLogin (you can configure the Session using a SessionCustomizer in JPA).


login.setQueryRetryAttemptCount(0);

you may also try,

login.setConnectionHealthValidatedOnError(false)
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic