You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2012/09/11 14:10:32 UTC
svn commit: r1383372 - in
/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub:
index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/
revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/
store/file/s...
Author: suat
Date: Tue Sep 11 12:10:31 2012
New Revision: 1383372
URL: http://svn.apache.org/viewvc?rev=1383372&view=rev
Log:
STANBOL-730:
- After choosing service PIDs of Stores instead of their names as the name of revision tables, it is needed to put delimeters surrounding the table name. Considering this, I have adapted the SQL query strings in various classes.
- Name changes on the class existing names:
RevisionManager -> DerbyRevisionManager
StoreDBManager -> DerbyDBManager
Added:
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyDBManager.java
- copied, changed from r1377646, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyRevisionManager.java
- copied, changed from r1379367, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyDBManagerTest.java
- copied, changed from r1377646, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyRevisionManagerTest.java
- copied, changed from r1377646, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java
Removed:
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java
Modified:
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java?rev=1383372&r1=1383371&r2=1383372&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java Tue Sep 11 12:10:31 2012
@@ -873,7 +873,7 @@ public class LDPathSemanticIndex impleme
}
private long indexDocuments() throws StoreException, IndexException {
- ChangeSet<ContentItem> cs;
+ ChangeSet cs;
long revision = Long.MIN_VALUE;
boolean noChange = false;
do {
@@ -914,7 +914,7 @@ public class LDPathSemanticIndex impleme
return;
}
- ChangeSet<ContentItem> changeSet = null;
+ ChangeSet changeSet = null;
try {
changeSet = indexingSource.changes(epoch, revision, batchSize);
} catch (StoreException e) {
Copied: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyDBManager.java (from r1377646, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyDBManager.java?p2=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyDBManager.java&p1=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java&r1=1377646&r2=1383372&rev=1383372&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyDBManager.java Tue Sep 11 12:10:31 2012
@@ -47,12 +47,12 @@ import org.slf4j.LoggerFactory;
*
*/
@Component(immediate = true)
-@Service(value = StoreDBManager.class)
-public class StoreDBManager {
+@Service(value = DerbyDBManager.class)
+public class DerbyDBManager {
public static final String EPOCH_TABLE_NAME = "epochTable";
- private static Logger log = LoggerFactory.getLogger(StoreDBManager.class);
+ private static Logger log = LoggerFactory.getLogger(DerbyDBManager.class);
private static int MAX_ID_LENGTH = 1024;
@@ -70,7 +70,7 @@ public class StoreDBManager {
/**
* Creates an empty revision table with the given name. Different {@link Store} implementations are
* expected to call this method in their initializations with the value to be obtained by
- * {@link RevisionManager#getStoreID(Store)} method.
+ * {@link DerbyRevisionManager#getStoreID(Store)} method.
*
* @param tableName
* name of the table to be created
@@ -82,8 +82,9 @@ public class StoreDBManager {
try {
// try to create revision table
if (!existsTable(tableName)) {
- String createRevisionTable = "CREATE TABLE " + tableName + " (id VARCHAR(" + MAX_ID_LENGTH
- + ") NOT NULL PRIMARY KEY," + "revision BIGINT NOT NULL)";
+ String createRevisionTable = "CREATE TABLE \"" + tableName + "\" (id VARCHAR("
+ + MAX_ID_LENGTH + ") NOT NULL PRIMARY KEY,"
+ + "revision BIGINT NOT NULL)";
stmt = con.createStatement();
stmt.executeUpdate(createRevisionTable);
log.info("Revision table created for {}.", tableName);
@@ -170,12 +171,13 @@ public class StoreDBManager {
if (!exists) {
throw new IllegalArgumentException(String.format("There is no table having name: %s", tableName));
}
- String truncateTable = "TRUNCATE TABLE " + tableName;
+ String truncateTable = "TRUNCATE TABLE \"" + tableName + "\"";
Connection con = getConnection();
Statement stmt = null;
try {
stmt = con.createStatement();
stmt.execute(truncateTable);
+ log.debug("Table having name: {} has been truncated", tableName);
} catch (SQLException e) {
log.error("Failed to truncate table: {}", tableName, e);
throw new StoreException(String.format("Failed to truncate table: %s", tableName), e);
@@ -183,7 +185,6 @@ public class StoreDBManager {
closeStatement(stmt);
closeConnection(con);
}
- log.debug("Table having name: {} has been truncated", tableName);
}
/**
@@ -241,6 +242,7 @@ public class StoreDBManager {
Connection con = null;
try {
con = DriverManager.getConnection(DB_URL);
+ log.debug("New database connection has been prepared");
} catch (SQLException e) {
log.error("Failed to obtain Derby connection", e);
throw new StoreException("Failed to obtain Derby connection", e);
Copied: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyRevisionManager.java (from r1379367, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyRevisionManager.java?p2=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyRevisionManager.java&p1=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java&r1=1379367&r2=1383372&rev=1383372&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/DerbyRevisionManager.java Tue Sep 11 12:10:31 2012
@@ -21,6 +21,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -31,70 +32,126 @@ import org.apache.stanbol.commons.semant
import org.apache.stanbol.commons.semanticindex.store.ChangeSet;
import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
-import org.apache.stanbol.enhancer.servicesapi.ContentItem;
+import org.apache.stanbol.commons.semanticindex.store.revisionmanager.RevisionManager;
+import org.apache.stanbol.commons.semanticindex.store.revisionmanager.RevisionManagerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* <p>
- * This class aims to manage the epochs of several {@link Store} implementations and the revisions regarding
- * to the {@link ContentItem}s stored in {@link Store} instances. The revisions are kept in a single table in
- * the scope of Apache Derby database. The system time is set as the new revision of the {@link ContentItem}
- * when the {@link #updateRevision(Store, String)} method is called. Epochs of the Stores are managed in a
- * single table initialized by {@link StoreDBManager}.
+ * Apache Derby based implementation of {@link RevisionManager} interface. It does not depend on a specific
+ * generic type, so any {@link Store} instance can use it.
* </p>
* <p>
- * In the scope of this RevisionManager {@link Store}s are identified by according to their names which can be
- * obtained via the {@link Store#getName()} method.
+ * The revisions of items are kept in a single table in the scope of Apache Derby database. For each Store a
+ * separate table is created using the specified {@code storeID}. The system time is set as the new revision
+ * of the items when the {@link #updateRevision(Store, String)} method is called.
+ * </p>
+ * <p>
+ * Epochs of the Stores are managed in a single table initialized by {@link DerbyDBManager}. The epoch table
+ * contains a single record for each Store. When updating the epochs of the Stores, again the system time is
+ * used.
* </p>
*
* @author suat
*
*/
@Component(immediate = true)
-@Service(value = RevisionManager.class)
-public class RevisionManager {
- private static Logger log = LoggerFactory.getLogger(RevisionManager.class);
+@Service
+public class DerbyRevisionManager implements RevisionManager {
+ private static Logger log = LoggerFactory.getLogger(DerbyRevisionManager.class);
- private String SELECT_REVISION = "SELECT id,revision FROM %s content_item_revision WHERE id = ?";
+ private String SELECT_REVISION = "SELECT id,revision FROM \"%s\" content_item_revision WHERE id = ?";
- private String INSERT_REVISION = "INSERT INTO %s (id, revision) VALUES (?,?)";
+ private String INSERT_REVISION = "INSERT INTO \"%s\" (id, revision) VALUES (?,?)";
- private String UPDATE_REVISION = "UPDATE %s SET revision=? WHERE id=?";
+ private String UPDATE_REVISION = "UPDATE \"%s\" SET revision=? WHERE id=?";
- private String SELECT_CHANGES = "SELECT id, revision FROM %s WHERE revision > ? ORDER BY revision ASC";
+ private String SELECT_CHANGES = "SELECT id, revision FROM \"%s\" WHERE revision > ? ORDER BY revision ASC";
- private String SELECT_MORECHANGES = "SELECT id, revision FROM %s WHERE revision > ? AND revision <= ? ORDER BY revision ASC OFFSET ? ROWS";
+ private String SELECT_MORECHANGES = "SELECT id, revision FROM \"%s\" WHERE revision > ? AND revision <= ? ORDER BY revision ASC OFFSET ? ROWS";
- private String SELECT_EPOCH = "SELECT epoch FROM " + StoreDBManager.EPOCH_TABLE_NAME
+ private String SELECT_EPOCH = "SELECT epoch FROM " + DerbyDBManager.EPOCH_TABLE_NAME
+ " WHERE tableName = ?";
- private String INSERT_EPOCH = "INSERT INTO " + StoreDBManager.EPOCH_TABLE_NAME
+ private String INSERT_EPOCH = "INSERT INTO " + DerbyDBManager.EPOCH_TABLE_NAME
+ " (epoch, tableName) values (?, ?)";
- private String UPDATE_EPOCH = "UPDATE " + StoreDBManager.EPOCH_TABLE_NAME
+ private String UPDATE_EPOCH = "UPDATE " + DerbyDBManager.EPOCH_TABLE_NAME
+ " SET epoch = ? WHERE tableName = ?";
@Reference
- StoreDBManager dbManager;
+ DerbyDBManager dbManager;
/**
- * Updates revision of the {@link ContentItem} specified with the <code>contentItemID</code> parameter and
- * managed within the given {@code store}. The system time set as the new revision number by
- * {@link System#currentTimeMillis()}.
+ * Initializes the revision table for the {@link Store} specified by the given {@code storeID} if not
+ * already done and creates an entry in the "epochTable" for the same Store. This method is expected to be
+ * called while initializing the {@link Store} implementations. For instance OSGi based Store
+ * implementations can call this method within the @Activate method.
*
- * @param store
- * The {@link Store} instance in which the {@link ContentItem} specified by the
- * {@code contentItemID} is stored
- * @param contentItemID
- * ID of the {@link ContentItem} of which revision to be updated
- * @return the new revision
+ * @param storeID
+ * the identifier of the {@link Store}
+ * @throws RevisionManagerException
+ */
+ @Override
+ public void registerStore(String storeID) throws RevisionManagerException {
+ // initialize tables if not already
+ try {
+ dbManager.createRevisionTable(storeID);
+ log.debug("Revision table initialized for the Store: {}", storeID);
+ } catch (StoreException e) {
+ log.error("Failed to create revision table for the store: {}", storeID);
+ throw new RevisionManagerException(String.format(
+ "Failed to create revision table for the store: %s", storeID), e);
+ }
+
+ // add initial epoch for the store
+ updateEpoch(storeID, true);
+ log.debug("Epoch is initialized for the Store: {}", storeID);
+ }
+
+ /**
+ * Removes the revision table and the epoch entry regarding the given {@link Store}
+ *
+ * @param storeID
+ * the identifier of the {@link Store}
* @throws StoreException
*/
- public <Item> long updateRevision(Store<Item> store, String contentItemID) throws StoreException {
+ public void unregisterStore(String storeID) throws RevisionManagerException {
+ // get connection
+ Connection con = getConnection();
+ Statement stmt = null;
+ PreparedStatement ps = null;
+ String tableName = storeID;
+ try {
+ // first remove the the table
+ stmt = con.createStatement();
+ stmt.executeUpdate("DROP TABLE \"" + tableName + "\"");
+ log.debug("The revision table for the Store: {} has been dropped", storeID);
+
+ // delete the entry from epoch table
+ ps = con.prepareStatement("DELETE FROM " + DerbyDBManager.EPOCH_TABLE_NAME
+ + " WHERE tableName = ?");
+ ps.setString(1, tableName);
+ ps.executeUpdate();
+ log.debug("The epoch entry for the the Store: {} has been deleted", storeID);
+
+ } catch (SQLException e) {
+ log.error("Failed clear test resources for the table: {}", tableName);
+ throw new RevisionManagerException(String.format("Failed clear test resources for the table: %s",
+ tableName), e);
+ } finally {
+ dbManager.closeStatement(stmt);
+ dbManager.closeStatement(ps);
+ dbManager.closeConnection(con);
+ }
+ }
+
+ @Override
+ public long updateRevision(String storeID, String itemID) throws RevisionManagerException {
// get connection
- Connection con = dbManager.getConnection();
- String revisionTableName = getStoreID(store);
+ Connection con = getConnection();
+ String revisionTableName = storeID;
// check existence of record for the given content item id
PreparedStatement ps = null;
@@ -102,7 +159,7 @@ public class RevisionManager {
boolean recordExist = false;
try {
ps = con.prepareStatement(String.format(SELECT_REVISION, revisionTableName));
- ps.setString(1, contentItemID);
+ ps.setString(1, itemID);
rs = ps.executeQuery();
if (rs.next()) {
recordExist = true;
@@ -111,7 +168,7 @@ public class RevisionManager {
} catch (SQLException e) {
dbManager.closeConnection(con);
log.error("Failed to query revision of content item", e);
- throw new StoreException("Failed to query revision of content item", e);
+ throw new RevisionManagerException("Failed to query revision of content item", e);
} finally {
dbManager.closeResultSet(rs);
dbManager.closeStatement(ps);
@@ -121,18 +178,18 @@ public class RevisionManager {
try {
long newRevision = System.currentTimeMillis();
if (!recordExist) {
- log.debug("New revision: {} for the content item: {} of Store: {} will be added",
- new Object[] {newRevision, contentItemID, revisionTableName});
+ log.debug("New revision: {} for the item: {} of Store: {} will be added",
+ new Object[] {newRevision, itemID, revisionTableName});
ps = con.prepareStatement(String.format(INSERT_REVISION, revisionTableName));
- ps.setString(1, contentItemID);
+ ps.setString(1, itemID);
ps.setLong(2, newRevision);
} else {
- log.debug("New revision: {} for the content item: {} of Store: {} will be updated",
- new Object[] {newRevision, contentItemID, revisionTableName});
+ log.debug("New revision: {} for the item: {} of Store: {} will be updated",
+ new Object[] {newRevision, itemID, revisionTableName});
ps = con.prepareStatement(String.format(UPDATE_REVISION, revisionTableName));
ps.setLong(1, newRevision);
- ps.setString(2, contentItemID);
+ ps.setString(2, itemID);
}
int updatedRecordNum = ps.executeUpdate();
// exactly one record should be affected
@@ -142,7 +199,7 @@ public class RevisionManager {
return newRevision;
} catch (SQLException e) {
log.error("Failed to update revision", e);
- throw new StoreException("Failed to update revision", e);
+ throw new RevisionManagerException("Failed to update revision", e);
} finally {
dbManager.closeStatement(ps);
dbManager.closeConnection(con);
@@ -150,30 +207,31 @@ public class RevisionManager {
}
/**
- * Returns the updates after the given revision number. If the total size of revisions after the given
- * revision number fit in <code>batchSize</code>, all of the changes for the last revision are also
- * included in the results. This is because we do not want to include a subset of the changes regarding to
- * a particular revision in the result.
+ * Returns the changes larger than the given revision number. If the total size of revisions coming after
+ * the given revision number <b>DOES NOT</b> fit in <code>batchSize</code>, <b>all of the changes</b> for
+ * the last revision are also included in the results. This is because we do not want to include a subset
+ * of the changes regarding to a particular revision in the result.
*
* @param store
* {@link Store} instance for which the changes are requested
* @param revision
* Starting revision of the to be returned in the results
* @param batchSize
- * Maximum number of changes to be returned. However to return all changes regarding to
- * particular revisions, the results might not have as much items as specified with this
- * number. For instance, if there are 10 changes regarding a requested particular revision and
+ * Maximum number of changes to be returned. Please note that while returning all changes
+ * regarding to particular revisions, the changes might be more than the number specified with
+ * this parameter. For instance, if there are 10 changes regarding a particular revision and
* this parameter is specified as 5, the results will include 10 changes.
* @return a {@link ChangeSet} including the changes in the specified Store.
* @throws StoreException
*/
- public <Item> ChangeSet<Item> getChanges(Store<Item> store, long revision, int batchSize) throws StoreException {
+ @Override
+ public ChangeSet getChanges(String storeID, long revision, int batchSize) throws RevisionManagerException {
+ // get connection
+ Connection con = getConnection();
+
Set<String> changedUris = new LinkedHashSet<String>();
long to, from;
-
- // get connection
- Connection con = dbManager.getConnection();
- String revisionTableName = getStoreID(store);
+ String revisionTableName = storeID;
batchSize = batchSize == Integer.MAX_VALUE ? batchSize - 1 : batchSize;
// check existence of record for the given content item id
@@ -191,14 +249,15 @@ public class RevisionManager {
ps.setMaxRows(batchSize + 1);
rs = ps.executeQuery();
- // if there is no row, return an empty ChangeSet
if (!rs.first()) {
- return new ChangeSetImpl<Item>(store, store.getEpoch(), Long.MIN_VALUE, Long.MAX_VALUE,
- changedUris);
+ log.debug("There is no changes in store: {}, after revision: {}", storeID, revision);
+ return new ChangeSetImpl(Long.MIN_VALUE, Long.MIN_VALUE, Long.MIN_VALUE,
+ new ArrayList<String>());
}
// if the number of changes >= batchsize + 1
if (rs.absolute(batchSize + 1)) {
+ log.debug("There are changes after given revision more than the given batch size");
lastRowRevision = rs.getLong(2);
rs.previous();
long nextToLastRowRevision = rs.getLong(2);
@@ -206,6 +265,7 @@ public class RevisionManager {
// if we are in the middle of a revision, set the moreChanges flag to add all changes in
// that revision to changedUris
if (lastRowRevision == nextToLastRowRevision) {
+ log.debug("The changes for the revision: {} exceeds the batch size");
moreChanges = true;
}
while (rs.next()) {
@@ -216,6 +276,7 @@ public class RevisionManager {
}
rs.previous();
} else {
+ log.debug("There are changes after given revision less than or equal to the given batch size");
rs.beforeFirst();
while (rs.next()) {
changedUris.add(rs.getString(1));
@@ -226,10 +287,12 @@ public class RevisionManager {
to = rs.getLong(2);
rs.first();
from = rs.getLong(2);
+ log.debug("Changes have been fetched for the initial batch size");
} catch (SQLException e) {
- log.error("Failed to get changes", e);
- throw new StoreException("Failed to get changes", e);
+ log.error("Failed to get changes for the Store: {}", storeID, e);
+ throw new RevisionManagerException(String.format("Failed to get changes for the Store: %s",
+ storeID), e);
} finally {
dbManager.closeResultSet(rs);
dbManager.closeStatement(ps);
@@ -246,43 +309,47 @@ public class RevisionManager {
while (rs.next()) {
changedUris.add(rs.getString(1));
}
+ log.debug("Changes exceeding the batch size have been fetched");
} catch (SQLException e) {
log.error("Failed to get changes", e);
- throw new StoreException("Failed to get changes", e);
+ throw new RevisionManagerException("Failed to get changes", e);
} finally {
dbManager.closeResultSet(rs);
dbManager.closeStatement(ps);
}
}
- return new ChangeSetImpl<Item>(store, store.getEpoch(), from, to, changedUris);
+
+ long epoch = getEpoch(storeID);
+ return new ChangeSetImpl(epoch, from, to, changedUris);
} finally {
dbManager.closeConnection(con);
}
}
- public <Item> long getEpoch(Store<Item> store) throws StoreException {
+ @Override
+ public long getEpoch(String storeID) throws RevisionManagerException {
// get connection
- Connection con = dbManager.getConnection();
-
+ Connection con = getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
long epoch;
try {
ps = con.prepareStatement(SELECT_EPOCH);
- ps.setString(1, getStoreID(store));
+ ps.setString(1, storeID);
rs = ps.executeQuery();
if (rs.next()) {
epoch = rs.getLong(1);
} else {
- log.error(String.format("There is not an epoch record for the Store: %s", store.getName()));
- throw new StoreException(String.format("There is not an epoch record for the Store: %s",
- store.getName()));
+ log.error(String.format("There is not an epoch record for the Store: %s", storeID));
+ throw new RevisionManagerException(String.format(
+ "There is not an epoch record for the Store: %s", storeID));
}
+ log.debug("The epoch: {} for the Store: {} has been fetched", epoch, storeID);
} catch (SQLException e) {
log.error("Failed to execute query", e);
- throw new StoreException("Failed to execute query", e);
+ throw new RevisionManagerException("Failed to execute query", e);
} finally {
dbManager.closeResultSet(rs);
dbManager.closeStatement(ps);
@@ -298,15 +365,14 @@ public class RevisionManager {
* Store instance of which epoch will be updated.
* @throws StoreException
*/
- public <Item> void updateEpoch(Store<Item> store) throws StoreException {
- updateEpoch(store, false);
+ @Override
+ public long updateEpoch(String storeID) throws RevisionManagerException {
+ return updateEpoch(storeID, false);
}
- private <Item> void updateEpoch(Store<Item> store, boolean insert) throws StoreException {
- String storeID = getStoreID(store);
-
+ private long updateEpoch(String storeID, boolean insert) throws RevisionManagerException {
// get connection
- Connection con = dbManager.getConnection();
+ Connection con = getConnection();
PreparedStatement ps = null;
// update the table
@@ -314,7 +380,13 @@ public class RevisionManager {
long newEpoch = System.currentTimeMillis();
if (!insert) {
// truncate the revision table
- dbManager.truncateTable(storeID);
+ try {
+ dbManager.truncateTable(storeID);
+ } catch (StoreException e) {
+ log.error("Failed to truncate table while updating the epoch for the Store: {}", storeID);
+ throw new RevisionManagerException(String.format(
+ "Failed to truncate table while updating the epoch for the Store: %s", storeID), e);
+ }
log.debug("New epoch: {} for the Store: {} will be updated", newEpoch, storeID);
ps = con.prepareStatement(UPDATE_EPOCH);
@@ -328,11 +400,12 @@ public class RevisionManager {
rs = ps.executeQuery();
if (rs.next()) {
recordExist = true;
+ newEpoch = rs.getLong("epoch");
}
} catch (SQLException e) {
log.error("Failed to query revision of content item", e);
- throw new StoreException("Failed to query revision of content item", e);
+ throw new RevisionManagerException("Failed to query revision of content item", e);
} finally {
dbManager.closeResultSet(rs);
dbManager.closeStatement(ps);
@@ -344,74 +417,37 @@ public class RevisionManager {
} else {
// if there already exists an entry in the "epochTable"
// for the given store, return from the method
- return;
+ return newEpoch;
}
}
ps.setLong(1, newEpoch);
ps.setString(2, storeID);
int updatedRecordNum = ps.executeUpdate();
+ log.debug("Epoch update/insertion has been done");
+
// exactly one record should be affected
if (updatedRecordNum != 1) {
log.warn("Unexpected number of updated records: {}, should be 1", updatedRecordNum);
}
+ return newEpoch;
} catch (SQLException e) {
log.error("Failed to update epoch for Store identified as: {}", storeID, e);
- throw new StoreException(String.format("Failed to update epoch for identified as: %s", storeID),
- e);
+ throw new RevisionManagerException(String.format("Failed to update epoch for identified as: %s",
+ storeID), e);
} finally {
dbManager.closeStatement(ps);
dbManager.closeConnection(con);
}
}
- /**
- * Initializes the revision table for the given {@link Store} if not already done and creates an entry in
- * the "epochTable" for the given Store. This method is expected to be called while initializing the
- * {@link Store} implementations. For instance OSGi based Store implementations can call this method
- * within the @Activate method.
- *
- * @param store
- * Store instance of which revision tables are initialized
- * @throws StoreException
- */
- public <Item> void initializeRevisionTables(Store<Item> store) throws StoreException {
- // initialize tables if not already
- dbManager.createRevisionTable(getStoreID(store));
-
- // add initial epoch for the store
- updateEpoch(store, true);
- }
-
- /**
- * Clear the resources including the revision table and the epoch entry regarding the given {@link Store}
- *
- * @param store
- * Store instance of which resources will be cleared
- * @throws StoreException
- */
- public <Item> void clearRevisionTables(Store<Item> store) throws StoreException {
- Connection con = null;
- Statement stmt = null;
- PreparedStatement ps = null;
- String tableName = getStoreID(store);
+ private Connection getConnection() throws RevisionManagerException {
+ Connection con;
try {
con = dbManager.getConnection();
- // first remove the the table
- stmt = con.createStatement();
- stmt.executeUpdate("DROP TABLE " + tableName);
-
- // delete the entry from epoch table
- ps = con.prepareStatement("DELETE FROM " + StoreDBManager.EPOCH_TABLE_NAME
- + " WHERE tableName = ?");
- ps.setString(1, tableName);
- ps.executeUpdate();
-
- } catch (SQLException e) {
- log.error("Failed clear test resources for the table: {}", tableName);
- } finally {
- dbManager.closeStatement(stmt);
- dbManager.closeStatement(ps);
- dbManager.closeConnection(con);
+ return con;
+ } catch (StoreException e) {
+ log.error("Failed to obtain the database connection", e);
+ throw new RevisionManagerException("Failed to obtain the database connection", e);
}
}
@@ -423,7 +459,7 @@ public class RevisionManager {
* @param store
* @return
*/
- public <Item> String getStoreID(Store<Item> store) {
- return store.getName();
- }
+ // public <Item> String getStoreID(Store<Item> store) {
+ // return store.getName();
+ // }
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java?rev=1383372&r1=1383371&r2=1383372&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java Tue Sep 11 12:10:31 2012
@@ -61,8 +61,9 @@ import org.apache.stanbol.commons.semant
import org.apache.stanbol.commons.semanticindex.store.EpochException;
import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
-import org.apache.stanbol.contenthub.revisionmanager.RevisionManager;
-import org.apache.stanbol.contenthub.revisionmanager.StoreDBManager;
+import org.apache.stanbol.commons.semanticindex.store.revisionmanager.RevisionManager;
+import org.apache.stanbol.contenthub.revisionmanager.DerbyRevisionManager;
+import org.apache.stanbol.contenthub.revisionmanager.DerbyDBManager;
import org.apache.stanbol.contenthub.store.file.serializer.ContentPartDeserializer;
import org.apache.stanbol.contenthub.store.file.serializer.ContentPartSerializer;
import org.apache.stanbol.enhancer.servicesapi.Blob;
@@ -91,9 +92,9 @@ import org.slf4j.LoggerFactory;
* suitable with the types of the parts.
* </p>
* <p>
- * Revisions of {@link ContentItem}s submitted to this store is managed through the {@link RevisionManager}.
- * Once a document added, updated or deleted the revision of the {@link ContentItem} is set as
- * {@link System#currentTimeMillis()}.
+ * Revisions of {@link ContentItem}s submitted to this store is managed through the
+ * {@link DerbyRevisionManager}. Once a document added, updated or deleted the revision of the
+ * {@link ContentItem} is set as {@link System#currentTimeMillis()}.
* </p>
* <p>
* To be able to populate the HTML interface, this implementation also provides additional metadata regarding
@@ -152,7 +153,7 @@ public class FileStore implements Store<
+ FIELD_TITLE + " VARCHAR(" + MAX_ID_LENGTH
+ "))";
- private static final String SELECT_RECENTLY_ENHANCED_ITEMS = "SELECT t1.id, mimeType, enhancementCount, title FROM %s t1, "
+ private static final String SELECT_RECENTLY_ENHANCED_ITEMS = "SELECT t1.id, mimeType, enhancementCount, title FROM \"%s\" t1, "
+ RECENTLY_ENHANCED_TABLE_NAME
+ " t2 WHERE"
+ " t1.id=t2."
@@ -190,7 +191,7 @@ public class FileStore implements Store<
private RevisionManager revisionManager;
@Reference
- private StoreDBManager dbManager;
+ private DerbyDBManager dbManager;
@Reference
private ContentPartSerializer contentPartSerializer;
@@ -201,22 +202,9 @@ public class FileStore implements Store<
@Reference
private EnhancementJobManager jobManager;
- Map<String,Object> storeProperties;
+ private Map<String,Object> storeProperties;
- public FileStore() {
-
- }
-
- /**
- * Public constructor which is intended to be used from the tests. This component is an OSGi based
- * component, so this constructor MUST NOT be used to obtain a {@link FileStore} instance.
- *
- * @param name
- */
- public FileStore(String name, RevisionManager revisionManager) {
- this.name = name;
- this.revisionManager = revisionManager;
- }
+ private String pid;
@Activate
protected void activate(ComponentContext componentContext) throws StoreException {
@@ -235,14 +223,16 @@ public class FileStore implements Store<
}
// init the store properties
+ pid = (String) componentContext.getProperties().get(Constants.SERVICE_PID);
Map<String,Object> properties = new HashMap<String,Object>();
properties.put(PROPERTY_NAME, getName());
properties.put(PROPERTY_DESCRIPTION, getDescription());
properties.put(PROPERTY_ITEM_TYPE, getItemType());
+ properties.put(Constants.SERVICE_PID, pid);
storeProperties = Collections.unmodifiableMap(properties);
// create file store revision and recentlyenhanced tables
- revisionManager.initializeRevisionTables(this);
+ revisionManager.registerStore(pid);
createRecentlyEnhancedTable();
}
@@ -271,7 +261,7 @@ public class FileStore implements Store<
@Override
public long getEpoch() throws StoreException {
- return revisionManager.getEpoch(this);
+ return revisionManager.getEpoch(pid);
}
@Override
@@ -314,7 +304,7 @@ public class FileStore implements Store<
@Override
public void removeAll() throws StoreException {
// get changes to obtain identifier of the all changed ContentItems
- ChangeSet<ContentItem> changes = changes(getEpoch(), Long.MIN_VALUE, Integer.MAX_VALUE);
+ ChangeSet changes = changes(getEpoch(), Long.MIN_VALUE, Integer.MAX_VALUE);
List<ContentItem> removed = new ArrayList<ContentItem>();
Iterator<String> idIterator = changes.iterator();
while (idIterator.hasNext()) {
@@ -325,12 +315,12 @@ public class FileStore implements Store<
}
}
// update the epoch of this Store. It will also clear the revision table
- revisionManager.updateEpoch(this);
+ revisionManager.updateEpoch(pid);
}
private void updateTablesForDelete(String id) throws StoreException {
// update revision
- revisionManager.updateRevision(this, id);
+ revisionManager.updateRevision(pid, id);
// update recently_enhanced table
removeFromRecentlyEnhancedTable(id);
}
@@ -445,7 +435,7 @@ public class FileStore implements Store<
// ignore the exception
}
try {
- revisionManager.updateRevision(this, htmlMetadata.getString(FIELD_ID));
+ revisionManager.updateRevision(pid, htmlMetadata.getString(FIELD_ID));
updateRecentlyEnhancedItem(htmlMetadata.getString(FIELD_ID), title,
htmlMetadata.getString(FIELD_MIME_TYPE), htmlMetadata.getLong(FIELD_ENHANCEMENT_COUNT));
} catch (JSONException e) {
@@ -763,12 +753,11 @@ public class FileStore implements Store<
}
@Override
- public ChangeSet<ContentItem> changes(long epoch, long revision, int batchSize) throws StoreException {
+ public ChangeSet changes(long epoch, long revision, int batchSize) throws StoreException {
if (getEpoch() != epoch) {
throw new EpochException(this, getEpoch(), epoch);
}
- ChangeSetImpl<ContentItem> changesSet = (ChangeSetImpl<ContentItem>) revisionManager.getChanges(this,
- revision, batchSize);
+ ChangeSetImpl changesSet = (ChangeSetImpl) revisionManager.getChanges(pid, revision, batchSize);
return changesSet;
}
@@ -854,8 +843,7 @@ public class FileStore implements Store<
ResultSet rs = null;
List<JSONObject> recentlyEnhancedList = new ArrayList<JSONObject>();
try {
- ps = con.prepareStatement(String.format(SELECT_RECENTLY_ENHANCED_ITEMS,
- revisionManager.getStoreID(this)));
+ ps = con.prepareStatement(String.format(SELECT_RECENTLY_ENHANCED_ITEMS, pid));
ps.setMaxRows(limit);
ps.setInt(1, offset);
rs = ps.executeQuery();
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java?rev=1383372&r1=1383371&r2=1383372&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java Tue Sep 11 12:10:31 2012
@@ -343,6 +343,8 @@ public class LDPathSemanticIndexTest {
try {
SemanticIndex<ContentItem> semanticIndex = getLDPathSemanticIndex(name);
+ // TODO instead of creating a new ContentItem and enhancing and use an already existing
+ // ContentItem
ContentItem ci = contentItemFactory.createContentItem(new StringSource(
"Michael Jackson is a very famous person, and he was born in Indiana."));
jobManager.enhanceContent(ci);
Copied: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyDBManagerTest.java (from r1377646, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyDBManagerTest.java?p2=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyDBManagerTest.java&p1=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java&r1=1377646&r2=1383372&rev=1383372&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyDBManagerTest.java Tue Sep 11 12:10:31 2012
@@ -28,15 +28,15 @@ import java.sql.Statement;
import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
import org.apache.sling.junit.annotations.TestReference;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
-import org.apache.stanbol.contenthub.revisionmanager.StoreDBManager;
+import org.apache.stanbol.contenthub.revisionmanager.DerbyDBManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
@RunWith(SlingAnnotationsTestRunner.class)
-public class StoreDBManagerTest {
+public class DerbyDBManagerTest {
@TestReference
- private StoreDBManager dbManager;
+ private DerbyDBManager dbManager;
@TestReference
private BundleContext bundleContext;
@@ -60,8 +60,8 @@ public class StoreDBManagerTest {
@Test
public void testEpochTable() throws StoreException {
- assertTrue(StoreDBManager.EPOCH_TABLE_NAME + " has not been created",
- dbManager.existsTable(StoreDBManager.EPOCH_TABLE_NAME));
+ assertTrue(DerbyDBManager.EPOCH_TABLE_NAME + " has not been created",
+ dbManager.existsTable(DerbyDBManager.EPOCH_TABLE_NAME));
}
@Test
@@ -75,7 +75,7 @@ public class StoreDBManagerTest {
try {
// first remove the the table
stmt = con.createStatement();
- stmt.executeUpdate("DROP TABLE " + tableName);
+ stmt.executeUpdate("DROP TABLE \"" + tableName + "\"");
} finally {
dbManager.closeStatement(stmt);
@@ -94,7 +94,7 @@ public class StoreDBManagerTest {
ResultSet rs = null;
try {
// put some value into it
- String insertQuery = "INSERT INTO " + tableName + "(id, revision) VALUES(?,?)";
+ String insertQuery = "INSERT INTO \"" + tableName + "\" (id, revision) VALUES(?,?)";
long initialRevision = System.currentTimeMillis();
con = dbManager.getConnection();
for (int i = 0; i < 5; i++) {
@@ -110,7 +110,7 @@ public class StoreDBManagerTest {
dbManager.truncateTable(tableName);
// check the values
- ps = con.prepareStatement("SELECT * FROM " + tableName);
+ ps = con.prepareStatement("SELECT * FROM \"" + tableName + "\"");
rs = ps.executeQuery();
boolean recordExists = false;
@@ -127,7 +127,7 @@ public class StoreDBManagerTest {
try {
// first remove the the table
stmt = con.createStatement();
- stmt.executeUpdate("DROP TABLE " + tableName);
+ stmt.executeUpdate("DROP TABLE \"" + tableName + "\"");
} finally {
dbManager.closeStatement(stmt);
Copied: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyRevisionManagerTest.java (from r1377646, incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java)
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyRevisionManagerTest.java?p2=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyRevisionManagerTest.java&p1=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java&r1=1377646&r2=1383372&rev=1383372&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/DerbyRevisionManagerTest.java Tue Sep 11 12:10:31 2012
@@ -30,9 +30,8 @@ import org.apache.sling.junit.annotation
import org.apache.sling.junit.annotations.TestReference;
import org.apache.stanbol.commons.semanticindex.store.ChangeSet;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
-import org.apache.stanbol.contenthub.revisionmanager.RevisionManager;
-import org.apache.stanbol.contenthub.revisionmanager.StoreDBManager;
-import org.apache.stanbol.contenthub.store.file.FileStore;
+import org.apache.stanbol.commons.semanticindex.store.revisionmanager.RevisionManager;
+import org.apache.stanbol.contenthub.revisionmanager.DerbyDBManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
@@ -40,14 +39,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RunWith(SlingAnnotationsTestRunner.class)
-public class RevisionManagerTest {
- private static Logger log = LoggerFactory.getLogger(RevisionManagerTest.class);
+public class DerbyRevisionManagerTest {
+ private static Logger log = LoggerFactory.getLogger(DerbyRevisionManagerTest.class);
@TestReference
private RevisionManager revisionManager;
@TestReference
- private StoreDBManager dbManager;
+ private DerbyDBManager dbManager;
@TestReference
private BundleContext bundleContext;
@@ -69,7 +68,7 @@ public class RevisionManagerTest {
@Test
public void updateRevisionTest() throws StoreException, SQLException {
- FileStore fileStore = new FileStore("updateRevisionTestStore", revisionManager);
+ String storeID = "updateRevisionTestStore";
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
@@ -80,10 +79,9 @@ public class RevisionManagerTest {
long revisionNumber = Long.MAX_VALUE;
String query;
try {
- revisionManager.initializeRevisionTables(fileStore);
- newRevision = revisionManager.updateRevision(fileStore, contentItemID);
- query = String.format("SELECT id, revision FROM %s WHERE id = ?",
- revisionManager.getStoreID(fileStore));
+ revisionManager.registerStore(storeID);
+ newRevision = revisionManager.updateRevision(storeID, contentItemID);
+ query = String.format("SELECT id, revision FROM \"%s\" WHERE id = ?", storeID);
// check the update
con = dbManager.getConnection();
@@ -101,23 +99,22 @@ public class RevisionManagerTest {
} finally {
dbManager.closeResultSet(rs);
dbManager.closeStatement(ps);
- clearDummyStoreResources(fileStore, con);
+ clearDummyStoreResources(storeID, con);
}
}
@Test
public void iterativeChangesTest() throws StoreException, InterruptedException, SQLException {
- FileStore fileStore = new FileStore("iterativeChangesTestStore", revisionManager);
+ String storeID = "iterativeChangesTestStore";
Connection con = null;
String contentItemID = "contenthub_test_content_item_id";
PreparedStatement ps = null;
try {
con = dbManager.getConnection();
- revisionManager.initializeRevisionTables(fileStore);
+ revisionManager.registerStore(storeID);
// do the update
- String query = "INSERT INTO " + revisionManager.getStoreID(fileStore)
- + " (id, revision) VALUES (?,?)";
+ String query = "INSERT INTO \"" + storeID + "\" (id, revision) VALUES (?,?)";
long startRevision = System.currentTimeMillis();
long revision = System.currentTimeMillis();
for (int i = 0; i < 5; i++) {
@@ -130,7 +127,7 @@ public class RevisionManagerTest {
}
// check changes
- ChangeSet<?> changeSet = revisionManager.getChanges(fileStore, startRevision, 3);
+ ChangeSet changeSet = revisionManager.getChanges(storeID, startRevision, 3);
Iterator<String> changedItems = changeSet.iterator();
int itemCount = 0;
while (changedItems.hasNext()) {
@@ -153,7 +150,7 @@ public class RevisionManagerTest {
assertTrue("Changes does not include correct toRevision value",
(changeSet.toRevision() == revision - 2));
- changeSet = revisionManager.getChanges(fileStore, revision - 2, 3);
+ changeSet = revisionManager.getChanges(storeID, revision - 2, 3);
itemCount = 0;
changedItems = changeSet.iterator();
while (changedItems.hasNext()) {
@@ -178,22 +175,21 @@ public class RevisionManagerTest {
(changeSet.toRevision() == revision));
} finally {
dbManager.closeStatement(ps);
- clearDummyStoreResources(fileStore, con);
+ clearDummyStoreResources(storeID, con);
}
}
@Test
public void batchSizeDoesNotFitToRevisionTest() throws StoreException, SQLException {
- FileStore fileStore = new FileStore("batchSizeDoesNotFitToRevisionTestStore", revisionManager);
+ String storeID = "batchSizeDoesNotFitToRevisionTestStore";
Connection con = null;
String contentItemID = "contenthub_test_content_item_id";
PreparedStatement ps = null;
try {
- revisionManager.initializeRevisionTables(fileStore);
+ revisionManager.registerStore(storeID);
con = dbManager.getConnection();
// do the update
- String query = "INSERT INTO " + revisionManager.getStoreID(fileStore)
- + " (id, revision) VALUES (?,?)";
+ String query = "INSERT INTO \"" + storeID + "\" (id, revision) VALUES (?,?)";
long revision = System.currentTimeMillis();
for (int i = 0; i < 2; i++) {
ps = con.prepareStatement(query);
@@ -204,7 +200,7 @@ public class RevisionManagerTest {
}
// get changes
- ChangeSet<?> changeSet = revisionManager.getChanges(fileStore, revision, 1);
+ ChangeSet changeSet = revisionManager.getChanges(storeID, revision, 1);
int itemCount = 0;
Iterator<String> changedItems = changeSet.iterator();
while (changedItems.hasNext()) {
@@ -224,39 +220,32 @@ public class RevisionManagerTest {
}
} finally {
dbManager.closeStatement(ps);
- clearDummyStoreResources(fileStore, con);
+ clearDummyStoreResources(storeID, con);
}
}
@Test
public void emptyChangesTest() throws StoreException {
- FileStore fileStore = new FileStore("emptyChangesTestStore", revisionManager);
+ String storeID = "emptyChangesTestStore";
try {
- revisionManager.initializeRevisionTables(fileStore);
+ revisionManager.registerStore(storeID);
long revision = System.currentTimeMillis();
- ChangeSet<?> changeSet = revisionManager.getChanges(fileStore, revision, 1);
- assertTrue("There must be no changes", !changeSet.iterator().hasNext());
+ ChangeSet changeSet = revisionManager.getChanges(storeID, revision, 1);
+ assertTrue("There must be no changes", changeSet.iterator().hasNext() == false);
} finally {
- clearDummyStoreResources(fileStore, dbManager.getConnection());
+ clearDummyStoreResources(storeID, dbManager.getConnection());
}
}
@Test
- public void getStoreIDTest() {
- FileStore fileStore = new FileStore("getStoreIDTestStore", null);
- assertTrue("Store ID must be same with the name of the Store", revisionManager.getStoreID(fileStore)
- .equals(fileStore.getName()));
- }
-
- @Test
public void initializeRevisionTablesTest() throws StoreException, SQLException {
- FileStore fileStore = new FileStore("revisionManagerTestStore", revisionManager);
+ String storeID = "revisionManagerTestStore";
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
- String tableName = revisionManager.getStoreID(fileStore);
+ String tableName = storeID;
try {
- revisionManager.initializeRevisionTables(fileStore);
+ revisionManager.registerStore(storeID);
// check table
assertTrue(String.format("There is no table having name: %s", tableName),
dbManager.existsTable(tableName));
@@ -264,7 +253,7 @@ public class RevisionManagerTest {
// check epoch table entry
con = dbManager.getConnection();
boolean recordExists = false;
- ps = con.prepareStatement("SELECT epoch FROM " + StoreDBManager.EPOCH_TABLE_NAME
+ ps = con.prepareStatement("SELECT epoch FROM " + DerbyDBManager.EPOCH_TABLE_NAME
+ " WHERE tableName = ?");
ps.setString(1, tableName);
rs = ps.executeQuery();
@@ -277,21 +266,21 @@ public class RevisionManagerTest {
} finally {
dbManager.closeResultSet(rs);
dbManager.closeStatement(ps);
- clearDummyStoreResources(fileStore, con);
+ clearDummyStoreResources(storeID, con);
}
}
- private void clearDummyStoreResources(FileStore store, Connection con) {
+ private void clearDummyStoreResources(String storeID, Connection con) {
Statement stmt = null;
PreparedStatement ps = null;
- String tableName = revisionManager.getStoreID(store);
+ String tableName = storeID;
try {
// first remove the the table
stmt = con.createStatement();
- stmt.executeUpdate("DROP TABLE " + tableName);
+ stmt.executeUpdate("DROP TABLE \"" + tableName + "\"");
// delete the entry from epoch table
- ps = con.prepareStatement("DELETE FROM " + StoreDBManager.EPOCH_TABLE_NAME
+ ps = con.prepareStatement("DELETE FROM " + DerbyDBManager.EPOCH_TABLE_NAME
+ " WHERE tableName = ?");
ps.setString(1, tableName);
ps.executeUpdate();
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java?rev=1383372&r1=1383371&r2=1383372&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java Tue Sep 11 12:10:31 2012
@@ -47,8 +47,7 @@ import org.apache.stanbol.commons.semant
import org.apache.stanbol.commons.semanticindex.index.IndexManagementException;
import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
-import org.apache.stanbol.contenthub.revisionmanager.RevisionManager;
-import org.apache.stanbol.contenthub.revisionmanager.StoreDBManager;
+import org.apache.stanbol.contenthub.revisionmanager.DerbyDBManager;
import org.apache.stanbol.contenthub.store.file.FileStore;
import org.apache.stanbol.enhancer.servicesapi.Blob;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
@@ -59,6 +58,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
@@ -75,10 +75,7 @@ public class FileStoreTest {
private ContentItemFactory contentItemFactory;
@TestReference
- private StoreDBManager dbManager;
-
- @TestReference
- private RevisionManager revisionManager;
+ private DerbyDBManager dbManager;
private Store<ContentItem> store;
@@ -152,8 +149,8 @@ public class FileStoreTest {
file.exists());
// check revision is updated, then delete it
- String selectRevision = "SELECT id,revision FROM " + revisionManager.getStoreID(store)
- + " content_item_revision WHERE id = '%s'";
+ String selectRevision = "SELECT id,revision FROM \""
+ + store.getProperties().get(Constants.SERVICE_PID) + "\" WHERE id = '%s'";
Connection con = dbManager.getConnection();
// Create a Statement for scrollable ResultSet
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
@@ -191,8 +188,9 @@ public class FileStoreTest {
file2.exists());
// check revisions are updated, then delete them
- String selectRevision = "SELECT id,revision FROM " + revisionManager.getStoreID(store)
- + " content_item_revision WHERE id = '%s' OR id = '%s'";
+ String selectRevision = "SELECT id,revision FROM \""
+ + store.getProperties().get(Constants.SERVICE_PID)
+ + "\" WHERE id = '%s' OR id = '%s'";
Connection con = dbManager.getConnection();
// Create a Statement for scrollable ResultSet
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
@@ -363,7 +361,8 @@ public class FileStoreTest {
f.delete();
// delete the database records
- String query = String.format("DELETE FROM %s WHERE id = ?", revisionManager.getStoreID(store));
+ String query = String.format("DELETE FROM \"%s\" WHERE id = ?",
+ store.getProperties().get(Constants.SERVICE_PID));
Connection connection = dbManager.getConnection();
PreparedStatement ps = null;
try {