exo-jcr SVN: r1173 - ws/trunk/exo.ws.commons/src/main/java/org/exoplatform/common/http/client.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2009-12-24 11:11:56 -0500 (Thu, 24 Dec 2009)
New Revision: 1173
Modified:
ws/trunk/exo.ws.commons/src/main/java/org/exoplatform/common/http/client/HTTPConnection.java
Log:
EXOJCR-346 methods
public HTTPResponse Get(String file, String query) throws IOException, ModuleException
public HTTPResponse Get(String file, String query, NVPair[] headers) throws IOException, ModuleException
marked as deprecated
Modified: ws/trunk/exo.ws.commons/src/main/java/org/exoplatform/common/http/client/HTTPConnection.java
===================================================================
--- ws/trunk/exo.ws.commons/src/main/java/org/exoplatform/common/http/client/HTTPConnection.java 2009-12-24 15:52:23 UTC (rev 1172)
+++ ws/trunk/exo.ws.commons/src/main/java/org/exoplatform/common/http/client/HTTPConnection.java 2009-12-24 16:11:56 UTC (rev 1173)
@@ -892,6 +892,7 @@
* socket.
* @exception ModuleException if an exception is encountered in any module.
*/
+ @Deprecated
public HTTPResponse Get(String file, String query) throws IOException, ModuleException
{
return Get(file, query, null);
@@ -908,6 +909,7 @@
* socket.
* @exception ModuleException if an exception is encountered in any module.
*/
+ @Deprecated
public HTTPResponse Get(String file, String query, NVPair[] headers) throws IOException, ModuleException
{
String File = stripRef(file);
16 years, 7 months
exo-jcr SVN: r1172 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation: db and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2009-12-24 10:52:23 -0500 (Thu, 24 Dec 2009)
New Revision: 1172
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCStorageConnection.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
Log:
EXOJCR-302: getChildNodes query result parsing implemented
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCStorageConnection.java 2009-12-24 15:52:07 UTC (rev 1171)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCStorageConnection.java 2009-12-24 15:52:23 UTC (rev 1172)
@@ -60,7 +60,10 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
import javax.jcr.InvalidItemStateException;
@@ -587,12 +590,22 @@
checkIfOpened();
try
{
- ResultSet node = findChildNodesByParentIdentifier(getInternalId(parent.getIdentifier()));
- List<NodeData> childrens = new ArrayList<NodeData>();
- while (node.next())
- childrens.add((NodeData)itemData(parent.getQPath(), node, I_CLASS_NODE, parent.getACL()));
+ // ResultSet node = findChildNodesByParentIdentifier(getInternalId(parent.getIdentifier()));
+ // List<NodeData> childrens = new ArrayList<NodeData>();
+ // while (node.next())
+ // childrens.add((NodeData)itemData(parent.getQPath(), node, I_CLASS_NODE, parent.getACL()));
+ //
+ // return childrens;
+ ResultSet resultSet = findChildNodesByParentIdentifierNew(getInternalId(parent.getIdentifier()));
+ if (resultSet.next())
+ {
+ return loadChildNodesData(resultSet, parent);
+ }
+ else
+ {
+ return new ArrayList<NodeData>();
+ }
- return childrens;
}
catch (SQLException e)
{
@@ -604,6 +617,80 @@
}
}
+ protected List<NodeData> loadChildNodesData(ResultSet resultSet, NodeData parent) throws RepositoryException,
+ IOException, SQLException
+ {
+
+ Map<String, TempNodeData> nodesData = new LinkedHashMap<String, TempNodeData>();
+ do
+ {
+ int itemClass = resultSet.getInt(COLUMN_CLASS);
+ if (itemClass == I_CLASS_NODE)
+ {
+ TempNodeData data = new TempNodeData(resultSet);
+ nodesData.put(data.cid, data);
+ }
+ else
+ {
+ String cpid = resultSet.getString(COLUMN_PARENTID);
+ TempNodeData data = nodesData.get(cpid);
+ if (data.properties == null)
+ {
+ data.properties = new HashMap<String, List<byte[]>>();
+ }
+ Map<String, List<byte[]>> properties = data.properties;
+ String key = resultSet.getString(COLUMN_NAME);
+ List<byte[]> values = properties.get(key);
+ if (values == null)
+ {
+ values = new ArrayList<byte[]>();
+ properties.put(key, values);
+ }
+ values.add(resultSet.getBytes(COLUMN_VDATA));
+ }
+ }
+ while (resultSet.next());
+
+ List<NodeData> childrens = new ArrayList<NodeData>(nodesData.size());
+ QPath parentQPath = parent.getQPath();
+ AccessControlList parentACL = parent.getACL();
+ for (TempNodeData data : nodesData.values())
+ {
+ NodeData nodeData = loadNodeRecordFromBuffer(data, parentQPath, parentACL);
+ childrens.add(nodeData);
+ }
+ return childrens;
+ }
+
+ private static class TempNodeData
+ {
+ String cid;
+
+ String cname;
+
+ int cversion;
+
+ String cpid;
+
+ int cindex;
+
+ int cnordernumb;
+
+ Map<String, List<byte[]>> properties = new HashMap<String, List<byte[]>>();
+
+ public TempNodeData(ResultSet item) throws SQLException
+ {
+ cid = item.getString(COLUMN_ID);
+ cname = item.getString(COLUMN_NAME);
+ cversion = item.getInt(COLUMN_VERSION);
+
+ cpid = item.getString(COLUMN_PARENTID);
+
+ cindex = item.getInt(COLUMN_INDEX);
+ cnordernumb = item.getInt(COLUMN_NORDERNUM);
+ }
+ }
+
/**
* {@inheritDoc}
*/
@@ -1821,6 +1908,157 @@
}
}
+ protected PersistedNodeData loadNodeRecordFromBuffer(TempNodeData buf, QPath parentPath, AccessControlList pACL)
+ throws RepositoryException, SQLException, IOException
+ {
+
+ String cid = buf.cid;
+ String cname = buf.cname;
+ int cversion = buf.cversion;
+ String cpid = buf.cpid;
+ int cindex = buf.cindex;
+ int cnordernumb = buf.cnordernumb;
+ AccessControlList parentACL = pACL;
+
+ try
+ {
+ InternalQName qname = InternalQName.parse(cname);
+
+ // TODO can't avoid QPath traverse
+ QPath qpath;
+ String parentCid;
+ if (parentPath != null)
+ {
+ // get by parent and name
+ qpath = QPath.makeChildPath(parentPath, qname, cindex);
+ parentCid = cpid;
+ }
+ else
+ {
+ // get by id
+ if (cpid.equals(Constants.ROOT_PARENT_UUID))
+ {
+ // root node
+ qpath = Constants.ROOT_PATH;
+ parentCid = null;
+ }
+ else
+ {
+ qpath = QPath.makeChildPath(traverseQPath(cpid), qname, cindex);
+ parentCid = cpid;
+ }
+ }
+
+ // PRIMARY
+
+ List<byte[]> primaryType = buf.properties.get(Constants.JCR_PRIMARYTYPE.getAsString());
+ if (primaryType == null || primaryType.size() == 0)
+ {
+ throw new SQLException("Node finded but primaryType property not " + cid);
+ }
+
+ byte[] data = primaryType.get(0);
+ InternalQName ptName = InternalQName.parse(new String((data != null ? data : new byte[]{})));
+
+ // MIXIN
+ MixinInfo mixins = null;
+ List<InternalQName> mts = null;
+ boolean owneable = false;
+ boolean privilegeable = false;
+ List<byte[]> mixinTypes = buf.properties.get(Constants.JCR_MIXINTYPES.getAsString());
+ if (mixinTypes != null)
+ {
+ mts = new ArrayList<InternalQName>();
+ for (byte[] mxnb : mixinTypes)
+ {
+ InternalQName mxn = InternalQName.parse(new String(mxnb));
+ mts.add(mxn);
+
+ if (!privilegeable && Constants.EXO_PRIVILEGEABLE.equals(mxn))
+ privilegeable = true;
+ else if (!owneable && Constants.EXO_OWNEABLE.equals(mxn))
+ owneable = true;
+ }
+ }
+
+ mixins = new MixinInfo(mts, owneable, privilegeable);
+
+ try
+ {
+ // ACL
+ AccessControlList acl; // NO DEFAULT values!
+
+ if (mixins.hasOwneable())
+ {
+ // has own owner
+ if (mixins.hasPrivilegeable())
+ {
+ // and permissions
+ acl = new AccessControlList(readACLOwner(cid), readACLPermisions(cid));
+ }
+ else if (parentACL != null)
+ {
+ // use permissions from existed parent
+ acl =
+ new AccessControlList(readACLOwner(cid), parentACL.hasPermissions() ? parentACL
+ .getPermissionEntries() : null);
+ }
+ else
+ {
+ // have to search nearest ancestor permissions in ACL manager
+ // acl = new AccessControlList(readACLOwner(cid), traverseACLPermissions(cpid));
+ acl = new AccessControlList(readACLOwner(cid), null);
+ }
+ }
+ else if (mixins.hasPrivilegeable())
+ {
+ // has own permissions
+ if (mixins.hasOwneable())
+ {
+ // and owner
+ acl = new AccessControlList(readACLOwner(cid), readACLPermisions(cid));
+ }
+ else if (parentACL != null)
+ {
+ // use owner from existed parent
+ acl = new AccessControlList(parentACL.getOwner(), readACLPermisions(cid));
+ }
+ else
+ {
+ // have to search nearest ancestor owner in ACL manager
+ // acl = new AccessControlList(traverseACLOwner(cpid), readACLPermisions(cid));
+ acl = new AccessControlList(null, readACLPermisions(cid));
+ }
+ }
+ else
+ {
+ if (parentACL != null)
+ // construct ACL from existed parent ACL
+ acl =
+ new AccessControlList(parentACL.getOwner(), parentACL.hasPermissions() ? parentACL
+ .getPermissionEntries() : null);
+ else
+ // have to search nearest ancestor owner and permissions in ACL manager
+ // acl = traverseACL(cpid);
+ acl = null;
+ }
+
+ return new PersistedNodeData(getIdentifier(cid), qpath, getIdentifier(parentCid), cversion, cnordernumb,
+ ptName, mixins.mixinNames(), acl);
+
+ }
+ catch (IllegalACLException e)
+ {
+ throw new RepositoryException("FATAL ERROR Node " + getIdentifier(cid) + " " + qpath.getAsString()
+ + " has wrong formed ACL. ", e);
+ }
+ }
+ catch (IllegalNameException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
protected PersistedPropertyData loadPropertyRecord(ResultSet item, QPath parentPath) throws RepositoryException,
SQLException, IOException
{
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2009-12-24 15:52:07 UTC (rev 1171)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2009-12-24 15:52:23 UTC (rev 1172)
@@ -223,10 +223,10 @@
FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where I_CLASS=1 and PARENT_ID=?" + " order by N_ORDER_NUM";
FIND_NODES_BY_PARENTID_NEW =
- "select I.*, V.ORDER_NUM, V.DATA, V.STORAGE_DESC"
- + " from JCR_MITEM I LEFT OUTER JOIN JCR_MVALUE V ON (V.PROPERTY_ID=I.ID), (select ID, PARENT_ID from JCR_MITEM where PARENT_ID=? AND I_CLASS=1) I2"
- + " where (I.PARENT_ID=? AND I.I_CLASS=1 AND I2.ID=I.ID) OR (I.I_CLASS=2 and I.PARENT_ID=I2.ID and"
- + " I.NAME IN ('[http://www.jcp.org/jcr/1.0]primaryType','[http://www.jcp.org/jcr/1.0]mixinTypes')) order by I.I_CLASS, I.N_ORDER_NUM";
+ "select I.*, V.DATA"
+ + " from JCR_MITEM I LEFT OUTER JOIN JCR_MVALUE V ON (V.PROPERTY_ID=I.ID), (select ID from JCR_MITEM where PARENT_ID=? AND I_CLASS=1) I2"
+ + " where (I.I_CLASS=1 AND I.ID=I2.ID) OR (I.I_CLASS=2 and I.PARENT_ID=I2.ID and"
+ + " (I.NAME='[http://www.jcp.org/jcr/1.0]primaryType' OR I.NAME='[http://www.jcp.org/jcr/1.0]mixinTypes')) order by I.I_CLASS, I.N_ORDER_NUM";
//,'[http://www.exoplatform.com/jcr/exo/1.0]owner','[http://www.exoplatform.com/jcr/exo/1.0]permissions'
FIND_NODES_COUNT_BY_PARENTID = "select count(ID) from JCR_MITEM" + " where I_CLASS=1 and PARENT_ID=?";
@@ -506,7 +506,7 @@
findNodesByParentId.clearParameters();
findNodesByParentId.setString(1, parentIdentifier);
- findNodesByParentId.setString(2, parentIdentifier);
+ //findNodesByParentId.setString(2, parentIdentifier);
return findNodesByParentId.executeQuery();
}
16 years, 7 months
exo-jcr SVN: r1171 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent: jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-24 10:52:07 -0500 (Thu, 24 Dec 2009)
New Revision: 1171
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-334 : code clean up.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24 15:38:31 UTC (rev 1170)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24 15:52:07 UTC (rev 1171)
@@ -61,197 +61,10 @@
protected final Map<Integer, DataRequest> requestCache;
/**
- * ItemData request, used on get operations.
*
*/
- protected class DataRequest
- {
+ private TransactionManager transactionManager;
- /**
- * GET_NODES type.
- */
- static public final int GET_NODES = 1;
-
- /**
- * GET_PROPERTIES type.
- */
- static public final int GET_PROPERTIES = 2;
-
- /**
- * GET_ITEM_ID type.
- */
- static private final int GET_ITEM_ID = 3;
-
- /**
- * GET_ITEM_NAME type.
- */
- static private final int GET_ITEM_NAME = 4;
-
- /**
- * Request type.
- */
- protected final int type;
-
- /**
- * Item parentId.
- */
- protected final String parentId;
-
- /**
- * Item id.
- */
- protected final String id;
-
- /**
- * Item name.
- */
- protected final QPathEntry name;
-
- /**
- * Hash code.
- */
- protected final int hcode;
-
- /**
- * Readiness latch.
- */
- protected CountDownLatch ready = new CountDownLatch(1);
-
- /**
- * DataRequest constructor.
- *
- * @param parentId
- * parent id
- * @param type
- * request type
- */
- DataRequest(String parentId, int type)
- {
- this.parentId = parentId;
- this.name = null;
- this.id = null;
- this.type = type;
-
- // hashcode
- this.hcode = 31 * (31 + this.type) + this.parentId.hashCode();
- }
-
- /**
- * DataRequest constructor.
- *
- * @param parentId
- * parent id
- * @param name
- * Item name
- */
- DataRequest(String parentId, QPathEntry name)
- {
- this.parentId = parentId;
- this.name = name;
- this.id = null;
- this.type = GET_ITEM_NAME;
-
- // hashcode
- int hc = 31 * (31 + this.type) + this.parentId.hashCode();
- this.hcode = 31 * hc + this.name.hashCode();
- }
-
- /**
- * DataRequest constructor.
- *
- * @param id
- * Item id
- */
- DataRequest(String id)
- {
- this.parentId = null;
- this.name = null;
- this.id = id;
- this.type = GET_ITEM_ID;
-
- // hashcode
- this.hcode = 31 * (31 + this.type) + this.id.hashCode();
- }
-
- /**
- * Find the same, and if found wait till the one will be finished.
- *
- * WARNING. This method effective with cache use only!!! Without cache the database will control
- * requests performance/chaching process.
- *
- * @return this data request
- */
- DataRequest waitSame()
- {
- DataRequest prev = null;
- synchronized (requestCache)
- {
- prev = requestCache.get(this.hashCode());
- }
- if (prev != null)
- prev.await();
- return this;
- }
-
- /**
- * Start the request, each same will wait till this will be finished
- */
- void start()
- {
- synchronized (requestCache)
- {
- requestCache.put(this.hashCode(), this);
- }
- }
-
- /**
- * Done the request. Must be called after the data request will be finished. This call allow
- * another same requests to be performed.
- */
- void done()
- {
- this.ready.countDown();
- synchronized (requestCache)
- {
- requestCache.remove(this.hashCode());
- }
- }
-
- /**
- * Await this thread for another one running same request.
- *
- */
- void await()
- {
- try
- {
- this.ready.await();
- }
- catch (InterruptedException e)
- {
- LOG.warn("Can't wait for same request process. " + e, e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj)
- {
- return this.hcode == obj.hashCode();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
- {
- return hcode;
- }
- }
-
/**
* CacheableWorkspaceDataManager constructor.
*
@@ -267,29 +80,62 @@
{
super(dataContainer, systemDataContainerHolder);
this.cache = cache;
+
this.requestCache = new HashMap<Integer, DataRequest>();
addItemPersistenceListener(cache);
+ if (cache instanceof JBossCacheWorkspaceStorageCache)
+ {
+ transactionManager = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+ }
+ else
+ {
+ transactionManager = null;
+ }
}
/**
- * {@inheritDoc}
+ * Get Items Cache.
+ *
+ * @return WorkspaceStorageCache
*/
- public ItemData getItemData(String identifier) throws RepositoryException
+ public WorkspaceStorageCache getCache()
{
- // 2. Try from cache
- ItemData data = getCachedItemData(identifier);
+ return cache;
+ }
- // 3. Try from container
- if (data == null)
+ public int getChildNodesCount(NodeData parent) throws RepositoryException
+ {
+ if (cache.isEnabled())
{
- return getPersistedItemData(identifier);
+ List<NodeData> childNodes = cache.getChildNodes(parent);
+ if (childNodes != null)
+ {
+ return childNodes.size();
+ }
}
- return data;
+
+ return super.getChildNodesCount(parent);
}
/**
* {@inheritDoc}
*/
+ public List<NodeData> getChildNodesData(NodeData nodeData) throws RepositoryException
+ {
+ return getChildNodesData(nodeData, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> getChildPropertiesData(NodeData nodeData) throws RepositoryException
+ {
+ return getChildPropertiesData(nodeData, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ItemData getItemData(NodeData parentData, QPathEntry name) throws RepositoryException
{
@@ -306,78 +152,121 @@
}
/**
+ * {@inheritDoc}
+ */
+ public ItemData getItemData(String identifier) throws RepositoryException
+ {
+ // 2. Try from cache
+ ItemData data = getCachedItemData(identifier);
+
+ // 3. Try from container
+ if (data == null)
+ {
+ return getPersistedItemData(identifier);
+ }
+ return data;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> getReferencesData(String identifier, boolean skipVersionStorage)
+ throws RepositoryException
+ {
+ return super.getReferencesData(identifier, skipVersionStorage);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> listChildPropertiesData(NodeData nodeData) throws RepositoryException
+ {
+ return listChildPropertiesData(nodeData, false);
+ }
+
+ /**
* @see org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#save(org.exoplatform.services.jcr.dataflow.ItemStateChangesLog)
*/
@Override
public void save(ItemStateChangesLog changesLog) throws RepositoryException
{
- TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
-
- try
+ if (transactionManager == null)
{
- tm.begin();
super.save(changesLog);
- tm.commit();
}
- catch (RollbackException e)
+ else
{
- // Indicate that the transaction has been rolled back rather than committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
- catch (RepositoryException e)
- {
try
{
- tm.rollback();
+ transactionManager.begin();
+ super.save(changesLog);
+ transactionManager.commit();
}
- catch (Exception e1)
+ catch (RollbackException e)
{
- // Treat the exception
+ // Indicate that the transaction has been rolled back rather than committed.
throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
- throw e;
- }
- catch (Exception e)
- {
- try
+ catch (RepositoryException e)
{
- tm.rollback();
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ throw e;
}
- catch (Exception e1)
+ catch (Exception e)
{
- // Treat the exception
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e1.getLocalizedMessage(), e1.getCause());
+ }
throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
-
}
/**
- * {@inheritDoc}
+ * Get cached ItemData.
+ *
+ * @param parentData
+ * parent
+ * @param name
+ * Item name
+ * @return ItemData
+ * @throws RepositoryException
+ * error
*/
- public List<NodeData> getChildNodesData(NodeData nodeData) throws RepositoryException
+ protected ItemData getCachedItemData(NodeData parentData, QPathEntry name) throws RepositoryException
{
- return getChildNodesData(nodeData, false);
+ return cache.get(parentData.getIdentifier(), name);
}
/**
- * {@inheritDoc}
+ * Returns an item from cache by Identifier or null if the item don't cached.
+ *
+ * @param identifier
+ * Item id
+ * @return ItemData
+ * @throws RepositoryException
+ * error
*/
- public List<PropertyData> getChildPropertiesData(NodeData nodeData) throws RepositoryException
+ protected ItemData getCachedItemData(String identifier) throws RepositoryException
{
- return getChildPropertiesData(nodeData, false);
+ return cache.get(identifier);
}
/**
- * {@inheritDoc}
- */
- public List<PropertyData> listChildPropertiesData(NodeData nodeData) throws RepositoryException
- {
- return listChildPropertiesData(nodeData, false);
- }
-
- /**
* Get child NodesData.
*
* @param nodeData
@@ -417,38 +306,43 @@
if (parentData != null)
{
-
- TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
-
- try
+ if (transactionManager == null)
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
- {
- cache.addChildNodes(parentData, childNodes);
- }
- else
- {
- tm.begin();
- cache.addChildNodes(parentData, childNodes);
- tm.commit();
- }
+ cache.addChildNodes(parentData, childNodes);
}
- catch (RollbackException e)
+ else
{
- // Indicate that the transaction has been rolled back rather than committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
- catch (Exception e)
- {
+
try
{
- tm.rollback();
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildNodes(parentData, childNodes);
+ }
+ else
+ {
+ transactionManager.begin();
+ cache.addChildNodes(parentData, childNodes);
+ transactionManager.commit();
+ }
}
- catch (Exception e1)
+ catch (RollbackException e)
{
- // Treat the exception
+ // Indicate that the transaction has been rolled back rather than committed.
throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
+ catch (Exception e)
+ {
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
}
@@ -460,20 +354,6 @@
}
}
- public int getChildNodesCount(NodeData parent) throws RepositoryException
- {
- if (cache.isEnabled())
- {
- List<NodeData> childNodes = cache.getChildNodes(parent);
- if (childNodes != null)
- {
- return childNodes.size();
- }
- }
-
- return super.getChildNodesCount(parent);
- }
-
/**
* Get child PropertyData.
*
@@ -516,37 +396,42 @@
if (parentData != null)
{
-
- TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
- try
+ if (transactionManager == null)
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
- {
- cache.addChildProperties(parentData, childProperties);
- }
- else
- {
- tm.begin();
- cache.addChildProperties(parentData, childProperties);
- tm.commit();
- }
+ cache.addChildProperties(parentData, childProperties);
}
- catch (RollbackException e)
+ else
{
- // Indicate that the transaction has been rolled back rather than committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
- catch (Exception e)
- {
try
{
- tm.rollback();
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildProperties(parentData, childProperties);
+ }
+ else
+ {
+ transactionManager.begin();
+ cache.addChildProperties(parentData, childProperties);
+ transactionManager.commit();
+ }
}
- catch (Exception e1)
+ catch (RollbackException e)
{
- // Treat the exception
+ // Indicate that the transaction has been rolled back rather than committed.
throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
+ catch (Exception e)
+ {
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
}
@@ -559,57 +444,40 @@
}
/**
- * Get child PropertyData list (without ValueData).
+ * Get persisted ItemData.
*
- * @param nodeData
+ * @param parentData
* parent
- * @param forcePersistentRead
- * true if persistent read is required (without cache)
- * @return List<PropertyData>
+ * @param name
+ * Item name
+ * @return ItemData
* @throws RepositoryException
- * Repository error
+ * error
*/
- protected List<PropertyData> listChildPropertiesData(NodeData nodeData, boolean forcePersistentRead)
- throws RepositoryException
+ protected ItemData getPersistedItemData(NodeData parentData, QPathEntry name) throws RepositoryException
{
- final DataRequest request = new DataRequest(nodeData.getIdentifier(), DataRequest.GET_PROPERTIES);
-
- List<PropertyData> propertiesList;
- if (!forcePersistentRead && cache.isEnabled())
+ ItemData data = null;
+ data = super.getItemData(parentData, name);
+ if (data != null && cache.isEnabled())
{
- request.waitSame(); // wait if getChildProp... working somewhere
- propertiesList = cache.listChildProperties(nodeData);
- if (propertiesList != null)
- return propertiesList;
- }
-
- propertiesList = super.listChildPropertiesData(nodeData);
- // TODO propertiesList.size() > 0 for SDB
- if (propertiesList.size() > 0 && cache.isEnabled())
- {
- NodeData parentData = (NodeData)cache.get(nodeData.getIdentifier());
- if (parentData == null)
+ if (transactionManager == null)
{
- parentData = (NodeData)super.getItemData(nodeData.getIdentifier());
+ cache.put(data);
}
-
- if (parentData != null)
+ else
{
-
- TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
-
try
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
{
- cache.addChildPropertiesList(parentData, propertiesList);
+ cache.put(data);
}
else
{
- tm.begin();
- cache.addChildPropertiesList(parentData, propertiesList);
- tm.commit();
+ transactionManager.begin();
+ cache.put(data);
+ transactionManager.commit();
}
}
catch (RollbackException e)
@@ -621,7 +489,7 @@
{
try
{
- tm.rollback();
+ transactionManager.rollback();
}
catch (Exception e1)
{
@@ -631,161 +499,334 @@
}
}
}
- return propertiesList;
+ return data;
}
/**
- * {@inheritDoc}
- */
- public List<PropertyData> getReferencesData(String identifier, boolean skipVersionStorage)
- throws RepositoryException
- {
- return super.getReferencesData(identifier, skipVersionStorage);
- }
-
- /**
- * Get Items Cache.
+ * Call
+ * {@link org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#getItemData(java.lang.String)
+ * WorkspaceDataManager.getItemDataByIdentifier(java.lang.String)} and cache result if non null
+ * returned.
*
- * @return WorkspaceStorageCache
+ * @see org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#getItemData(java.lang.String)
*/
- public WorkspaceStorageCache getCache()
+ protected ItemData getPersistedItemData(String identifier) throws RepositoryException
{
- return cache;
- }
+ ItemData data = super.getItemData(identifier);
+ if (data != null && cache.isEnabled())
+ {
+ if (transactionManager == null)
+ {
+ cache.put(data);
+ }
+ else
+ {
+ try
+ {
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(data);
+ }
+ else
+ {
+ transactionManager.begin();
+ cache.put(data);
+ transactionManager.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+ }
- /**
- * Get cached ItemData.
- *
- * @param parentData
- * parent
- * @param name
- * Item name
- * @return ItemData
- * @throws RepositoryException
- * error
- */
- protected ItemData getCachedItemData(NodeData parentData, QPathEntry name) throws RepositoryException
- {
- return cache.get(parentData.getIdentifier(), name);
+ }
+ return data;
}
/**
- * Get persisted ItemData.
+ * Get child PropertyData list (without ValueData).
*
- * @param parentData
+ * @param nodeData
* parent
- * @param name
- * Item name
- * @return ItemData
+ * @param forcePersistentRead
+ * true if persistent read is required (without cache)
+ * @return List<PropertyData>
* @throws RepositoryException
- * error
+ * Repository error
*/
- protected ItemData getPersistedItemData(NodeData parentData, QPathEntry name) throws RepositoryException
+ protected List<PropertyData> listChildPropertiesData(NodeData nodeData, boolean forcePersistentRead)
+ throws RepositoryException
{
- ItemData data = null;
- data = super.getItemData(parentData, name);
- if (data != null && cache.isEnabled())
+ final DataRequest request = new DataRequest(nodeData.getIdentifier(), DataRequest.GET_PROPERTIES);
+
+ List<PropertyData> propertiesList;
+ if (!forcePersistentRead && cache.isEnabled())
{
- TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+ request.waitSame(); // wait if getChildProp... working somewhere
+ propertiesList = cache.listChildProperties(nodeData);
+ if (propertiesList != null)
+ return propertiesList;
+ }
- try
+ propertiesList = super.listChildPropertiesData(nodeData);
+ // TODO propertiesList.size() > 0 for SDB
+ if (propertiesList.size() > 0 && cache.isEnabled())
+ {
+ NodeData parentData = (NodeData)cache.get(nodeData.getIdentifier());
+ if (parentData == null)
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
- {
- cache.put(data);
- }
- else
- {
- tm.begin();
- cache.put(data);
- tm.commit();
- }
+ parentData = (NodeData)super.getItemData(nodeData.getIdentifier());
}
- catch (RollbackException e)
+
+ if (parentData != null)
{
- // Indicate that the transaction has been rolled back rather than committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
- catch (Exception e)
- {
- try
+ if (transactionManager == null)
{
- tm.rollback();
+ cache.addChildPropertiesList(parentData, propertiesList);
}
- catch (Exception e1)
+ else
{
- // Treat the exception
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ try
+ {
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildPropertiesList(parentData, propertiesList);
+ }
+ else
+ {
+ transactionManager.begin();
+ cache.addChildPropertiesList(parentData, propertiesList);
+ transactionManager.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
}
- return data;
+ return propertiesList;
}
/**
- * Returns an item from cache by Identifier or null if the item don't cached.
+ * ItemData request, used on get operations.
*
- * @param identifier
- * Item id
- * @return ItemData
- * @throws RepositoryException
- * error
*/
- protected ItemData getCachedItemData(String identifier) throws RepositoryException
+ protected class DataRequest
{
- return cache.get(identifier);
- }
- /**
- * Call
- * {@link org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#getItemData(java.lang.String)
- * WorkspaceDataManager.getItemDataByIdentifier(java.lang.String)} and cache result if non null
- * returned.
- *
- * @see org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#getItemData(java.lang.String)
- */
- protected ItemData getPersistedItemData(String identifier) throws RepositoryException
- {
- ItemData data = super.getItemData(identifier);
- if (data != null && cache.isEnabled())
+ /**
+ * GET_NODES type.
+ */
+ static public final int GET_NODES = 1;
+
+ /**
+ * GET_PROPERTIES type.
+ */
+ static public final int GET_PROPERTIES = 2;
+
+ /**
+ * GET_ITEM_ID type.
+ */
+ static private final int GET_ITEM_ID = 3;
+
+ /**
+ * GET_ITEM_NAME type.
+ */
+ static private final int GET_ITEM_NAME = 4;
+
+ /**
+ * Request type.
+ */
+ protected final int type;
+
+ /**
+ * Item parentId.
+ */
+ protected final String parentId;
+
+ /**
+ * Item id.
+ */
+ protected final String id;
+
+ /**
+ * Item name.
+ */
+ protected final QPathEntry name;
+
+ /**
+ * Hash code.
+ */
+ protected final int hcode;
+
+ /**
+ * Readiness latch.
+ */
+ protected CountDownLatch ready = new CountDownLatch(1);
+
+ /**
+ * DataRequest constructor.
+ *
+ * @param id
+ * Item id
+ */
+ DataRequest(String id)
{
+ this.parentId = null;
+ this.name = null;
+ this.id = id;
+ this.type = GET_ITEM_ID;
- TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+ // hashcode
+ this.hcode = 31 * (31 + this.type) + this.id.hashCode();
+ }
+ /**
+ * DataRequest constructor.
+ *
+ * @param parentId
+ * parent id
+ * @param type
+ * request type
+ */
+ DataRequest(String parentId, int type)
+ {
+ this.parentId = parentId;
+ this.name = null;
+ this.id = null;
+ this.type = type;
+
+ // hashcode
+ this.hcode = 31 * (31 + this.type) + this.parentId.hashCode();
+ }
+
+ /**
+ * DataRequest constructor.
+ *
+ * @param parentId
+ * parent id
+ * @param name
+ * Item name
+ */
+ DataRequest(String parentId, QPathEntry name)
+ {
+ this.parentId = parentId;
+ this.name = name;
+ this.id = null;
+ this.type = GET_ITEM_NAME;
+
+ // hashcode
+ int hc = 31 * (31 + this.type) + this.parentId.hashCode();
+ this.hcode = 31 * hc + this.name.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ return this.hcode == obj.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ return hcode;
+ }
+
+ /**
+ * Await this thread for another one running same request.
+ *
+ */
+ void await()
+ {
try
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
- {
- cache.put(data);
- }
- else
- {
- tm.begin();
- cache.put(data);
- tm.commit();
- }
+ this.ready.await();
}
- catch (RollbackException e)
+ catch (InterruptedException e)
{
- // Indicate that the transaction has been rolled back rather than committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ LOG.warn("Can't wait for same request process. " + e, e);
}
- catch (Exception e)
+ }
+
+ /**
+ * Done the request. Must be called after the data request will be finished. This call allow
+ * another same requests to be performed.
+ */
+ void done()
+ {
+ this.ready.countDown();
+ synchronized (requestCache)
{
- try
- {
- tm.rollback();
- }
- catch (Exception e1)
- {
- // Treat the exception
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
+ requestCache.remove(this.hashCode());
}
+ }
+ /**
+ * Start the request, each same will wait till this will be finished
+ */
+ void start()
+ {
+ synchronized (requestCache)
+ {
+ requestCache.put(this.hashCode(), this);
+ }
}
- return data;
+
+ /**
+ * Find the same, and if found wait till the one will be finished.
+ *
+ * WARNING. This method effective with cache use only!!! Without cache the database will control
+ * requests performance/chaching process.
+ *
+ * @return this data request
+ */
+ DataRequest waitSame()
+ {
+ DataRequest prev = null;
+ synchronized (requestCache)
+ {
+ prev = requestCache.get(this.hashCode());
+ }
+ if (prev != null)
+ prev.await();
+ return this;
+ }
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2009-12-24 15:38:31 UTC (rev 1170)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2009-12-24 15:52:07 UTC (rev 1171)
@@ -137,146 +137,6 @@
protected boolean txStarted = false;
/**
- * Node order comparator for getChildNodes().
- */
- class NodesOrderComparator<N extends NodeData> implements Comparator<NodeData>
- {
-
- /**
- * {@inheritDoc}
- */
- public int compare(NodeData n1, NodeData n2)
- {
- return n1.getOrderNumber() - n2.getOrderNumber();
- }
- }
-
- class ChildItemsIterator<T extends ItemData> implements Iterator<T>
- {
-
- final Iterator<Object> childs;
-
- final String parentId;
-
- final Fqn<String> root;
-
- T next;
-
- ChildItemsIterator(Fqn<String> root, String parentId)
- {
- this.parentId = parentId;
- this.root = root;
-
- Fqn<String> parentFqn = makeChildListFqn(root, parentId);
- // TODO replace getNode with get attr -> use ITEMS with CHILDS etc
- Node<Serializable, Object> parent = cache.getNode(parentFqn);
- if (parent != null)
- {
- this.childs = cache.getChildrenNames(parentFqn).iterator();
- fetchNext();
- }
- else
- {
- this.childs = null;
- this.next = null;
- }
- }
-
- protected void fetchNext()
- {
- if (childs.hasNext())
- {
- // traverse to the first existing or the end of childs
- T n = null;
- do
- {
- String itemId = (String)cache.get(makeChildListFqn(root, parentId, (String)childs.next()), ITEM_ID);
- if (itemId != null)
- {
- n = (T)cache.get(makeItemFqn(itemId), ITEM_DATA);
- }
- }
- while (n == null && childs.hasNext());
- next = n;
- }
- else
- {
- next = null;
- }
- }
-
- public boolean hasNext()
- {
- return next != null;
- }
-
- public T next()
- {
- if (next == null)
- {
- throw new NoSuchElementException();
- }
-
- final T current = next;
- fetchNext();
- return current;
- }
-
- public void remove()
- {
- throw new IllegalArgumentException("Not implemented");
- }
- }
-
- class ChildNodesIterator<N extends NodeData> extends ChildItemsIterator<N>
- {
-
- ChildNodesIterator(String parentId)
- {
- super(childNodes, parentId);
- }
-
- @Override
- public N next()
- {
- return super.next();
- }
- }
-
- class ChildPropertiesIterator<P extends PropertyData> extends ChildItemsIterator<P>
- {
-
- ChildPropertiesIterator(String parentId)
- {
- super(childProps, parentId);
- }
-
- @Override
- public P next()
- {
- return super.next();
- }
- }
-
- public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig) throws RepositoryException,
- RepositoryConfigurationException
- {
- this(readJBCConfig(wsConfig));
- }
-
- protected static String readJBCConfig(final WorkspaceEntry wsConfig) throws RepositoryConfigurationException
- {
- if (wsConfig.getCache() != null)
- {
- return wsConfig.getCache().getParameterValue(JBOSSCACHE_CONFIG);
- }
- else
- {
- throw new RepositoryConfigurationException("Cache configuration not found");
- }
- }
-
- /**
* JBossCacheWorkspaceStorageCache constructor.
*
*/
@@ -344,147 +204,35 @@
}
- /**
- * {@inheritDoc}
- */
- public void put(ItemData item)
+ public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig) throws RepositoryException,
+ RepositoryConfigurationException
{
- txStart();
- try
- {
- putItem(item);
-
- txCommit();
- }
- catch (Throwable e)
- {
- txRollback();
- LOG.error("put error " + (item != null ? item.getQPath().getAsString() : item), e);
- }
+ this(readJBCConfig(wsConfig));
}
/**
* {@inheritDoc}
*/
- public void remove(ItemData item)
+ public void addChildNodes(NodeData parent, List<NodeData> childs)
{
- txStart();
- try
- {
- removeItem(item);
- txCommit();
- }
- catch (Throwable e)
- {
- txRollback();
- LOG.error("remove error " + (item != null ? item.getQPath().getAsString() : item), e);
- }
- }
+ // remove previous all (to be sure about consistency)
+ cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
- /**
- * {@inheritDoc}
- */
- public void onSaveItems(final ItemStateChangesLog itemStates)
- {
- txStart();
- try
+ if (childs.size() > 0)
{
-
- ItemState prevState = null;
-
- for (ItemState state : itemStates.getAllStates())
+ // add all new
+ for (NodeData child : childs)
{
-
- if (state.isAdded())
- {
- if (state.isPersisted())
- {
- putItem(state.getData());
- }
- }
- else if (state.isUpdated())
- {
- if (state.isPersisted())
- {
- ItemData prevItem = putItem(state.getData());
- if (prevItem != null && state.isNode())
- {
- // nodes reordered, if prev is null it's InvalidItemState case
- update((NodeData)state.getData(), (NodeData)prevItem);
- }
- }
- }
- else if (state.isDeleted())
- {
- removeItem(state.getData());
- }
- else if (state.isRenamed())
- {
- // TODO cleanup: update subtree paths
- // if (prevState.isDeleted() && prevState.isNode())
- // {
- // renameNode((NodeData)prevState.getData(), (NodeData)state.getData());
- // }
- putItem(state.getData());
- }
- else if (state.isMixinChanged())
- {
- if (state.isPersisted())
- {
- // update subtree ACLs
- updateMixin((NodeData)state.getData());
- }
- }
- else
- {
- // TODO warn it?
- }
-
- prevState = state;
+ putNode(child);
}
-
- txCommit();
}
- catch (Throwable e)
+ else
{
- txRollback();
- LOG.error("onSaveItems error " + itemStates, e);
+ // cache fact of empty childs list
+ cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), NULL_DATA);
}
- }
- /**
- * {@inheritDoc}
- */
- public void addChildNodes(NodeData parent, List<NodeData> childs)
- {
- txStart();
- try
- {
- // remove previous all (to be sure about consistency)
- cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
-
- if (childs.size() > 0)
- {
- // add all new
- for (NodeData child : childs)
- {
- putNode(child);
- }
- }
- else
- {
- // cache fact of empty childs list
- cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), NULL_DATA);
- }
-
- txCommit();
- }
- catch (Throwable e)
- {
- txRollback();
- LOG.error("addChildNodes error " + (parent != null ? parent.getQPath().getAsString() : parent), e);
- }
}
/**
@@ -492,32 +240,23 @@
*/
public void addChildProperties(NodeData parent, List<PropertyData> childs)
{
- txStart();
- try
- {
- // remove previous all (to be sure about consistency)
- cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
- if (childs.size() > 0)
+ // remove previous all (to be sure about consistency)
+ cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
+
+ if (childs.size() > 0)
+ {
+ // add all new
+ for (PropertyData child : childs)
{
- // add all new
- for (PropertyData child : childs)
- {
- putProperty(child);
- }
+ putProperty(child);
}
- else
- {
- LOG.warn("Empty properties list cached " + (parent != null ? parent.getQPath().getAsString() : parent));
- }
-
- txCommit();
}
- catch (Throwable e)
+ else
{
- txRollback();
- LOG.error("addChildProperties error " + (parent != null ? parent.getQPath().getAsString() : parent), e);
+ LOG.warn("Empty properties list cached " + (parent != null ? parent.getQPath().getAsString() : parent));
}
+
}
/**
@@ -542,6 +281,14 @@
/**
* {@inheritDoc}
*/
+ public ItemData get(String id)
+ {
+ return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ItemData get(String parentId, QPathEntry name)
{
@@ -564,14 +311,6 @@
/**
* {@inheritDoc}
*/
- public ItemData get(String id)
- {
- return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
- }
-
- /**
- * {@inheritDoc}
- */
public List<NodeData> getChildNodes(final NodeData parent)
{
final List<NodeData> childs = new ArrayList<NodeData>();
@@ -612,12 +351,120 @@
/**
* {@inheritDoc}
*/
+ public long getSize()
+ {
+ // TODO
+ return -1;
+ }
+
+ /**
+ * Return TransactionManager.
+ * @return TransactionManager.
+ */
+ public TransactionManager getTransactionManager()
+ {
+ return ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ // TODO
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public List<PropertyData> listChildProperties(NodeData parent)
{
return getChildProps(parent.getIdentifier(), false);
}
/**
+ * {@inheritDoc}
+ */
+ public void onSaveItems(final ItemStateChangesLog itemStates)
+ {
+
+ ItemState prevState = null;
+
+ for (ItemState state : itemStates.getAllStates())
+ {
+
+ if (state.isAdded())
+ {
+ if (state.isPersisted())
+ {
+ putItem(state.getData());
+ }
+ }
+ else if (state.isUpdated())
+ {
+ if (state.isPersisted())
+ {
+ ItemData prevItem = putItem(state.getData());
+ if (prevItem != null && state.isNode())
+ {
+ // nodes reordered, if prev is null it's InvalidItemState case
+ update((NodeData)state.getData(), (NodeData)prevItem);
+ }
+ }
+ }
+ else if (state.isDeleted())
+ {
+ removeItem(state.getData());
+ }
+ else if (state.isRenamed())
+ {
+ // TODO cleanup: update subtree paths
+ // if (prevState.isDeleted() && prevState.isNode())
+ // {
+ // renameNode((NodeData)prevState.getData(), (NodeData)state.getData());
+ // }
+ putItem(state.getData());
+ }
+ else if (state.isMixinChanged())
+ {
+ if (state.isPersisted())
+ {
+ // update subtree ACLs
+ updateMixin((NodeData)state.getData());
+ }
+ }
+ else
+ {
+ // TODO warn it?
+ }
+
+ prevState = state;
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void put(ItemData item)
+ {
+
+ putItem(item);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void remove(ItemData item)
+ {
+
+ removeItem(item);
+
+ }
+
+ /**
* Internal get child properties.
*
* @param parentId String
@@ -656,175 +503,28 @@
}
/**
- * {@inheritDoc}
- */
- public long getSize()
- {
- // TODO
- return -1;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isEnabled()
- {
- // TODO
- return true;
- }
-
- // ****************
-
- protected void txStart()
- {
- // if (!txStarted)
- // {
- // txStarted = true;
- // //this.cache.startBatch();
- // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
- // try
- // {
- // tm.begin();
- // }
- // catch (NotSupportedException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (SystemException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // }
- }
-
- protected void txCommit()
- {
- // if (LOG.isDebugEnabled())
- // {
- // LOG.debug("commit " + txStarted);
- // }
- //
- // // end batch
- // if (txStarted)
- // {
- // //this.cache.endBatch(true);
- // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
- // try
- // {
- // tm.commit();
- // }
- // catch (SecurityException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (IllegalStateException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (RollbackException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (HeuristicMixedException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (HeuristicRollbackException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (SystemException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // txStarted = false;
- // }
- // else
- // {
- // // TODO
- // LOG.warn("Commit call without changes made.");
- // }
- }
-
- /**
- * Return TransactionManager.
- * @return TransactionManager.
- */
- public TransactionManager getTransactionManager()
- {
- return ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
- }
-
- protected void txRollback()
- {
- // if (LOG.isDebugEnabled())
- // {
- // LOG.debug("rollback " + txStarted);
- // }
- //
- // // rollback batch
- // if (txStarted)
- // {
- // //this.cache.endBatch(false);
- // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
- // try
- // {
- // tm.rollback();
- // }
- // catch (IllegalStateException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (SecurityException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (SystemException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // txStarted = false;
- // }
- // else
- // {
- // // TODO
- // LOG.warn("Rollback call without changes made.");
- // }
- }
-
- /**
- * Make Item absolute Fqn, i.e. /$ITEMS/itemID.
+ * Make child Item absolute Fqn, i.e. /root/parentId/childName.
*
- * @param itemId String
+ * @param root Fqn
+ * @param parentId String
+ * @param childName QPathEntry
* @return Fqn
*/
- protected Fqn<String> makeItemFqn(String itemId)
+ protected Fqn<String> makeChildFqn(Fqn<String> root, String parentId, QPathEntry childName)
{
- return Fqn.fromRelativeElements(itemsRoot, itemId);
+ return Fqn.fromRelativeElements(root, parentId, childName.getAsString(true));
}
/**
- * Make child Item absolute Fqn, i.e. /root/parentId/childName.
+ * Make child node parent absolute Fqn, i.e. /root/itemId.
*
* @param root Fqn
* @param parentId String
- * @param childName QPathEntry
* @return Fqn
*/
- protected Fqn<String> makeChildFqn(Fqn<String> root, String parentId, QPathEntry childName)
+ protected Fqn<String> makeChildListFqn(Fqn<String> root, String parentId)
{
- return Fqn.fromRelativeElements(root, parentId, childName.getAsString(true));
+ return Fqn.fromRelativeElements(root, parentId);
}
/**
@@ -841,17 +541,18 @@
}
/**
- * Make child node parent absolute Fqn, i.e. /root/itemId.
+ * Make Item absolute Fqn, i.e. /$ITEMS/itemID.
*
- * @param root Fqn
- * @param parentId String
+ * @param itemId String
* @return Fqn
*/
- protected Fqn<String> makeChildListFqn(Fqn<String> root, String parentId)
+ protected Fqn<String> makeItemFqn(String itemId)
{
- return Fqn.fromRelativeElements(root, parentId);
+ return Fqn.fromRelativeElements(itemsRoot, itemId);
}
+ // ****************
+
/**
* Internal put Item.
*
@@ -995,28 +696,6 @@
}
/**
- * Update Node's mixin and ACL.
- *
- * @param node NodeData
- */
- protected void updateMixin(NodeData node)
- {
- NodeData prevData = (NodeData)cache.put(makeItemFqn(node.getIdentifier()), ITEM_DATA, node);
- if (prevData != null)
- {
- // do update ACL if needed
- if (!prevData.getACL().equals(node.getACL()))
- {
- updateChildsACL(node.getIdentifier(), node.getACL());
- }
- }
- else if (LOG.isDebugEnabled())
- {
- LOG.debug("Previous NodeData not found for mixin update " + node.getQPath().getAsString());
- }
- }
-
- /**
* Update Node hierachy in case of same-name siblings reorder.
* Assumes the new (updated) nodes already putted in the cache. Previous name of updated nodes will be calculated
* and that node will be deleted (if has same id as the new node). Childs paths will be updated to a new node path.
@@ -1049,6 +728,63 @@
}
/**
+ * Update child Nodes ACLs.
+ *
+ * @param parentId String - root node id of JCR subtree.
+ * @param acl AccessControlList
+ */
+ protected void updateChildsACL(final String parentId, final AccessControlList acl)
+ {
+ for (Iterator<NodeData> iter = new ChildNodesIterator<NodeData>(parentId); iter.hasNext();)
+ {
+ NodeData prevNode = iter.next();
+
+ // is ACL changes on this node (i.e. ACL inheritance brokes)
+ for (InternalQName mixin : prevNode.getMixinTypeNames())
+ {
+ if (mixin.equals(Constants.EXO_PRIVILEGEABLE) || mixin.equals(Constants.EXO_OWNEABLE))
+ {
+ continue;
+ }
+ }
+
+ // recreate with new path for child Nodes only
+ TransientNodeData newNode =
+ new TransientNodeData(prevNode.getQPath(), prevNode.getIdentifier(), prevNode.getPersistedVersion(),
+ prevNode.getPrimaryTypeName(), prevNode.getMixinTypeNames(), prevNode.getOrderNumber(), prevNode
+ .getParentIdentifier(), acl);
+
+ // update this node
+ cache.put(makeItemFqn(newNode.getIdentifier()), ITEM_DATA, newNode);
+
+ // update childs recursive
+ updateChildsACL(newNode.getIdentifier(), acl);
+ }
+ }
+
+ /**
+ * Update Node's mixin and ACL.
+ *
+ * @param node NodeData
+ */
+ protected void updateMixin(NodeData node)
+ {
+ NodeData prevData = (NodeData)cache.put(makeItemFqn(node.getIdentifier()), ITEM_DATA, node);
+ if (prevData != null)
+ {
+ // do update ACL if needed
+ if (!prevData.getACL().equals(node.getACL()))
+ {
+ updateChildsACL(node.getIdentifier(), node.getACL());
+ }
+ }
+ else if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Previous NodeData not found for mixin update " + node.getQPath().getAsString());
+ }
+ }
+
+ /**
* Update Nodes tree with new path.
*
* @param parentId String - root node id of JCR subtree.
@@ -1107,39 +843,138 @@
}
}
- /**
- * Update child Nodes ACLs.
- *
- * @param parentId String - root node id of JCR subtree.
- * @param acl AccessControlList
- */
- protected void updateChildsACL(final String parentId, final AccessControlList acl)
+ class ChildItemsIterator<T extends ItemData> implements Iterator<T>
{
- for (Iterator<NodeData> iter = new ChildNodesIterator<NodeData>(parentId); iter.hasNext();)
+
+ final Iterator<Object> childs;
+
+ final String parentId;
+
+ final Fqn<String> root;
+
+ T next;
+
+ ChildItemsIterator(Fqn<String> root, String parentId)
{
- NodeData prevNode = iter.next();
+ this.parentId = parentId;
+ this.root = root;
- // is ACL changes on this node (i.e. ACL inheritance brokes)
- for (InternalQName mixin : prevNode.getMixinTypeNames())
+ Fqn<String> parentFqn = makeChildListFqn(root, parentId);
+ // TODO replace getNode with get attr -> use ITEMS with CHILDS etc
+ Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ if (parent != null)
{
- if (mixin.equals(Constants.EXO_PRIVILEGEABLE) || mixin.equals(Constants.EXO_OWNEABLE))
+ this.childs = cache.getChildrenNames(parentFqn).iterator();
+ fetchNext();
+ }
+ else
+ {
+ this.childs = null;
+ this.next = null;
+ }
+ }
+
+ public boolean hasNext()
+ {
+ return next != null;
+ }
+
+ public T next()
+ {
+ if (next == null)
+ {
+ throw new NoSuchElementException();
+ }
+
+ final T current = next;
+ fetchNext();
+ return current;
+ }
+
+ public void remove()
+ {
+ throw new IllegalArgumentException("Not implemented");
+ }
+
+ protected void fetchNext()
+ {
+ if (childs.hasNext())
+ {
+ // traverse to the first existing or the end of childs
+ T n = null;
+ do
{
- continue;
+ String itemId = (String)cache.get(makeChildListFqn(root, parentId, (String)childs.next()), ITEM_ID);
+ if (itemId != null)
+ {
+ n = (T)cache.get(makeItemFqn(itemId), ITEM_DATA);
+ }
}
+ while (n == null && childs.hasNext());
+ next = n;
}
+ else
+ {
+ next = null;
+ }
+ }
+ }
- // recreate with new path for child Nodes only
- TransientNodeData newNode =
- new TransientNodeData(prevNode.getQPath(), prevNode.getIdentifier(), prevNode.getPersistedVersion(),
- prevNode.getPrimaryTypeName(), prevNode.getMixinTypeNames(), prevNode.getOrderNumber(), prevNode
- .getParentIdentifier(), acl);
+ class ChildNodesIterator<N extends NodeData> extends ChildItemsIterator<N>
+ {
- // update this node
- cache.put(makeItemFqn(newNode.getIdentifier()), ITEM_DATA, newNode);
+ ChildNodesIterator(String parentId)
+ {
+ super(childNodes, parentId);
+ }
- // update childs recursive
- updateChildsACL(newNode.getIdentifier(), acl);
+ @Override
+ public N next()
+ {
+ return super.next();
}
}
+ class ChildPropertiesIterator<P extends PropertyData> extends ChildItemsIterator<P>
+ {
+
+ ChildPropertiesIterator(String parentId)
+ {
+ super(childProps, parentId);
+ }
+
+ @Override
+ public P next()
+ {
+ return super.next();
+ }
+ }
+
+ /**
+ * Node order comparator for getChildNodes().
+ */
+ class NodesOrderComparator<N extends NodeData> implements Comparator<NodeData>
+ {
+
+ /**
+ * {@inheritDoc}
+ */
+ public int compare(NodeData n1, NodeData n2)
+ {
+ return n1.getOrderNumber() - n2.getOrderNumber();
+ }
+ }
+
+ protected static String readJBCConfig(final WorkspaceEntry wsConfig) throws RepositoryConfigurationException
+ {
+ if (wsConfig.getCache() != null)
+ {
+ return wsConfig.getCache().getParameterValue(JBOSSCACHE_CONFIG);
+ }
+ else
+ {
+ throw new RepositoryConfigurationException("Cache configuration not found");
+ }
+ }
+
}
16 years, 7 months
exo-jcr SVN: r1170 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-24 10:38:31 -0500 (Thu, 24 Dec 2009)
New Revision: 1170
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
Log:
EXOJCR-327: JbossCacheIndexInfos extended to handle Transactions and transaction manager.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java 2009-12-24 15:16:11 UTC (rev 1169)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java 2009-12-24 15:38:31 UTC (rev 1170)
@@ -23,6 +23,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeModified;
@@ -32,6 +33,10 @@
import java.io.Serializable;
import java.util.Set;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+
/**
* List of indexes is stored in FS and all operations with it are wrapped by IndexInfos class. In
* standalone mode index and so the list of indexes are managed by indexer and can't be changed
@@ -56,7 +61,7 @@
private static final String SYSINDEX_NAMES = "$sysNames".intern();
- private static final String LIST_KEY = "$list".intern();
+ private static final String LIST_KEY = "$listOfIndexes".intern();
private final Cache<Serializable, Object> cache;
@@ -109,7 +114,7 @@
{
if (this.ioMode != ioMode)
{
- log.info("New IoMode:"+ioMode);
+ log.info("New IoMode:" + ioMode);
super.setIoMode(ioMode);
if (ioMode == IndexerIoMode.READ_WRITE)
{
@@ -139,7 +144,41 @@
// write to FS
super.write();
// write to cache
- cache.put(namesFqn, LIST_KEY, getNames());
+ // cache.put(namesFqn, LIST_KEY, getNames());
+ // get transaction manager
+ TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ try
+ {
+ // if any active transaction, use it
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(namesFqn, LIST_KEY, getNames());
+ }
+ else
+ {
+ // no active transaction, creating new one
+ tm.begin();
+ cache.put(namesFqn, LIST_KEY, getNames());
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ log.error(e.getMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ log.error(e.getMessage(), e.getCause());
+ }
+ }
}
}
16 years, 7 months
exo-jcr SVN: r1169 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-24 10:16:11 -0500 (Thu, 24 Dec 2009)
New Revision: 1169
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
Log:
EXOJCR-327: JbossCacheChangesFilter extended to handle Transactions and transaction manager.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-24 15:12:17 UTC (rev 1168)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-24 15:16:11 UTC (rev 1169)
@@ -26,6 +26,7 @@
import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.JBossCacheWorkspaceStorageCache;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -43,6 +44,9 @@
import java.util.Set;
import javax.jcr.RepositoryException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
/**
* @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
@@ -120,16 +124,14 @@
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
//parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
- //parentHandler.setIndexInfos(new IndexInfos());
- parentHandler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
+ //parentHandler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
parentHandler.init();
}
if (!handler.isInitialized())
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
//handler.setIndexInfos(new JbossCacheIndexInfos(cache, false, ioMode));
- //handler.setIndexInfos(new IndexInfos());
- handler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
+ //handler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
handler.init();
}
@@ -143,8 +145,43 @@
Set<String> parentAddedNodes)
{
String id = IdGenerator.generate();
- cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes,
- parentRemovedNodes));
+ // get TransactionManager
+ TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ try
+ {
+ // if any active transaction, use it
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes,
+ parentRemovedNodes));
+ }
+ else
+ {
+ // no active transaction, creating new one
+ tm.begin();
+ cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes,
+ parentRemovedNodes));
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ log.error(e.getMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ log.error(e.getMessage(), e.getCause());
+ }
+ }
+
}
}
16 years, 7 months
exo-jcr SVN: r1168 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-24 10:12:17 -0500 (Thu, 24 Dec 2009)
New Revision: 1168
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml
Log:
EXOJCR-334 : update pom version
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml 2009-12-24 15:12:02 UTC (rev 1167)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml 2009-12-24 15:12:17 UTC (rev 1168)
@@ -143,20 +143,17 @@
</dependency>
<dependency>
<groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
+ <artifactId>commons-collections</artifactId>
</dependency>
<dependency>
- <groupId>jboss.jbossts</groupId>
- <artifactId>jbossjts</artifactId>
- <version>4.6.1.GA</version>
-</dependency>
-<dependency>
- <groupId>jboss.jbossts</groupId>
- <artifactId>jbossts-common</artifactId>
- <version>4.6.1.GA</version>
-</dependency>
-
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossjts</artifactId>
+ </dependency>
<dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossts-common</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.ws.commons</groupId>
<artifactId>ws-commons-util</artifactId>
<exclusions>
16 years, 7 months
exo-jcr SVN: r1167 - jcr/branches/1.12.0-JBCCACHE.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-24 10:12:02 -0500 (Thu, 24 Dec 2009)
New Revision: 1167
Modified:
jcr/branches/1.12.0-JBCCACHE/pom.xml
Log:
EXOJCR-334 : update pom version
Modified: jcr/branches/1.12.0-JBCCACHE/pom.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/pom.xml 2009-12-24 14:56:17 UTC (rev 1166)
+++ jcr/branches/1.12.0-JBCCACHE/pom.xml 2009-12-24 15:12:02 UTC (rev 1167)
@@ -356,7 +356,18 @@
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
<version>3.2.0.GA</version>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossjts</artifactId>
+ <version>4.6.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossts-common</artifactId>
+ <version>4.6.1.GA</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
16 years, 7 months
exo-jcr SVN: r1166 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: dataflow and 1 other directory.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-12-24 09:56:17 -0500 (Thu, 24 Dec 2009)
New Revision: 1166
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/FrozenNodeInitializer.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
Log:
EOXJCR-333 apply workaround for FrozenNodeInitializer in TransientValueData (from JBC), should be fixed by OPT merge
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/FrozenNodeInitializer.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/FrozenNodeInitializer.java 2009-12-24 14:42:15 UTC (rev 1165)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/FrozenNodeInitializer.java 2009-12-24 14:56:17 UTC (rev 1166)
@@ -104,7 +104,11 @@
List<ValueData> values = new ArrayList<ValueData>();
for (ValueData valueData : property.getValues())
{
- values.add(((TransientValueData)valueData).createTransientCopy());
+ // values.add(((TransientValueData)valueData).createTransientCopy());
+
+ // TODO workaround for JBC branch, issued by the FileRestoreTest
+ TransientValueData tvd = (TransientValueData)valueData;
+ values.add(tvd.createTransientCopy1());
}
boolean mv = property.isMultiValued();
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java 2009-12-24 14:42:15 UTC (rev 1165)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java 2009-12-24 14:56:17 UTC (rev 1166)
@@ -426,6 +426,37 @@
return this;
}
}
+
+ /**
+ * Create TransientCopy of data.
+ *
+ * TODO workaround for JBC branch, issued by the FileRestoreTest.
+ *
+ * @return TransientValueData
+ * @throws RepositoryException
+ */
+ public TransientValueData createTransientCopy1() throws RepositoryException
+ {
+ try
+ {
+ if (isByteArray())
+ {
+ // bytes based
+ return new TransientValueData(orderNumber, data, null, null, fileCleaner, maxBufferSize, tempDirectory,
+ deleteSpoolFile);
+ }
+ else
+ {
+ // stream (or file) based , i.e. shared across sessions
+ return new TransientValueData(orderNumber, null, getAsStream(), null, fileCleaner, maxBufferSize,
+ tempDirectory, true);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
/**
* Create editable ValueData copy.
16 years, 7 months
exo-jcr SVN: r1165 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core: src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent and 2 other directories.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-24 09:42:15 -0500 (Thu, 24 Dec 2009)
New Revision: 1165
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
Log:
EXOJCR-334 : added support of transactions
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml 2009-12-24 12:52:48 UTC (rev 1164)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml 2009-12-24 14:42:15 UTC (rev 1165)
@@ -146,6 +146,17 @@
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossjts</artifactId>
+ <version>4.6.1.GA</version>
+</dependency>
+<dependency>
+ <groupId>jboss.jbossts</groupId>
+ <artifactId>jbossts-common</artifactId>
+ <version>4.6.1.GA</version>
+</dependency>
+
+ <dependency>
<groupId>org.apache.ws.commons</groupId>
<artifactId>ws-commons-util</artifactId>
<exclusions>
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24 12:52:48 UTC (rev 1164)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24 14:42:15 UTC (rev 1165)
@@ -18,11 +18,13 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent;
+import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
import org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache;
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.QPathEntry;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.JBossCacheWorkspaceStorageCache;
import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
@@ -32,6 +34,9 @@
import java.util.concurrent.CountDownLatch;
import javax.jcr.RepositoryException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
/**
* Created by The eXo Platform SAS.
@@ -301,6 +306,54 @@
}
/**
+ * @see org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#save(org.exoplatform.services.jcr.dataflow.ItemStateChangesLog)
+ */
+ @Override
+ public void save(ItemStateChangesLog changesLog) throws RepositoryException
+ {
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ tm.begin();
+ super.save(changesLog);
+ tm.commit();
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (RepositoryException e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ throw e;
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+
+ }
+
+ /**
* {@inheritDoc}
*/
public List<NodeData> getChildNodesData(NodeData nodeData) throws RepositoryException
@@ -364,7 +417,39 @@
if (parentData != null)
{
- cache.addChildNodes(parentData, childNodes);
+
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildNodes(parentData, childNodes);
+ }
+ else
+ {
+ tm.begin();
+ cache.addChildNodes(parentData, childNodes);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
return childNodes;
@@ -431,7 +516,38 @@
if (parentData != null)
{
- cache.addChildProperties(parentData, childProperties);
+
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildProperties(parentData, childProperties);
+ }
+ else
+ {
+ tm.begin();
+ cache.addChildProperties(parentData, childProperties);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
return childProperties;
@@ -480,7 +596,39 @@
if (parentData != null)
{
- cache.addChildPropertiesList(parentData, propertiesList);
+
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildPropertiesList(parentData, propertiesList);
+ }
+ else
+ {
+ tm.begin();
+ cache.addChildPropertiesList(parentData, propertiesList);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
}
return propertiesList;
@@ -539,7 +687,38 @@
data = super.getItemData(parentData, name);
if (data != null && cache.isEnabled())
{
- cache.put(data);
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(data);
+ }
+ else
+ {
+ tm.begin();
+ cache.put(data);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
}
return data;
}
@@ -571,7 +750,40 @@
ItemData data = super.getItemData(identifier);
if (data != null && cache.isEnabled())
{
- cache.put(data);
+
+ TransactionManager tm = ((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+
+ try
+ {
+ if (tm.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(data);
+ }
+ else
+ {
+ tm.begin();
+ cache.put(data);
+ tm.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+
}
return data;
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2009-12-24 12:52:48 UTC (rev 1164)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2009-12-24 14:42:15 UTC (rev 1165)
@@ -37,6 +37,7 @@
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -52,6 +53,8 @@
import java.util.Set;
import javax.jcr.RepositoryException;
+import javax.transaction.RollbackException;
+import javax.transaction.TransactionManager;
/**
* Created by The eXo Platform SAS.<p/>
@@ -292,9 +295,12 @@
// TODO transaction
// prepare cache structures
- txStart();
+
+ TransactionManager tm = getTransactionManager();
+
try
{
+ tm.begin();
this.itemsRoot = Fqn.fromElements(ITEMS);
cacheRoot.addChild(this.itemsRoot).setResident(true);
@@ -315,14 +321,27 @@
// TODO apply locks
//this.locks = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.LOCKS));
-
- txCommit();
+ tm.commit();
}
- catch (Throwable e)
+ catch (RollbackException e)
{
- txRollback();
- throw new RepositoryException("Cannot preare cache", e);
+ // Indicate that the transaction has been rolled back rather than committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
+ catch (Exception e)
+ {
+ try
+ {
+ tm.rollback();
+ throw new RepositoryException("Cannot preare cache", e);
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+
}
/**
@@ -658,51 +677,130 @@
protected void txStart()
{
- if (!txStarted)
- {
- txStarted = true;
- this.cache.startBatch();
- }
+ // if (!txStarted)
+ // {
+ // txStarted = true;
+ // //this.cache.startBatch();
+ // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ // try
+ // {
+ // tm.begin();
+ // }
+ // catch (NotSupportedException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (SystemException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // }
}
protected void txCommit()
{
- if (LOG.isDebugEnabled())
- {
- LOG.debug("commit " + txStarted);
- }
+ // if (LOG.isDebugEnabled())
+ // {
+ // LOG.debug("commit " + txStarted);
+ // }
+ //
+ // // end batch
+ // if (txStarted)
+ // {
+ // //this.cache.endBatch(true);
+ // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ // try
+ // {
+ // tm.commit();
+ // }
+ // catch (SecurityException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (IllegalStateException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (RollbackException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (HeuristicMixedException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (HeuristicRollbackException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (SystemException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // txStarted = false;
+ // }
+ // else
+ // {
+ // // TODO
+ // LOG.warn("Commit call without changes made.");
+ // }
+ }
- // end batch
- if (txStarted)
- {
- this.cache.endBatch(true);
- txStarted = false;
- }
- else
- {
- // TODO
- LOG.warn("Commit call without changes made.");
- }
+ /**
+ * Return TransactionManager.
+ * @return TransactionManager.
+ */
+ public TransactionManager getTransactionManager()
+ {
+ return ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
}
protected void txRollback()
{
- if (LOG.isDebugEnabled())
- {
- LOG.debug("rollback " + txStarted);
- }
-
- // rollback batch
- if (txStarted)
- {
- this.cache.endBatch(false);
- txStarted = false;
- }
- else
- {
- // TODO
- LOG.warn("Rollback call without changes made.");
- }
+ // if (LOG.isDebugEnabled())
+ // {
+ // LOG.debug("rollback " + txStarted);
+ // }
+ //
+ // // rollback batch
+ // if (txStarted)
+ // {
+ // //this.cache.endBatch(false);
+ // TransactionManager tm = ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
+ // try
+ // {
+ // tm.rollback();
+ // }
+ // catch (IllegalStateException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (SecurityException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // catch (SystemException e)
+ // {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // txStarted = false;
+ // }
+ // else
+ // {
+ // // TODO
+ // LOG.warn("Rollback call without changes made.");
+ // }
}
/**
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml 2009-12-24 12:52:48 UTC (rev 1164)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-config.xml 2009-12-24 14:42:15 UTC (rev 1165)
@@ -3,7 +3,7 @@
xmlns="urn:jboss:jbosscache-core:config:3.1">
<!-- Configure the TransactionManager -->
- <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup" />
+ <transaction transactionManagerLookupClass="org.jboss.cache.transaction.JBossStandaloneJTAManagerLookup" />
<!-- Enable batching -->
<invocationBatching enabled="true"/>
16 years, 7 months
exo-jcr SVN: r1164 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query: lucene and 1 other directory.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-24 07:52:48 -0500 (Thu, 24 Dec 2009)
New Revision: 1164
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java
Log:
EXOJCR-327: Updated indexInfos: removed method exists and added check on read(). Updated JbossCacheIndexInfos
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java 2009-12-24 12:42:02 UTC (rev 1163)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java 2009-12-24 12:52:48 UTC (rev 1164)
@@ -33,6 +33,15 @@
import java.util.Set;
/**
+ * List of indexes is stored in FS and all operations with it are wrapped by IndexInfos class. In
+ * standalone mode index and so the list of indexes are managed by indexer and can't be changed
+ * externally.
+ * But in cluster environment all JCR Indexers are reading from shared file system and only one
+ * cluster node is writing this index. So read-only cluster nodes should be notified when content
+ * of index (actually list of index segments) is changed.
+ * This class is responsible for storing list of segments (indexes) in distributed JBoss Cache
+ * instance.
+ *
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
* @version $Id: JbossCacheIndexInfos.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
*
@@ -47,7 +56,7 @@
private static final String SYSINDEX_NAMES = "$sysNames".intern();
- private static final String LIST = "$list".intern();
+ private static final String LIST_KEY = "$list".intern();
private final Cache<Serializable, Object> cache;
@@ -82,60 +91,25 @@
{
super(fileName);
this.cache = cache;
+ // store parsed FQN to avoid it's parsing each time cache event is generated
namesFqn = Fqn.fromString(system ? SYSINDEX_NAMES : INDEX_NAMES);
if (ioMode == IndexerIoMode.READ_ONLY)
{
// Currently READ_ONLY is set, so new lists should be fired to multiIndex.
cache.addCacheListener(this);
}
+ log.info("/!\\ created jboss cache index infos");
}
/**
- * CacheListener method, that accepts event, when cache node changed. This class is registered as cache listener,
- * only in READ_ONLY mode.
- * @param event
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#setIoMode(org.exoplatform.services.jcr.impl.core.query.IndexerIoMode)
*/
- @NodeModified
- public void cacheNodeModified(NodeModifiedEvent event)
- {
- if (!event.isPre() && event.equals(namesFqn))
- {
- // update lists
- setNames((Set<String>)cache.get(namesFqn, LIST));
- // callback multiIndex to refresh lists
- try
- {
- getMultiIndex().refreshIndexList();
- }
- catch (IOException e)
- {
- log.error("Failed to update indexes! " + e.getMessage(), e);
- }
- }
- }
-
- /**
- * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#getIoMode()
- */
- public IndexerIoMode getIoMode()
- {
- return ioMode;
- }
-
- /**
- * Returns true if this {@link IndexInfos} corresponds to SystemSearchManager
- * @return
- */
- public boolean isSystem()
- {
- return system;
- }
-
@Override
public void setIoMode(IndexerIoMode ioMode) throws IOException
{
if (this.ioMode != ioMode)
{
+ log.info("New IoMode:"+ioMode);
super.setIoMode(ioMode);
if (ioMode == IndexerIoMode.READ_WRITE)
{
@@ -143,7 +117,7 @@
// Remove listener to avoid asserting if ioMode is RO on each cache event
cache.removeCacheListener(this);
// re-read from FS current actual list.
- refresh();
+ super.read();
}
else
{
@@ -159,14 +133,41 @@
@Override
public void write() throws IOException
{
- boolean dirty = isDirty();
- // write to FS
- super.write();
- // write to cache
- if (dirty)
+ // if READ_WRITE and is dirty, then flush.
+ if (isDirty() && ioMode == IndexerIoMode.READ_WRITE)
{
- // send to cache new list.
+ // write to FS
+ super.write();
+ // write to cache
+ cache.put(namesFqn, LIST_KEY, getNames());
}
}
+ /**
+ * CacheListener method, that accepts event, when cache node changed. This class is registered as cache listener,
+ * only in READ_ONLY mode.
+ * @param event
+ */
+ @NodeModified
+ public void cacheNodeModified(NodeModifiedEvent event)
+ {
+ if (!event.isPre() && event.getFqn().equals(namesFqn))
+ {
+ // read from cache to update lists
+ Set<String> set = (Set<String>)cache.get(namesFqn, LIST_KEY);
+ if (set != null)
+ {
+ setNames(set);
+ // callback multiIndex to refresh lists
+ try
+ {
+ getMultiIndex().refreshIndexList();
+ }
+ catch (IOException e)
+ {
+ log.error("Failed to update indexes! " + e.getMessage(), e);
+ }
+ }
+ }
+ }
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java 2009-12-24 12:42:02 UTC (rev 1163)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java 2009-12-24 12:52:48 UTC (rev 1164)
@@ -96,19 +96,6 @@
}
/**
- * Returns <code>true</code> if this index infos exists in
- * <code>dir</code>.
- *
- * @param dir the directory where to look for the index infos.
- * @return <code>true</code> if it exists; <code>false</code> otherwise.
- * @throws IOException if an error occurs while reading from the directory.
- */
- public boolean exists() throws IOException
- {
- return dir.fileExists(name);
- }
-
- /**
* Returns the name of the file where infos are stored.
*
* @return the name of the file where infos are stored.
@@ -119,47 +106,38 @@
}
/**
- * Reads the index infos.
+ * Reads the index infos. Before reading it checks if file exists
*
* @param dir the directory from where to read the index infos.
* @throws IOException if an error occurs.
*/
public void read() throws IOException
{
- // clear current lists
- InputStream in = new IndexInputStream(dir.openInput(name));
- try
+ names.clear();
+ indexes.clear();
+ if (dir.fileExists(name))
{
- DataInputStream di = new DataInputStream(in);
- counter = di.readInt();
- for (int i = di.readInt(); i > 0; i--)
+ // clear current lists
+ InputStream in = new IndexInputStream(dir.openInput(name));
+ try
{
- String indexName = di.readUTF();
- indexes.add(indexName);
- names.add(indexName);
+ DataInputStream di = new DataInputStream(in);
+ counter = di.readInt();
+ for (int i = di.readInt(); i > 0; i--)
+ {
+ String indexName = di.readUTF();
+ indexes.add(indexName);
+ names.add(indexName);
+ }
}
+ finally
+ {
+ in.close();
+ }
}
- finally
- {
- in.close();
- }
}
/**
- * re-reads list of indexes from FS
- * @throws IOException
- */
- public void refresh() throws IOException
- {
- names.clear();
- indexes.clear();
- if (exists())
- {
- read();
- }
- }
-
- /**
* Writes the index infos to disk if they are dirty.
*
* @param dir the directory where to write the index infos.
@@ -305,16 +283,9 @@
}
/**
- * Returns current mode.
- * @return
- */
- public IndexerIoMode getIoMode()
- {
- return IndexerIoMode.READ_WRITE;
- }
-
- /**
- * Sets new names, clearing existing.
+ * Sets new names, clearing existing. It is thought to be used when list of indexes can
+ * be externally changed.
+ *
* @param names
*/
protected void setNames(Set<String> names)
16 years, 7 months