[exo-jcr-commits] exo-jcr SVN: r437 - 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
Wed Oct 28 04:54:27 EDT 2009
Author: areshetnyak
Date: 2009-10-28 04:54:26 -0400 (Wed, 28 Oct 2009)
New Revision: 437
Added:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoaderException.java
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-28 06:47:29 UTC (rev 436)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoader.java 2009-10-28 08:54:26 UTC (rev 437)
@@ -18,28 +18,29 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+
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.datamodel.QPath;
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;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.RepositoryException;
-
/**
* Created by The eXo Platform SAS.
*
@@ -48,11 +49,19 @@
* @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter Nedonosko</a>
* @version $Id$
*/
-public class ExoJCRCacheLoader implements CacheLoader
+public class ExoJCRCacheLoader
+ implements CacheLoader
{
+ private CacheSPI cache;
+ private RegionManager regionManager;
+
+ private IndividualCacheLoaderConfig config;
+
private WorkspaceDataContainer dataContainer;
-
+
+ private HashMap<Object, List<Modification>> transactions = new HashMap<Object, List<Modification>>();
+
/**
* Init the loader DataContainer with given WorkspaceDataContainer instance.
*
@@ -60,10 +69,11 @@
*/
public void initDataContainer(WorkspaceDataContainer dataContainer) throws RepositoryConfigurationException
{
- if (this.dataContainer != null) {
+ if (this.dataContainer != null)
+ {
throw new RepositoryConfigurationException("Cannot set WorkspaceDataContainer twice");
}
-
+
this.dataContainer = dataContainer;
}
@@ -72,8 +82,11 @@
*/
public void commit(Object tx) throws Exception
{
- // TODO Auto-generated method stub
-
+ List<Modification> modifications = transactions.remove(tx);
+ if (modifications != null)
+ doModified(modifications);
+ else
+ throw new ExoJCRCacheLoaderException("Transaction " + tx + " not exist in transaction table");
}
/**
@@ -108,8 +121,7 @@
*/
public IndividualCacheLoaderConfig getConfig()
{
- // TODO Auto-generated method stub
- return null;
+ return config;
}
/**
@@ -135,33 +147,64 @@
*/
public void prepare(Object tx, List<Modification> modifications, boolean onePhase) throws Exception
{
+ if (onePhase)
+ {
+ doModified(modifications);
+ }
+ else
+ {
+ transactions.put(tx, modifications);
+ }
+ }
+
+ /**
+ * Will be added data to DB.
+ *
+ * @param modifications
+ * @throws Exception
+ */
+ private void doModified(List<Modification> modifications) throws Exception
+ {
JDBCStorageConnection jdbcConnection = (JDBCStorageConnection) dataContainer.openConnection();
- try {
- for (Modification md : modifications)
+ try
+ {
+ for (int modificatinIndex = 0; modificatinIndex < modifications.size(); modificatinIndex++)
{
- switch (md.getType()) {
- case PUT_KEY_VALUE:
- doModified(md, jdbcConnection);
+ Modification md = modifications.get(modificatinIndex);
+ switch (md.getType())
+ {
+ case PUT_KEY_VALUE :
+ doModifiedAddOrUpdate(md, jdbcConnection);
break;
- case REMOVE_NODE:
- doRemove(md, jdbcConnection);
+ case REMOVE_NODE :
+ doRemove(md, jdbcConnection, "TODO $<Node identifier>");
break;
}
}
-
+
if (jdbcConnection != null)
jdbcConnection.commit();
- } finally {
+ }
+ finally
+ {
if (jdbcConnection != null && jdbcConnection.isOpened())
jdbcConnection.rollback();
}
}
-
- private void doRemove(Modification modification, JDBCStorageConnection jdbcConnection) {
- //TODO
+
+ private void doRemove(Modification modification, JDBCStorageConnection jdbcConnection, String identifier)
+ throws IllegalStateException, RepositoryException
+ {
+
+ ItemData itemData = jdbcConnection.getItemData(identifier);
+
+ if (itemData instanceof NodeData)
+ jdbcConnection.delete((NodeData) itemData);
+ if (itemData instanceof PropertyData)
+ jdbcConnection.delete((PropertyData) itemData);
}
-
+
/**
* Performs ADD and UPDATE to NodeData and PropertyData.
* @param modification
@@ -169,34 +212,41 @@
* @throws IllegalStateException
* @throws RepositoryException
*/
- private void doModified(Modification modification, JDBCStorageConnection jdbcConnection) throws IllegalStateException, RepositoryException
+ private void doModifiedAddOrUpdate(Modification modification, JDBCStorageConnection jdbcConnection)
+ throws IllegalStateException, RepositoryException
{
- if (modification.getValue() instanceof NodeData)
+ if (modification.getValue() instanceof NodeData)
{
//add or update node data
NodeData nodeData = (NodeData) modification.getValue();
-
+
ItemData itemData = jdbcConnection.getItemData(nodeData.getIdentifier());
-
- if (itemData == null) {
+
+ if (itemData == null)
+ {
//add
jdbcConnection.add(nodeData);
- } else {
+ }
+ 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) {
+
+ if (itemData == null)
+ {
//add
jdbcConnection.add(propertyData);
- } else {
+ }
+ else
+ {
//update
jdbcConnection.update(propertyData);
}
@@ -261,8 +311,7 @@
*/
public void rollback(Object tx)
{
- // TODO Auto-generated method stub
-
+ transactions.remove(tx);
}
/**
@@ -270,7 +319,7 @@
*/
public void setCache(CacheSPI c)
{
- // TODO Auto-generated method stub
+ this.cache = c;
}
@@ -279,7 +328,7 @@
*/
public void setConfig(IndividualCacheLoaderConfig config)
{
- // TODO Auto-generated method stub
+ this.config = config;
}
@@ -288,8 +337,7 @@
*/
public void setRegionManager(RegionManager manager)
{
- // TODO Auto-generated method stub
-
+ this.regionManager = manager;
}
/**
Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoaderException.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoaderException.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoaderException.java 2009-10-28 08:54:26 UTC (rev 437)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>
+ * Date: 27.10.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class ExoJCRCacheLoaderException
+ extends Exception
+{
+ /**
+ * Constructs an Exception without a message.
+ */
+ public ExoJCRCacheLoaderException()
+ {
+ super();
+ }
+
+ /**
+ * Constructs an Exception with a detailed message.
+ *
+ * @param Message
+ * The message associated with the exception.
+ */
+ public ExoJCRCacheLoaderException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructs an Exception with a detailed message and base exception.
+ *
+ * @param Message
+ * The message associated with the exception.
+ * @param cause
+ * Throwable, the base exception.
+ */
+ public ExoJCRCacheLoaderException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ /**
+ * RepositoryConfigurationException constructor.
+ *
+ * @param cause
+ * Throwable, the base exception.
+ */
+ public ExoJCRCacheLoaderException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ExoJCRCacheLoaderException.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the exo-jcr-commits
mailing list