[exo-jcr-commits] exo-jcr SVN: r395 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Oct 26 12:00:48 EDT 2009
Author: areshetnyak
Date: 2009-10-26 12:00:48 -0400 (Mon, 26 Oct 2009)
New Revision: 395
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java
Log:
EXOJCR-201 : ExoJCRCacheLoader was changed.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java 2009-10-26 15:59:56 UTC (rev 394)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java 2009-10-26 16:00:48 UTC (rev 395)
@@ -19,12 +19,16 @@
package org.exoplatform.services.jcr.impl.storage.jbosscache;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.Modification.ModificationType;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.loader.CacheLoader;
@@ -34,6 +38,8 @@
import java.util.Map;
import java.util.Set;
+import javax.jcr.RepositoryException;
+
/**
* Created by The eXo Platform SAS.
*
@@ -47,8 +53,6 @@
private WorkspaceDataContainer dataContainer;
- private JDBCStorageConnection jdbcConnection;
-
/**
* Init the loader DataContainer with given WorkspaceDataContainer instance.
*
@@ -131,16 +135,79 @@
*/
public void prepare(Object tx, List<Modification> modifications, boolean onePhase) throws Exception
{
- // TODO Auto-generated method stub
+ JDBCStorageConnection jdbcConnection = (JDBCStorageConnection) dataContainer.openConnection();
+ try {
+ for (Modification md : modifications)
+ {
+ switch (md.getType()) {
+ case PUT_KEY_VALUE:
+ doModified(md, jdbcConnection);
+ break;
+ case REMOVE_NODE:
+ doRemove(md, jdbcConnection);
+ break;
+ }
+ }
+
+ if (jdbcConnection != null)
+ jdbcConnection.commit();
+ } finally {
+ if (jdbcConnection != null && jdbcConnection.isOpened())
+ jdbcConnection.rollback();
+ }
}
+
+ private void doRemove(Modification modification, JDBCStorageConnection jdbcConnection) {
+ //TODO
+ }
+
+ /**
+ * Performs ADD and UPDATE to NodeData and PropertyData.
+ * @param modification
+ * @param jdbcConnection
+ * @throws IllegalStateException
+ * @throws RepositoryException
+ */
+ private void doModified(Modification modification, JDBCStorageConnection jdbcConnection) throws IllegalStateException, RepositoryException
+ {
+ if (modification.getValue() instanceof NodeData)
+ {
+ //add or update node data
+ NodeData nodeData = (NodeData) modification.getValue();
+
+ ItemData itemData = jdbcConnection.getItemData(nodeData.getIdentifier());
+
+ if (itemData == null) {
+ //add
+ jdbcConnection.add(nodeData);
+ } else {
+ //update
+ jdbcConnection.update(nodeData);
+ }
+ }
+ else if (modification.getValue() instanceof PropertyData)
+ {
+ //add or update property data
+ PropertyData propertyData = (PropertyData) modification.getValue();
+
+ ItemData itemData = jdbcConnection.getItemData(propertyData.getIdentifier());
+
+ if (itemData == null) {
+ //add
+ jdbcConnection.add(propertyData);
+ } else {
+ //update
+ jdbcConnection.update(propertyData);
+ }
+ }
+ }
/**
* {@inheritDoc}
*/
public Object put(Fqn name, Object key, Object value) throws Exception
{
- dataContainer.
return null;
}
More information about the exo-jcr-commits
mailing list