mirror of
https://github.com/ethauvin/rife2.git
synced 2025-07-12 00:53:41 -07:00
Wrap DatabaseSession and RememberSession table bootstrapping. (#4)
* wrap try/catch around bootstrapping the DatabaseSession and DatabaseRemember tables. * remove transaction from _installs
This commit is contained in:
parent
fbbd157d9a
commit
8c4d7057d3
3 changed files with 50 additions and 5 deletions
|
@ -13,7 +13,9 @@ import rife.database.Datasource;
|
||||||
import rife.database.DbPreparedStatement;
|
import rife.database.DbPreparedStatement;
|
||||||
import rife.database.DbPreparedStatementHandler;
|
import rife.database.DbPreparedStatementHandler;
|
||||||
import rife.database.DbQueryManager;
|
import rife.database.DbQueryManager;
|
||||||
|
import rife.database.DbTransactionUserWithoutResult;
|
||||||
import rife.database.exceptions.DatabaseException;
|
import rife.database.exceptions.DatabaseException;
|
||||||
|
import rife.database.exceptions.ExecutionErrorException;
|
||||||
import rife.database.queries.CreateTable;
|
import rife.database.queries.CreateTable;
|
||||||
import rife.database.queries.Delete;
|
import rife.database.queries.Delete;
|
||||||
import rife.database.queries.DropTable;
|
import rife.database.queries.DropTable;
|
||||||
|
@ -21,6 +23,8 @@ import rife.database.queries.Insert;
|
||||||
import rife.database.queries.Select;
|
import rife.database.queries.Select;
|
||||||
import rife.tools.StringEncryptor;
|
import rife.tools.StringEncryptor;
|
||||||
import rife.tools.UniqueIDGenerator;
|
import rife.tools.UniqueIDGenerator;
|
||||||
|
import rife.tools.InnerClassException;
|
||||||
|
import rife.tools.ExceptionUtils;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
@ -46,8 +50,17 @@ public abstract class DatabaseRemember extends DbQueryManager implements Remembe
|
||||||
throws RememberManagerException;
|
throws RememberManagerException;
|
||||||
|
|
||||||
protected boolean _install(CreateTable createRemember, String createRememberMomentIndex) {
|
protected boolean _install(CreateTable createRemember, String createRememberMomentIndex) {
|
||||||
executeUpdate(createRemember);
|
assert createRemember != null;
|
||||||
executeUpdate(createRememberMomentIndex);
|
assert createRememberMomentIndex != null;
|
||||||
|
try {
|
||||||
|
executeUpdate(createRemember);
|
||||||
|
executeUpdate(createRememberMomentIndex);
|
||||||
|
} catch (DatabaseException e) {
|
||||||
|
final String trace = ExceptionUtils.getExceptionStackTrace(e);
|
||||||
|
if (!trace.contains("already exists")) {
|
||||||
|
throw new InstallRememberUserErrorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2022 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||||
|
*/
|
||||||
|
package rife.authentication.remembermanagers.exceptions;
|
||||||
|
|
||||||
|
import rife.authentication.exceptions.RememberManagerException;
|
||||||
|
import rife.database.exceptions.DatabaseException;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
|
public class InstallRememberUserErrorException extends RememberManagerException {
|
||||||
|
@Serial private static final long serialVersionUID = 4507208218418987745L;
|
||||||
|
|
||||||
|
public InstallRememberUserErrorException() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InstallRememberUserErrorException(DatabaseException cause) {
|
||||||
|
super("Can't install the remember user database structure.", cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,8 +16,12 @@ import rife.database.DbPreparedStatement;
|
||||||
import rife.database.DbPreparedStatementHandler;
|
import rife.database.DbPreparedStatementHandler;
|
||||||
import rife.database.DbQueryManager;
|
import rife.database.DbQueryManager;
|
||||||
import rife.database.DbRowProcessor;
|
import rife.database.DbRowProcessor;
|
||||||
|
import rife.database.DbTransactionUserWithoutResult;
|
||||||
import rife.database.exceptions.DatabaseException;
|
import rife.database.exceptions.DatabaseException;
|
||||||
|
import rife.database.exceptions.ExecutionErrorException;
|
||||||
import rife.tools.UniqueIDGenerator;
|
import rife.tools.UniqueIDGenerator;
|
||||||
|
import rife.tools.ExceptionUtils;
|
||||||
|
import rife.tools.InnerClassException;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -58,9 +62,15 @@ public abstract class DatabaseSessions extends DbQueryManager implements Session
|
||||||
protected boolean _install(CreateTable createAuthentication, String createAuthenticationSessStartIndex) {
|
protected boolean _install(CreateTable createAuthentication, String createAuthenticationSessStartIndex) {
|
||||||
assert createAuthentication != null;
|
assert createAuthentication != null;
|
||||||
assert createAuthenticationSessStartIndex != null;
|
assert createAuthenticationSessStartIndex != null;
|
||||||
|
try {
|
||||||
executeUpdate(createAuthentication);
|
executeUpdate(createAuthentication);
|
||||||
executeUpdate(createAuthenticationSessStartIndex);
|
executeUpdate(createAuthenticationSessStartIndex);
|
||||||
|
} catch (DatabaseException e) {
|
||||||
|
final String trace = ExceptionUtils.getExceptionStackTrace(e);
|
||||||
|
if (!trace.contains("already exists")) {
|
||||||
|
throw new InstallSessionsErrorException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue