• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to set eclipselink reconnect atampts to one

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
I'm still in control here. LOOK at this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic