// conn.setAutoCommit(true); //Problematic with DBCP?
session.setFlushMode(FlushMode.COMMIT);
getSessionStatus().setSession(session);
if (!session.isOpen()) {
throw new WGUnavailableException(_db, "Unable to connect to hibernate session");
}
// special handling if loadbalancing is enabled
if (hasFeature(WGDatabase.FEATURE_LOADBALANCE)) {
// set all connections to readonly except master sessions and if
// update is in progress
boolean readOnly;
if (master) {
readOnly = false;
} else {
readOnly = !isUpdateInProgress(authSession.getDistinguishedName());
}
try {
session.connection().setReadOnly(readOnly);
}
catch (SQLException e) {
throw new WGBackendException("Unable to set readonly flag on connection." , e);
}
}
if (getTransactionMode() != WGSessionContext.TRANSACTION_MODE_MANUAL) {
session.beginTransaction();
}
if (master) {
// Master login always has manager access
getSessionStatus().setUserDetails(new WGUserDetails(WGDatabase.ACCESSLEVEL_MANAGER, WGDatabase.MASTER_USERNAME ,"(None)", null, null, null, null, null, true, true));
return new WGUserAccess(WGDatabase.MASTER_USERNAME, WGDatabase.ACCESSLEVEL_MANAGER);
}
// Determine access
WGUserDetails userDetails;
try {
userDetails = _db.defaultBuildUserDetails(authSession);
}
catch (WGBackendException e) {
try {
closeSession();
}
catch (WGBackendException e1) {
WGFactory.getLogger().error(e1);
}
throw e;
}
getSessionStatus().setUserDetails(userDetails);
if (userDetails.getAccessLevel() <= WGDatabase.ACCESSLEVEL_NOACCESS) {
try {
closeSession();
}
catch (WGBackendException e) {
WGFactory.getLogger().error(e);
}
}
return userDetails;
}
catch (HibernateException e) {
try {
closeSession();
}
catch (WGBackendException e1) {
WGFactory.getLogger().error(e1);
}
throw new WGUnavailableException(_db, "Error opening hibernate session", e);
}
}