Refs #10221: Reopen DB connection if closed
Task-Url: https://support.d4science.org/issues/10221 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158229 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f59b3b550f
commit
f4673a0517
|
@ -55,23 +55,15 @@ public abstract class SecurityContextMapper {
|
|||
factory.setConnectionStrategy(DatabaseIntializator.CONNECTION_STRATEGY_PARAMETER.toString());
|
||||
|
||||
for (PermissionMode p : PermissionMode.values()) {
|
||||
OrientGraphFactory f = new OrientGraphFactory(
|
||||
DatabaseEnvironment.DB_URI,
|
||||
DatabaseEnvironment.CHANGED_ADMIN_USERNAME,
|
||||
DatabaseEnvironment.CHANGED_ADMIN_PASSWORD)
|
||||
.setupPool(1, 10);
|
||||
|
||||
f.setConnectionStrategy(DatabaseIntializator.CONNECTION_STRATEGY_PARAMETER.toString());
|
||||
|
||||
Map<UUID, OrientGraphFactory> map = new HashMap<>();
|
||||
map.put(ADMIN_SECURITY_CONTEXT_UUID, f);
|
||||
securityContextFactories.put(p, map);
|
||||
|
||||
getSecurityContextFactory(ADMIN_SECURITY_CONTEXT_UUID, p, false);
|
||||
}
|
||||
|
||||
|
||||
if (created) {
|
||||
OrientGraph orientGraph = factory.getTx();
|
||||
SecurityContext.createSecurityContext(orientGraph,
|
||||
MANAGEMENT_SECURITY_CONTEXT_UUID);
|
||||
SecurityContext.createSecurityContext(orientGraph, MANAGEMENT_SECURITY_CONTEXT_UUID);
|
||||
|
||||
getSecurityContextFactory(MANAGEMENT_SECURITY_CONTEXT_UUID,
|
||||
PermissionMode.READER, false);
|
||||
|
@ -124,8 +116,7 @@ public abstract class SecurityContextMapper {
|
|||
UUID context, PermissionMode permissionMode, boolean recreate) {
|
||||
OrientGraphFactory factory = null;
|
||||
|
||||
Map<UUID, OrientGraphFactory> permissionSecurityContextFactories = securityContextFactories
|
||||
.get(permissionMode);
|
||||
Map<UUID, OrientGraphFactory> permissionSecurityContextFactories = securityContextFactories.get(permissionMode);
|
||||
|
||||
if(recreate) {
|
||||
permissionSecurityContextFactories.remove(context);
|
||||
|
@ -134,12 +125,18 @@ public abstract class SecurityContextMapper {
|
|||
}
|
||||
|
||||
if (factory == null) {
|
||||
|
||||
String username = getSecurityRoleOrUserName(permissionMode,
|
||||
SecurityType.USER, context);
|
||||
String password = DatabaseEnvironment.DEFAULT_PASSWORDS
|
||||
.get(permissionMode);
|
||||
|
||||
|
||||
String username = null;
|
||||
String password = null;
|
||||
|
||||
if(context.compareTo(ADMIN_SECURITY_CONTEXT_UUID)==0){
|
||||
username = DatabaseEnvironment.CHANGED_ADMIN_USERNAME;
|
||||
password = DatabaseEnvironment.CHANGED_ADMIN_PASSWORD;
|
||||
}else {
|
||||
username = getSecurityRoleOrUserName(permissionMode, SecurityType.USER, context);
|
||||
password = DatabaseEnvironment.DEFAULT_PASSWORDS.get(permissionMode);
|
||||
}
|
||||
|
||||
factory = new OrientGraphFactory(DatabaseEnvironment.DB_URI,
|
||||
username, password).setupPool(1, 10);
|
||||
factory.setConnectionStrategy(DatabaseIntializator.CONNECTION_STRATEGY_PARAMETER.toString());
|
||||
|
@ -152,7 +149,7 @@ public abstract class SecurityContextMapper {
|
|||
|
||||
public static OrientGraph getSecurityContextGraph(
|
||||
UUID context, PermissionMode permissionMode) {
|
||||
OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, true);
|
||||
OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, false);
|
||||
OrientGraph orientGraph = factory.getTx();
|
||||
if(orientGraph.isClosed()) {
|
||||
factory = getSecurityContextFactory(context, permissionMode, true);
|
||||
|
@ -163,7 +160,7 @@ public abstract class SecurityContextMapper {
|
|||
|
||||
public static OrientGraphNoTx getSecurityContextGraphNoTx(
|
||||
UUID context, PermissionMode permissionMode) {
|
||||
OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, true);
|
||||
OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, false);
|
||||
OrientGraphNoTx orientGraphNoTx = factory.getNoTx();
|
||||
if(orientGraphNoTx.isClosed()) {
|
||||
factory = getSecurityContextFactory(context, permissionMode, true);
|
||||
|
@ -174,7 +171,7 @@ public abstract class SecurityContextMapper {
|
|||
|
||||
public static ODatabaseDocumentTx getSecurityContextDatabaseDocumentTx(
|
||||
UUID context, PermissionMode permissionMode) {
|
||||
OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, true);
|
||||
OrientGraphFactory factory = getSecurityContextFactory(context, permissionMode, false);
|
||||
ODatabaseDocumentTx databaseDocumentTx = factory.getDatabase();
|
||||
if(databaseDocumentTx.isClosed()) {
|
||||
factory = getSecurityContextFactory(context, permissionMode, true);
|
||||
|
|
Loading…
Reference in New Issue