@VisibleForTesting
void initializeUserCache() throws RepositoryException {
final String METHOD = "initializeUserCache";
Connection conn = null;
JdbcDatabase jdbcDatabase =
connectorSession.getConnector().getJdbcDatabase();
try {
conn = jdbcDatabase.getConnectionPool().getConnection();
// Notes user names don't have a simple defined max
// size. There are limits for each component (name, org
// unit, org). For now, we're going with "as big as a
// varchar can be".
jdbcDatabase.verifyTableExists(userTableName, new String[] {
"create table " + userTableName
+ " (userid long auto_increment primary key,"
+ " gsaname varchar(128), notesname varchar(254))"});
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified table: " + userTableName);
Util.executeStatements(conn, true, new String[] {
"create index if not exists idx_gsaname_" + userTableName
+ " on " + userTableName + "(gsaname)",
"create index if not exists idx_notesname_" + userTableName
+ " on " + userTableName + "(notesname)"});
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified index: idx_gsaname_" + userTableName + " and "
+ " idx_notesname_" + userTableName);
// Group names have a max size of 63, but we also create
// groups based on DN components, so make the groupname
// field larger than would otherwise be needed.
jdbcDatabase.verifyTableExists(groupTableName, new String[] {
"create table " + groupTableName
+ " (groupid long auto_increment primary key,"
+ " groupname varchar(254), pseudogroup boolean)"});
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified table: " + groupTableName);
Util.executeStatements(conn, true,
"create index if not exists idx_groupname_groups on "
+ groupTableName + "(groupname)");
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified index: idx_groupname_groups on " + groupTableName);
// Role names have a max size of 15.
jdbcDatabase.verifyTableExists(roleTableName, new String[] {
"create table " + roleTableName
+ " (roleid long auto_increment primary key,"
+ " rolename varchar(32), replicaid varchar(32))"});
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified table: " + roleTableName);
Util.executeStatements(conn, true,
"create index if not exists idx_rolename_roles on "
+ roleTableName + "(rolename)",
"create index if not exists idx_replicaid_roles on "
+ roleTableName + "(replicaid)");
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD, "Created/verified indexes: "
+ "idx_rolename_roles and idx_replicaid_roles on " + roleTableName);
jdbcDatabase.verifyTableExists(userGroupsTableName, new String[] {
"create table " + userGroupsTableName + " (userid long,"
+ " groupid long)"});
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified table: " + userGroupsTableName);
Util.executeStatements(conn, true,
"create index if not exists idx_userid_usergroups on "
+ userGroupsTableName + "(userid)",
"create index if not exists idx_groupid_usergroups on "
+ userGroupsTableName + "(groupid)");
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD, "Created/verified indexes: "
+ "idx_userid_usergroups and idx_groupid_usergroups on "
+ userGroupsTableName);
jdbcDatabase.verifyTableExists(userRolesTableName, new String[] {
"create table " + userRolesTableName + " (userid long, "
+ "roleid long)"});
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified table: " + userRolesTableName);
Util.executeStatements(conn, true,
"create index if not exists idx_userid_userroles on "
+ userRolesTableName + "(userid)",
"create index if not exists idx_roleid_userroles on "
+ userRolesTableName + "(roleid)");
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD, "Created/verified indexes: "
+ "idx_userid_userroles and idx_roleid_userroles on "
+ userRolesTableName);
jdbcDatabase.verifyTableExists(groupRolesTableName, new String[] {
"create table " + groupRolesTableName + " (groupid long,"
+ " roleid long)"});
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified table: " + groupRolesTableName);
Util.executeStatements(conn, true,
"create index if not exists idx_groupid_grouproles on "
+ groupRolesTableName + "(groupid)",
"create index if not exists idx_roleid_grouproles on "
+ groupRolesTableName + "(roleid)");
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD, "Created/verified indexes: "
+ "idx_groupid_grouproles and idx_roleid_grouproles on "
+ groupRolesTableName);
jdbcDatabase.verifyTableExists(groupChildrenTableName, new String[] {
"create table " + groupChildrenTableName + " (parentgroupid long,"
+ " childgroupid long)"});
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD,
"Created/verified table: " + groupChildrenTableName);
Util.executeStatements(conn, true,
"create index if not exists idx_parentgroupid_groupchildren on "
+ groupChildrenTableName + "(parentgroupid)",
"create index if not exists idx_childgroupid_groupchildren on "
+ groupChildrenTableName + "(childgroupid)");
LOGGER.logp(Level.INFO, CLASS_NAME, METHOD, "Created/verified indexes: "
+ "idx_parentgroupid_groupchildren and idx_childgroupid_groupchildren"
+ " on " + groupChildrenTableName);
} catch (Exception e) {
LOGGER.logp(Level.SEVERE, CLASS_NAME, METHOD,
"Failed to initialize user cache", e);
throw new RepositoryException("Failed to initialize user cache", e);
} finally {
if (conn != null) {
jdbcDatabase.getConnectionPool().releaseConnection(conn);
}
}
}