Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #28 from barmintor/fcrepo-659
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Mar 21, 2015
2 parents adde1ae + 89ea3cf commit c7770f2
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 603 deletions.
2 changes: 1 addition & 1 deletion fcrepo-installer/src/main/assembly/fedora-installer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</directory>
<outputDirectory>/resources</outputDirectory>
<includes>
<include>DefaultDOManager.dbspec</include>
<include>*.dbspec</include>
</includes>
</fileSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import junit.framework.JUnit4TestAdapter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.util.Arrays;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.fcrepo.common.MalformedPIDException;
import org.fcrepo.common.PID;

import org.fcrepo.server.errors.ModuleInitializationException;
import org.fcrepo.server.storage.ConnectionPool;
import org.fcrepo.server.utilities.SQLUtility;

Expand Down Expand Up @@ -52,11 +50,28 @@ public class DBPIDGenerator
* generated PID as reported by the log files in that directory. This is to
* support automatic upgrade of this functionality from versions of Fedora
* prior to 1.2.
* @throws ModuleInitializationException
* @throws
*/
public DBPIDGenerator(ConnectionPool cPool, File oldPidGenDir)
throws IOException {
throws IOException, ModuleInitializationException {
m_connectionPool = cPool;
m_highestID = new HashMap<String, Integer>();
try {
String dbSpec =
"org/fcrepo/server/storage/resources/DBPIDGenerator.dbspec";
InputStream specIn =
this.getClass().getClassLoader()
.getResourceAsStream(dbSpec);
if (specIn == null) {
throw new IOException("Cannot find required resource: " +
dbSpec);
}
SQLUtility.createNonExistingTables(m_connectionPool, specIn);
} catch (Exception e) {
throw new ModuleInitializationException(
"Error while attempting to check for and create non-existing table(s): " +
e.getClass().getName() + ": " + e.getMessage(), getRole(), e);
}
// load the values from the database into the m_highestID hash
// pidGen: namespace highestID
Statement s = null;
Expand All @@ -67,13 +82,15 @@ public DBPIDGenerator(ConnectionPool cPool, File oldPidGenDir)
String query = "SELECT namespace, highestID FROM pidGen";
s = conn.createStatement();
results = s.executeQuery(query);
m_highestID = new HashMap<String, Integer>();
while (results.next()) {
m_highestID.put(results.getString("namespace"),
new Integer(results.getInt("highestID")));
}
} catch (SQLException sqle) {
logger.warn("Unable to read pidGen table; assuming it "
+ "will be created shortly");
} catch (SQLException e) {
throw new ModuleInitializationException(
"Error while attempting to load highest existing pids and namespaces: " +
e.getClass().getName() + ": " + e.getMessage(), getRole(), e);
} finally {
try {
if (results != null) {
Expand All @@ -96,6 +113,10 @@ public DBPIDGenerator(ConnectionPool cPool, File oldPidGenDir)
upgradeIfNeeded(oldPidGenDir);
}

public String getRole() {
return PIDGenerator.class.getName();
}

/**
* Read the highest value from the old pidGen directory if it exists, and
* ensure it is never used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.fcrepo.server.search;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand All @@ -15,6 +16,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.fcrepo.server.errors.ModuleInitializationException;
import org.fcrepo.server.errors.ObjectIntegrityException;
import org.fcrepo.server.errors.RepositoryConfigurationException;
import org.fcrepo.server.errors.ServerException;
Expand Down Expand Up @@ -92,11 +94,13 @@ public class FieldSearchSQLImpl
* what the user might request
* @param maxSecondsPerSession
* maximum number of seconds per session.
* @throws ModuleInitializationException
*/
public FieldSearchSQLImpl(ConnectionPool cPool,
RepositoryReader repoReader,
int maxResults,
int maxSecondsPerSession) {
int maxSecondsPerSession,
SQLUtility sqlUtility) throws ModuleInitializationException {
this(cPool, repoReader, maxResults, maxSecondsPerSession, true);
}

Expand All @@ -118,21 +122,42 @@ public FieldSearchSQLImpl(ConnectionPool cPool,
* whether DC field values should be examined and updated in the
* database. If false, queries will behave as if no values had been
* specified for the DC fields.
* @throws ModuleInitializationException
*/
public FieldSearchSQLImpl(ConnectionPool cPool,
RepositoryReader repoReader,
int maxResults,
int maxSecondsPerSession,
boolean indexDCFields) {
boolean indexDCFields) throws ModuleInitializationException {
logger.debug("Entering constructor");
m_cPool = cPool;
m_repoReader = repoReader;
m_maxResults = maxResults;
m_maxSecondsPerSession = maxSecondsPerSession;
m_indexDCFields = indexDCFields;
try {
String dbSpec =
"org/fcrepo/server/storage/resources/FieldSearchSQLImpl.dbspec";
InputStream specIn =
this.getClass().getClassLoader()
.getResourceAsStream(dbSpec);
if (specIn == null) {
throw new IOException("Cannot find required resource: " +
dbSpec);
}
SQLUtility.createNonExistingTables(m_cPool, specIn);
} catch (Exception e) {
throw new ModuleInitializationException(
"Error while attempting to check for and create non-existing table(s): " +
e.getClass().getName() + ": " + e.getMessage(), getRole(), e);
}
logger.debug("Exiting constructor");
}

public String getRole() {
return FieldSearch.class.getName();
}

public void update(DOReader reader) throws ServerException {
logger.debug("Entering update(DOReader)");
String pid = reader.GetObjectPID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,24 +401,9 @@ public void postInitModule() throws ModuleInitializationException {
throw new ModuleInitializationException("Couldn't get required "
+ "connection pool; wasn't found", getRole());
}
try {
String dbSpec =
"org/fcrepo/server/storage/resources/DefaultDOManager.dbspec";
InputStream specIn =
this.getClass().getClassLoader()
.getResourceAsStream(dbSpec);
if (specIn == null) {
throw new IOException("Cannot find required " + "resource: " +
dbSpec);
}
SQLUtility.createNonExistingTables(m_connectionPool, specIn);
} catch (Exception e) {
throw new ModuleInitializationException(
"Error while attempting to " +
"check for and create non-existing table(s): " +
e.getClass().getName() + ": " + e.getMessage(),
getRole(), e);
}
ensureTableSpec("org/fcrepo/server/storage/resources/DefaultDOManager.dbspec");
// the cModel cache relies on the lastMod date from doFields table
ensureTableSpec("org/fcrepo/server/storage/resources/FieldSearchSQLImpl.dbspec");

// get ref to lowlevelstorage module
m_permanentStore =
Expand Down Expand Up @@ -454,6 +439,25 @@ public String lookupDeploymentForCModel(String cModelPid, String sDefPid) {
cModelPid, sDefPid));
}

private void ensureTableSpec(String dbSpec) throws ModuleInitializationException {
try {
InputStream specIn =
this.getClass().getClassLoader()
.getResourceAsStream(dbSpec);
if (specIn == null) {
throw new IOException("Cannot find required " + "resource: " +
dbSpec);
}
SQLUtility.createNonExistingTables(m_connectionPool, specIn);
} catch (Exception e) {
throw new ModuleInitializationException(
"Error while attempting to " +
"check for and create non-existing table(s): " +
e.getClass().getName() + ": " + e.getMessage(),
getRole(), e);
}
}

private void initializeCModelDeploymentCache() {
// Initialize Map containing links from Content Models to the Service
// Deployments.
Expand Down Expand Up @@ -481,7 +485,7 @@ private void initializeCModelDeploymentCache() {
}

} catch (SQLException e) {
throw new RuntimeException("Error loading cModel deployment cach",
throw new RuntimeException("Error loading cModel deployment cache",
e);
} finally {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class DBPathRegistry

private final boolean backslashIsEscape;

public DBPathRegistry(Map<String, ?> configuration) {
public DBPathRegistry(Map<String, ?> configuration) throws LowlevelStorageException {
super(configuration);
connectionPool = (ConnectionPool) configuration.get("connectionPool");
backslashIsEscape =
Expand All @@ -62,6 +63,23 @@ public DBPathRegistry(Map<String, ?> configuration) {
selectByIdQuery = "SELECT path FROM " + this.registryName + " WHERE token=?";
deleteByIdQuery = "DELETE FROM " + this.registryName + " WHERE "
+ this.registryName + ".token=?";
try {
String dbSpec =
"org/fcrepo/server/storage/resources/DBPathRegistry.dbspec";
InputStream specIn =
this.getClass().getClassLoader()
.getResourceAsStream(dbSpec);
if (specIn == null) {
throw new IOException("Cannot find required resource: " +
dbSpec);
}
SQLUtility.createNonExistingTables(connectionPool, specIn);
} catch (Exception e) {
throw new LowlevelStorageException(
true,
"Error while attempting to check for and create non-existing table(s): " +
e.getClass().getName() + ": " + e.getMessage(), e);
}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<database>
<table name="pidGen">
<comment>For each namespace the DBPIDGenerator keeps track of,
the highestID is the highest known id ever used from that namespace.
The PID generation algorithm simply increments this value to get
the next id within the namespace.</comment>
<column name="namespace" type="varchar(255)" notNull="true" binary="true"/>
<column name="highestID" type="int(11)" notNull="true"/>
</table>
</database>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<database>
<table name="objectPaths" primaryKey="tokenDbID">
<column name="tokenDbID" type="int(11)" notNull="true" autoIncrement="true"/>
<column name="token" type="varchar(64)" notNull="true" default="" unique="true"/>
<column name="path" type="varchar(255)" notNull="true" default=""/>
</table>
<table name="datastreamPaths" primaryKey="tokenDbID">
<column name="tokenDbID" type="int(11)" notNull="true" autoIncrement="true"/>
<column name="token" type="varchar(199)" notNull="true" default="" unique="true"/>
<column name="path" type="varchar(255)" notNull="true" default=""/>
</table>
</database>
Loading

0 comments on commit c7770f2

Please sign in to comment.