exo-jcr SVN: r1163 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-12-24 07:42:02 -0500 (Thu, 24 Dec 2009)
New Revision: 1163
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml
Log:
EOXJCR-325 exclusion on SysView tests (to check how Hudson will build it)
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 10:57:11 UTC (rev 1162)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/pom.xml 2009-12-24 12:42:02 UTC (rev 1163)
@@ -352,6 +352,8 @@
<exclude>org/exoplatform/services/jcr/**/api/**/TestVersionRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestSessionDataManager.java</exclude>
+
+ <exclude>org/exoplatform/services/jcr/**/usecases/**/ExportWorkspaceSystemViewTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -540,6 +542,7 @@
<configuration>
<phase>test</phase>
<forkMode>${exo.test.forkMode}</forkMode>
+ <argLine>${env.MAVEN_OPTS}</argLine>
<goals>
<goal>test</goal>
</goals>
@@ -550,14 +553,13 @@
</property>
</systemProperties>
<includes>
- <include>**/**/TestErrorMultithreading__.java</include>
- <include>**/**/TestConcurrentItems__.java</include>
-
+ <include>**/**/reading_/Test*.java</include>
+ <include>**/**/writing_/Test*.java</include>
+
<include>**/**/TestJBossCacheWorkspaceStorageCache_.java</include>
- <include>**/**/TestSVNodeDataOptimization.java</include>
+ <include>**/**/TestSVNodeDataOptimization_.java</include>
- <include>**/**/reading_/Test*.java</include>
- <include>**/**/writing_/Test*.java</include>
+ <include>**/**/ExportWorkspaceSystemViewTest.java</include>
</includes>
</configuration>
</plugin>
16 years, 7 months
exo-jcr SVN: r1162 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-24 05:57:11 -0500 (Thu, 24 Dec 2009)
New Revision: 1162
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
Log:
EXOJCR-325: Added default constructor to PersistedNodeData with empty ACL.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-12-24 10:46:32 UTC (rev 1161)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-12-24 10:57:11 UTC (rev 1162)
@@ -60,6 +60,12 @@
protected InternalQName[] mixinTypeNames;
protected AccessControlList acl;
+
+ public PersistedNodeData()
+ {
+ super();
+ this.acl = new AccessControlList();
+ }
public PersistedNodeData(String id, QPath qpath, String parentId, int version, int orderNumber,
InternalQName primaryTypeName, InternalQName[] mixinTypeNames, AccessControlList acl)
16 years, 7 months
exo-jcr SVN: r1161 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-24 05:46:32 -0500 (Thu, 24 Dec 2009)
New Revision: 1161
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-327: Fixed multiIndex to set itself to IndexInfos in constructor.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-24 10:41:54 UTC (rev 1160)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-24 10:46:32 UTC (rev 1161)
@@ -241,10 +241,8 @@
this.flushTask = null;
this.indexNames = indexInfos;
this.indexNames.setDirectory(indexDir);
- if (indexNames.exists())
- {
- indexNames.read();
- }
+ this.indexNames.setMultiIndex(this);
+ this.indexNames.read();
// as of 1.5 deletable file is not used anymore
removeDeletable();
@@ -2448,10 +2446,7 @@
IndexInfos newIndexNames = new IndexInfos();
newIndexNames.setMultiIndex(this);
newIndexNames.setDirectory(indexDir);
- if (newIndexNames.exists())
- {
- newIndexNames.read();
- }
+ newIndexNames.read();
// prepare added/removed sets
Set<String> removed = new HashSet<String>(indexNames.getNames());
removed.removeAll(newIndexNames.getNames());
@@ -2510,6 +2505,8 @@
// prepare added/removed sets
Set<String> newList = new HashSet<String>(indexNames.getNames());
+ log.info("GOT NEW LIST: "+newList);
+
// remove removed indexes
Iterator<PersistentIndex> iterator = indexes.iterator();
while (iterator.hasNext())
16 years, 7 months
exo-jcr SVN: r1160 - core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2009-12-24 05:41:54 -0500 (Thu, 24 Dec 2009)
New Revision: 1160
Modified:
core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/Identity.java
core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/MembershipEntry.java
Log:
EXOJCR-345: Improve the way to check if a given Identity contains a given MembershipEntry
Modified: core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/Identity.java
===================================================================
--- core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/Identity.java 2009-12-24 10:29:04 UTC (rev 1159)
+++ core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/Identity.java 2009-12-24 10:41:54 UTC (rev 1160)
@@ -44,7 +44,7 @@
/**
* Memberships.
*/
- private Collection<MembershipEntry> memberships;
+ private Set<MembershipEntry> memberships;
/**
* javax.security.auth.Subject can be used for logout process. <code>
@@ -84,7 +84,7 @@
public Identity(String userId, Collection<MembershipEntry> memberships, Collection<String> roles)
{
this.userId = userId;
- this.memberships = memberships;
+ this.memberships = new HashSet<MembershipEntry>(memberships);
this.roles = roles;
}
@@ -146,7 +146,7 @@
*/
public void setMemberships(Collection<MembershipEntry> memberships)
{
- this.memberships = memberships;
+ this.memberships = new HashSet<MembershipEntry>(memberships);
}
/**
@@ -199,12 +199,7 @@
*/
private boolean containsMembership(MembershipEntry checkMe)
{
- for (MembershipEntry membership : memberships)
- {
- if (checkMe.equals(membership))
- return true;
- }
- return false;
+ return memberships.contains(checkMe);
}
}
Modified: core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/MembershipEntry.java
===================================================================
--- core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/MembershipEntry.java 2009-12-24 10:29:04 UTC (rev 1159)
+++ core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/MembershipEntry.java 2009-12-24 10:41:54 UTC (rev 1160)
@@ -78,7 +78,9 @@
@Override
public boolean equals(Object obj)
{
- if (obj == null || !(obj instanceof MembershipEntry))
+ if (this == obj)
+ return true;
+ if (!(obj instanceof MembershipEntry))
return false;
MembershipEntry me = (MembershipEntry)obj;
if (membershipType.equals(ANY_TYPE) || me.membershipType.equals(ANY_TYPE))
@@ -86,13 +88,24 @@
return this.group.equals(me.group) && this.membershipType.equals(me.membershipType);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ return group.hashCode();
+ }
+
public static MembershipEntry parse(String identityStr)
{
- if (identityStr.indexOf(":") != -1)
+ final int index = identityStr.indexOf(":");
+ if (index != -1)
{
- String membershipName = identityStr.substring(0, identityStr.indexOf(":"));
- String groupName = identityStr.substring(identityStr.indexOf(":") + 1);
+ String membershipName = identityStr.substring(0, index);
+ String groupName = identityStr.substring(index + 1);
return new MembershipEntry(groupName, membershipName);
}
16 years, 7 months
exo-jcr SVN: r1159 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr: impl/core and 2 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2009-12-24 05:29:04 -0500 (Thu, 24 Dec 2009)
New Revision: 1159
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessControlEntry.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessManager.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionDataHolder.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
Log:
EXOJCR-344: Removal of the bottlenecks found with JProfiler
* The size of the array list is given in the constructor when it is possible
* We avoid to iterate over an iterator on a big set of data we use for (int i = 0, length = nodeDatas.size(); i < length; i++) instead of for (NodeData data : nodeDatas)
* We store the corresponding MembershipEntry of the identity of a given AccessControlEntry to avoid to call MembershipEntry.parse(ace.getIdentity()) too often
* We store the item definition in a tree of maps in ItemDefinitionDataHolder to avoid key creation to get, update or remove an entry
* We use a ConcurrentHashMap in CacheableWorkspaceDataManager to allow to start different DataRequest in parallel
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessControlEntry.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessControlEntry.java 2009-12-24 08:18:30 UTC (rev 1158)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessControlEntry.java 2009-12-24 10:29:04 UTC (rev 1159)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.access;
+import org.exoplatform.services.security.MembershipEntry;
+
/**
* Created by The eXo Platform SAS.
*
@@ -27,10 +29,12 @@
public class AccessControlEntry
{
- private String identity;
+ private final String identity;
- private String permission;
+ private final String permission;
+ private volatile MembershipEntry membership;
+
public static final String DELIMITER = " ";
public AccessControlEntry(String identity, String permission)
@@ -49,6 +53,21 @@
return permission;
}
+ public MembershipEntry getMembershipEntry()
+ {
+ if (membership == null)
+ {
+ synchronized (this)
+ {
+ if (membership == null)
+ {
+ membership = MembershipEntry.parse(getIdentity());
+ }
+ }
+ }
+ return membership;
+ }
+
public String getAsString()
{
return identity + AccessControlEntry.DELIMITER + permission;
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessManager.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessManager.java 2009-12-24 08:18:30 UTC (rev 1158)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/access/AccessManager.java 2009-12-24 10:29:04 UTC (rev 1159)
@@ -25,7 +25,6 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.security.Identity;
-import org.exoplatform.services.security.MembershipEntry;
import java.util.ArrayList;
import java.util.HashMap;
@@ -176,8 +175,9 @@
private boolean isPermissionMatch(List<AccessControlEntry> existedPermission, String testPermission, Identity user)
{
- for (AccessControlEntry ace : existedPermission)
+ for (int i = 0, length = existedPermission.size(); i < length; i++)
{
+ AccessControlEntry ace = existedPermission.get(i);
// match action
if (ace.getPermission().equals(testPermission))
{
@@ -191,7 +191,7 @@
return true;
}
- else if (user.isMemberOf(MembershipEntry.parse(ace.getIdentity())))
+ else if (user.isMemberOf(ace.getMembershipEntry()))
return true;
}
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2009-12-24 08:18:30 UTC (rev 1158)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2009-12-24 10:29:04 UTC (rev 1159)
@@ -43,7 +43,6 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.LocalWorkspaceDataManagerStub;
import org.exoplatform.services.jcr.impl.dataflow.session.SessionChangesLog;
import org.exoplatform.services.jcr.impl.dataflow.session.TransactionableDataManager;
-import org.exoplatform.services.jcr.impl.dataflow.session.WorkspaceStorageDataManagerProxy;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -522,9 +521,11 @@
*/
public List<PropertyImpl> getReferences(String identifier) throws RepositoryException
{
- List<PropertyImpl> refs = new ArrayList<PropertyImpl>();
- for (PropertyData data : transactionableManager.getReferencesData(identifier, true))
+ List<PropertyData> refDatas = transactionableManager.getReferencesData(identifier, true);
+ List<PropertyImpl> refs = new ArrayList<PropertyImpl>(refDatas.size());
+ for (int i = 0, length = refDatas.size(); i < length; i++)
{
+ PropertyData data = refDatas.get(i);
// check for permission for read
// [PN] 21.12.07 use item data
NodeData parent = (NodeData)getItemData(data.getParentIdentifier());
@@ -574,11 +575,12 @@
try
{
// merge data from changesLog with data from txManager
- List<NodeImpl> nodes = new ArrayList<NodeImpl>();
List<NodeData> nodeDatas = getChildNodesData(parent);
+ List<NodeImpl> nodes = new ArrayList<NodeImpl>(nodeDatas.size());
- for (NodeData data : nodeDatas)
+ for (int i = 0, length = nodeDatas.size(); i < length; i++)
{
+ NodeData data = nodeDatas.get(i);
NodeImpl item = itemFactory.createNode(data, parent);
session.getActionHandler().postRead(item);
@@ -625,9 +627,11 @@
try
{
- List<PropertyImpl> props = new ArrayList<PropertyImpl>();
- for (PropertyData data : getChildPropertiesData(parent))
+ List<PropertyData> propDatas = getChildPropertiesData(parent);
+ List<PropertyImpl> props = new ArrayList<PropertyImpl>(propDatas.size());
+ for (int i = 0, length = propDatas.size(); i < length; i++)
{
+ PropertyData data = propDatas.get(i);
ItemImpl item = itemFactory.createItem(data);
session.getActionHandler().postRead(item);
if (accessManager.hasPermission(parent.getACL(), new String[]{PermissionType.READ}, session.getUserState()
@@ -1537,15 +1541,25 @@
else
descendants.remove(data.getIdentifier());
}
- List<ItemData> retval = new ArrayList<ItemData>();
Collection<ItemData> desc = descendants.values();
+ List<ItemData> retval;
+ if (deep)
+ {
+ int size = desc.size();
+ retval = new ArrayList<ItemData>(size < 10 ? 10 : size);
- for (ItemData itemData : desc)
+ for (ItemData itemData : desc)
+ {
+ retval.add(itemData);
+ if (deep)
+ retval.addAll(merge(itemData, dataManager, true, action));
+ }
+ }
+ else
{
- retval.add(itemData);
- if (deep)
- retval.addAll(merge(itemData, dataManager, true, action));
+ retval = new ArrayList<ItemData>(desc);
}
+
return retval;
}
@@ -1581,14 +1595,23 @@
else
descendants.remove(data.getIdentifier());
}
- List<ItemData> retval = new ArrayList<ItemData>();
Collection<ItemData> desc = descendants.values();
+ List<ItemData> retval;
+ if (deep)
+ {
+ int size = desc.size();
+ retval = new ArrayList<ItemData>(size < 10 ? 10 : size);
- for (ItemData itemData : desc)
+ for (ItemData itemData : desc)
+ {
+ retval.add(itemData);
+ if (deep)
+ retval.addAll(mergeList(itemData, dataManager, true, action));
+ }
+ }
+ else
{
- retval.add(itemData);
- if (deep)
- retval.addAll(mergeList(itemData, dataManager, true, action));
+ retval = new ArrayList<ItemData>(desc);
}
return retval;
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionDataHolder.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionDataHolder.java 2009-12-24 08:18:30 UTC (rev 1158)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/nodetype/ItemDefinitionDataHolder.java 2009-12-24 10:29:04 UTC (rev 1159)
@@ -28,6 +28,8 @@
import org.exoplatform.services.log.Log;
import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
/**
* Created by The eXo Platform SAS. <br/>
@@ -45,22 +47,23 @@
private static Log LOG = ExoLogger.getLogger("jcr.ItemDefinitionDataHolder");
- private final HashMap<ChildNodeDefKey, NodeDefinitionData> nodeDefinitions;
+ private final Map<InternalQName, Map<InternalQName, Map<InternalQName, NodeDefinitionData>>> nodeDefinitions;
- private final HashMap<PropertyDefKey, PropertyDefinitionData> propertyDefinitions;
+ private final Map<InternalQName, Map<InternalQName, Map<Boolean, PropertyDefinitionData>>> propertyDefinitions;
- private final HashMap<DefaultNodeDefKey, NodeDefinitionData> defNodeDefinitions;
+ private final Map<InternalQName, Map<InternalQName, NodeDefinitionData>> defNodeDefinitions;
public ItemDefinitionDataHolder()
{
- this.nodeDefinitions = new HashMap<ChildNodeDefKey, NodeDefinitionData>();
- this.propertyDefinitions = new HashMap<PropertyDefKey, PropertyDefinitionData>();
- this.defNodeDefinitions = new HashMap<DefaultNodeDefKey, NodeDefinitionData>();
+ this.nodeDefinitions = new HashMap<InternalQName, Map<InternalQName, Map<InternalQName, NodeDefinitionData>>>();
+ this.propertyDefinitions = new HashMap<InternalQName, Map<InternalQName, Map<Boolean, PropertyDefinitionData>>>();
+ this.defNodeDefinitions = new HashMap<InternalQName, Map<InternalQName, NodeDefinitionData>>();
}
- private ItemDefinitionDataHolder(HashMap<ChildNodeDefKey, NodeDefinitionData> nodeDefinitions,
- HashMap<PropertyDefKey, PropertyDefinitionData> propertyDefinitions,
- HashMap<DefaultNodeDefKey, NodeDefinitionData> defNodeDefinitions)
+ private ItemDefinitionDataHolder(
+ Map<InternalQName, Map<InternalQName, Map<InternalQName, NodeDefinitionData>>> nodeDefinitions,
+ Map<InternalQName, Map<InternalQName, Map<Boolean, PropertyDefinitionData>>> propertyDefinitions,
+ Map<InternalQName, Map<InternalQName, NodeDefinitionData>> defNodeDefinitions)
{
this.nodeDefinitions = nodeDefinitions;
this.propertyDefinitions = propertyDefinitions;
@@ -92,7 +95,7 @@
for (InternalQName parentNodeType : nodeTypes)
{
- NodeDefinitionData def = defNodeDefinitions.get(new DefaultNodeDefKey(parentNodeType, childName));
+ NodeDefinitionData def = getNodeDefinitionDataInternal(parentNodeType, childName);
if (def != null)
return def;
}
@@ -100,7 +103,7 @@
// residual
for (InternalQName parentNodeType : nodeTypes)
{
- NodeDefinitionData def = defNodeDefinitions.get(new DefaultNodeDefKey(parentNodeType, Constants.JCR_ANY_NAME));
+ NodeDefinitionData def = getNodeDefinitionDataInternal(parentNodeType, Constants.JCR_ANY_NAME);
if (def != null)
return def;
}
@@ -118,13 +121,12 @@
InternalQName parentNodeType)
{
- PropertyDefKey key = new PropertyDefKey(parentNodeType, childName, multiValued);
- PropertyDefinitionData def = propertyDefinitions.get(key);
+ PropertyDefinitionData def = getPropertyDefinitionInternal(parentNodeType, childName, multiValued);
// try residual def
if (def == null)
{
- return propertyDefinitions.get(new PropertyDefKey(parentNodeType, Constants.JCR_ANY_NAME, multiValued));
+ return getPropertyDefinitionInternal(parentNodeType, Constants.JCR_ANY_NAME, multiValued);
}
return def;
@@ -145,12 +147,12 @@
for (InternalQName nt : nodeTypes)
{
// single-valued
- PropertyDefinitionData def = propertyDefinitions.get(new PropertyDefKey(nt, propertyName, false));
+ PropertyDefinitionData def = getPropertyDefinitionInternal(nt, propertyName, false);
if (def != null && pdefs.getDefinition(def.isMultiple()) == null)
pdefs.setDefinition(def); // set if same is not exists
// multi-valued
- def = propertyDefinitions.get(new PropertyDefKey(nt, propertyName, true));
+ def = getPropertyDefinitionInternal(nt, propertyName, true);
if (def != null && pdefs.getDefinition(def.isMultiple()) == null)
pdefs.setDefinition(def); // set if same is not exists
@@ -177,25 +179,21 @@
// put required node type defs
for (InternalQName rnt : nodeDef.getRequiredPrimaryTypes())
{
- ChildNodeDefKey nodeDefKey = new ChildNodeDefKey(name, nodeDef.getName(), rnt);
- nodeDefinitions.put(nodeDefKey, nodeDef);
-
+ addNodeDefinitionDataInternal(name, nodeDef.getName(), rnt, nodeDef);
if (LOG.isDebugEnabled())
{
LOG.debug("NodeDef added: parent NT: " + name.getAsString() + " child nodeName: "
- + nodeDef.getName().getAsString() + " childNT: " + rnt.getAsString() + " hash: "
- + nodeDefKey.hashCode());
+ + nodeDef.getName().getAsString() + " childNT: " + rnt.getAsString());
}
}
// put default node definition
- DefaultNodeDefKey defNodeDefKey = new DefaultNodeDefKey(name, nodeDef.getName());
- defNodeDefinitions.put(defNodeDefKey, nodeDef);
+ addNodeDefinitionDataInternal(name, nodeDef.getName(), nodeDef);
if (LOG.isDebugEnabled())
{
LOG.debug("Default NodeDef added: parent NT: " + name.getAsString() + " child nodeName: "
- + nodeDef.getName() + " hash: " + defNodeDefKey.hashCode());
+ + nodeDef.getName());
}
}
@@ -203,14 +201,12 @@
PropertyDefinitionData[] propDefs = nodeType.getDeclaredPropertyDefinitions();
for (PropertyDefinitionData propDef : propDefs)
{
- PropertyDefKey propDefKey = new PropertyDefKey(name, propDef.getName(), propDef.isMultiple());
- propertyDefinitions.put(propDefKey, propDef);
-
+ addPropertyDefinitionInternal(name, propDef.getName(), propDef.isMultiple(), propDef);
+
if (LOG.isDebugEnabled())
{
LOG.debug("PropDef added: parent NT: " + name.getAsString() + " child propName: "
- + propDef.getName().getAsString() + " isMultiple: " + propDef.isMultiple() + " hash: "
- + propDefKey.hashCode());
+ + propDef.getName().getAsString() + " isMultiple: " + propDef.isMultiple());
}
}
@@ -225,40 +221,32 @@
// remove required node type defs
for (InternalQName rnt : nodeDef.getRequiredPrimaryTypes())
{
- ChildNodeDefKey nodeDefKey = new ChildNodeDefKey(name, nodeDef.getName(), rnt);
- nodeDefinitions.remove(nodeDefKey);
-
+ removeNodeDefinitionDataInternal(name, nodeDef.getName(), rnt);
if (LOG.isDebugEnabled())
{
LOG.debug("NodeDef removed: parent NT: " + name.getAsString() + " child nodeName: "
- + nodeDef.getName().getAsString() + " childNT: " + rnt.getAsString() + " hash: "
- + nodeDefKey.hashCode());
+ + nodeDef.getName().getAsString() + " childNT: " + rnt.getAsString());
}
}
// remove default node definition
- DefaultNodeDefKey defNodeDefKey = new DefaultNodeDefKey(name, nodeDef.getName());
- defNodeDefinitions.remove(defNodeDefKey);
-
+ removeNodeDefinitionDataInternal(name, nodeDef.getName());
if (LOG.isDebugEnabled())
{
LOG.debug("Default NodeDef removed: parent NT: " + name.getAsString() + " child nodeName: "
- + nodeDef.getName() + " hash: " + defNodeDefKey.hashCode());
- }
+ + nodeDef.getName());
+ }
}
// remove defs
PropertyDefinitionData[] propDefs = nodeType.getDeclaredPropertyDefinitions();
for (PropertyDefinitionData propDef : propDefs)
{
- PropertyDefKey propDefKey = new PropertyDefKey(name, propDef.getName(), propDef.isMultiple());
- propertyDefinitions.remove(propDefKey);
-
+ removePropertyDefinitionInternal(name, propDef.getName(), propDef.isMultiple());
if (LOG.isDebugEnabled())
{
LOG.debug("PropDef remode: parent NT: " + name.getAsString() + " child propName: "
- + propDef.getName().getAsString() + " isMultiple: " + propDef.isMultiple() + " hash: "
- + propDefKey.hashCode());
+ + propDef.getName().getAsString() + " isMultiple: " + propDef.isMultiple());
}
}
}
@@ -267,299 +255,171 @@
InternalQName childName, InternalQName childNodeType)
{
- NodeDefinitionData def = nodeDefinitions.get(new ChildNodeDefKey(parentNodeType, childName, childNodeType));
+ NodeDefinitionData def = getNodeDefinitionDataInternal(parentNodeType, childName, childNodeType);
if (def != null)
return def;
return def;
}
- /**
- * Create copy of holder.
- *
- * @return
- */
- protected ItemDefinitionDataHolder createCopy()
+ private NodeDefinitionData getNodeDefinitionDataInternal(InternalQName parentNodeType, InternalQName childName)
{
- return new ItemDefinitionDataHolder(new HashMap<ChildNodeDefKey, NodeDefinitionData>(nodeDefinitions),
- new HashMap<PropertyDefKey, PropertyDefinitionData>(propertyDefinitions),
- new HashMap<DefaultNodeDefKey, NodeDefinitionData>(defNodeDefinitions));
+ Map<InternalQName, NodeDefinitionData> defs = defNodeDefinitions.get(parentNodeType);
+ if (defs == null)
+ {
+ return null;
+ }
+ return defs.get(childName);
}
- private class ChildNodeDefKey extends ItemDefKey
+ private void addNodeDefinitionDataInternal(InternalQName parentNodeType, InternalQName childName,
+ NodeDefinitionData nodeDef)
{
- private int hashCode = -1;
+ Map<InternalQName, NodeDefinitionData> defs = defNodeDefinitions.get(parentNodeType);
+ if (defs == null)
+ {
+ defs = new HashMap<InternalQName, NodeDefinitionData>();
+ defNodeDefinitions.put(parentNodeType, defs);
+ }
- private final InternalQName childNodeType;
+ defs.put(childName, nodeDef);
+ }
- private ChildNodeDefKey(InternalQName parentNodeType, InternalQName childName, InternalQName childNodeType)
+ private void removeNodeDefinitionDataInternal(InternalQName parentNodeType, InternalQName childName)
+ {
+ Map<InternalQName, NodeDefinitionData> defs = defNodeDefinitions.get(parentNodeType);
+ if (defs == null)
{
- super(parentNodeType, childName);
- this.childNodeType = childNodeType;
+ return;
}
+ defs.remove(childName);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj)
+ private PropertyDefinitionData getPropertyDefinitionInternal(InternalQName parentNodeType, InternalQName childName,
+ boolean multiValued)
+ {
+ Map<InternalQName, Map<Boolean, PropertyDefinitionData>> defs = propertyDefinitions.get(parentNodeType);
+ if (defs == null)
{
- if (this == obj)
- {
- return true;
- }
- if (!super.equals(obj))
- {
- return false;
- }
- if (!(obj instanceof ChildNodeDefKey))
- {
- return false;
- }
- ChildNodeDefKey other = (ChildNodeDefKey)obj;
- if (!getOuterType().equals(other.getOuterType()))
- {
- return false;
- }
- if (childNodeType == null)
- {
- if (other.childNodeType != null)
- {
- return false;
- }
- }
- else if (!childNodeType.equals(other.childNodeType))
- {
- return false;
- }
- return true;
+ return null;
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
+ Map<Boolean, PropertyDefinitionData> def = defs.get(childName);
+ if (def == null)
{
- if (hashCode == -1)
- {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + getOuterType().hashCode();
- result = prime * result + ((childNodeType == null) ? 0 : childNodeType.hashCode());
- hashCode = result;
- }
-
- return hashCode;
+ return null;
}
+ return def.get(multiValued);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString()
+ private void addPropertyDefinitionInternal(InternalQName parentNodeType, InternalQName childName,
+ boolean multiValued, PropertyDefinitionData propDef)
+ {
+ Map<InternalQName, Map<Boolean, PropertyDefinitionData>> defs = propertyDefinitions.get(parentNodeType);
+ if (defs == null)
{
- String result = super.toString();
- result += ((childNodeType == null) ? "" : childNodeType.getAsString());
-
- return result;
+ defs = new HashMap<InternalQName, Map<Boolean, PropertyDefinitionData>>();
+ propertyDefinitions.put(parentNodeType, defs);
}
-
- private ItemDefinitionDataHolder getOuterType()
+ Map<Boolean, PropertyDefinitionData> def = defs.get(childName);
+ if (def == null)
{
- return ItemDefinitionDataHolder.this;
+ def = new HashMap<Boolean, PropertyDefinitionData>();
+ defs.put(childName, def);
}
+ def.put(multiValued, propDef);
}
-
- private class DefaultNodeDefKey extends ItemDefKey
+
+ private void removePropertyDefinitionInternal(InternalQName parentNodeType, InternalQName childName,
+ boolean multiValued)
{
-
- private DefaultNodeDefKey(InternalQName parentNodeType, InternalQName childName)
+ Map<InternalQName, Map<Boolean, PropertyDefinitionData>> defs = propertyDefinitions.get(parentNodeType);
+ if (defs == null)
{
- super(parentNodeType, childName);
+ return;
}
+ Map<Boolean, PropertyDefinitionData> def = defs.get(childName);
+ if (def == null)
+ {
+ return;
+ }
+ def.remove(multiValued);
}
-
- /**
- * @see about hash code generation:
- * http://www.geocities.com/technofundo/tech/java/equalhash.html
- */
- private abstract class ItemDefKey
+
+ private NodeDefinitionData getNodeDefinitionDataInternal(InternalQName parentNodeType, InternalQName childName,
+ InternalQName childNodeType)
{
-
- private final InternalQName parentNodeType;
-
- private final InternalQName childName;
-
- private int hashCode = -1;
-
- protected ItemDefKey(InternalQName parentNodeType, InternalQName childName)
+ Map<InternalQName, Map<InternalQName, NodeDefinitionData>> defs = nodeDefinitions.get(parentNodeType);
+ if (defs == null)
{
- this.parentNodeType = parentNodeType;
- this.childName = childName;
+ return null;
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj)
+ Map<InternalQName, NodeDefinitionData> def = defs.get(childName);
+ if (def == null)
{
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (!(obj instanceof ItemDefKey))
- {
- return false;
- }
- ItemDefKey other = (ItemDefKey)obj;
- if (!getOuterType().equals(other.getOuterType()))
- {
- return false;
- }
- if (childName == null)
- {
- if (other.childName != null)
- {
- return false;
- }
- }
- else if (!childName.equals(other.childName))
- {
- return false;
- }
- if (parentNodeType == null)
- {
- if (other.parentNodeType != null)
- {
- return false;
- }
- }
- else if (!parentNodeType.equals(other.parentNodeType))
- {
- return false;
- }
- return true;
+ return null;
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
+ return def.get(childNodeType);
+ }
+
+ private void addNodeDefinitionDataInternal(InternalQName parentNodeType, InternalQName childName,
+ InternalQName childNodeType, NodeDefinitionData nodeDef)
+ {
+ Map<InternalQName, Map<InternalQName, NodeDefinitionData>> defs = nodeDefinitions.get(parentNodeType);
+ if (defs == null)
{
- if (hashCode == -1)
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + getOuterType().hashCode();
- result = prime * result + ((childName == null) ? 0 : childName.hashCode());
- result = prime * result + ((parentNodeType == null) ? 0 : parentNodeType.hashCode());
- hashCode = result;
- }
- return hashCode;
+ defs = new HashMap<InternalQName, Map<InternalQName, NodeDefinitionData>>();
+ nodeDefinitions.put(parentNodeType, defs);
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString()
+ Map<InternalQName, NodeDefinitionData> def = defs.get(childName);
+ if (def == null)
{
- String result = "";
- result += ((childName == null) ? 0 : childName.getAsString());
- result += ((parentNodeType == null) ? 0 : parentNodeType.getAsString());
- return result;
+ def = new HashMap<InternalQName, NodeDefinitionData>();
+ defs.put(childName, def);
}
- private ItemDefinitionDataHolder getOuterType()
- {
- return ItemDefinitionDataHolder.this;
- }
+ def.put(childNodeType, nodeDef);
}
-
- private class PropertyDefKey extends ItemDefKey
+
+ private void removeNodeDefinitionDataInternal(InternalQName parentNodeType, InternalQName childName,
+ InternalQName childNodeType)
{
-
- private final boolean multiValued;
-
- private int hashCode = -1;
-
- private PropertyDefKey(InternalQName parentNodeType, InternalQName childName, boolean multiValued)
+ Map<InternalQName, Map<InternalQName, NodeDefinitionData>> defs = nodeDefinitions.get(parentNodeType);
+ if (defs == null)
{
- super(parentNodeType, childName);
- this.multiValued = multiValued;
+ return;
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj)
+ Map<InternalQName, NodeDefinitionData> def = defs.get(childName);
+ if (def == null)
{
- if (this == obj)
- {
- return true;
- }
- if (!super.equals(obj))
- {
- return false;
- }
- if (!(obj instanceof PropertyDefKey))
- {
- return false;
- }
- PropertyDefKey other = (PropertyDefKey)obj;
- if (!getOuterType().equals(other.getOuterType()))
- {
- return false;
- }
- if (multiValued != other.multiValued)
- {
- return false;
- }
- return true;
+ return;
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
+ def.remove(childNodeType);
+ }
+
+ /**
+ * Create copy of holder.
+ *
+ * @return
+ */
+ protected ItemDefinitionDataHolder createCopy()
+ {
+ return new ItemDefinitionDataHolder(cloneMap(nodeDefinitions), cloneMap(propertyDefinitions),
+ cloneMap(defNodeDefinitions));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <K,V> Map<K,V> cloneMap(Map<? extends K, ? extends V> map)
+ {
+ Map<K,V> copyMap = (Map<K,V>)((HashMap<K, V>)map).clone();
+
+ for (Entry<K, V> entry : copyMap.entrySet())
{
- if (hashCode == -1)
+ if (entry.getValue() instanceof Map<?, ?>)
{
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + getOuterType().hashCode();
- result = prime * result + (multiValued ? 1231 : 1237);
- hashCode = result;
+ entry.setValue((V)cloneMap((Map<?, ?>)entry.getValue()));
}
-
- return hashCode;
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString()
- {
- String result = super.toString();
- result += " multiValued=" + multiValued;
- return result;
- }
-
- private ItemDefinitionDataHolder getOuterType()
- {
- return ItemDefinitionDataHolder.this;
- }
+ return copyMap;
}
-
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24 08:18:30 UTC (rev 1158)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24 10:29:04 UTC (rev 1159)
@@ -26,9 +26,9 @@
import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import javax.jcr.RepositoryException;
@@ -178,11 +178,7 @@
*/
DataRequest waitSame()
{
- DataRequest prev = null;
- synchronized (requestCache)
- {
- prev = requestCache.get(this.hashCode());
- }
+ DataRequest prev = requestCache.get(this.hashCode());
if (prev != null)
prev.await();
return this;
@@ -193,10 +189,7 @@
*/
void start()
{
- synchronized (requestCache)
- {
- requestCache.put(this.hashCode(), this);
- }
+ requestCache.put(this.hashCode(), this);
}
/**
@@ -206,10 +199,7 @@
void done()
{
this.ready.countDown();
- synchronized (requestCache)
- {
- requestCache.remove(this.hashCode());
- }
+ requestCache.remove(this.hashCode());
}
/**
@@ -262,7 +252,7 @@
{
super(dataContainer, systemDataContainerHolder);
this.cache = cache;
- this.requestCache = new HashMap<Integer, DataRequest>();
+ this.requestCache = new ConcurrentHashMap<Integer, DataRequest>();
addItemPersistenceListener(cache);
}
16 years, 7 months
exo-jcr SVN: r1158 - 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 03:18:30 -0500 (Thu, 24 Dec 2009)
New Revision: 1158
Added:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLConnectionFactory.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLMultiDbJDBCConnection.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLSingleDbJDBCConnection.java
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/NewJDBCWorkspaceDataContainer.java
Log:
EXOJCR-302: MysSQL connections added
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-23 16:49:34 UTC (rev 1157)
+++ 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 08:18:30 UTC (rev 1158)
@@ -720,13 +720,13 @@
references.add((PropertyData)itemData(null, refProps, I_CLASS_PROPERTY, null));
}
- ResultSet resultSet = findReferenceProperties(getInternalId(nodeIdentifier));
- references = new ArrayList<PropertyData>(); //List<PropertyData>
- if (resultSet.next())
- {
- while (!resultSet.isAfterLast())
- references.add(loadPropertyRecord(resultSet, null));
- }
+ // ResultSet resultSet = findReferenceProperties(getInternalId(nodeIdentifier));
+ // List<PropertyData> references = new ArrayList<PropertyData>(); //
+ // if (resultSet.next())
+ // {
+ // while (!resultSet.isAfterLast())
+ // references.add(loadPropertyRecord(resultSet, null));
+ // }
return references;
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCWorkspaceDataContainer.java 2009-12-23 16:49:34 UTC (rev 1157)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCWorkspaceDataContainer.java 2009-12-24 08:18:30 UTC (rev 1158)
@@ -24,7 +24,6 @@
import org.exoplatform.services.jcr.impl.storage.WorkspaceDataContainerBase;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
-import org.exoplatform.services.jcr.impl.storage.jdbc.db.MySQLConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.OracleConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.WorkspaceStorageConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.DBInitializer;
@@ -33,6 +32,7 @@
import org.exoplatform.services.jcr.impl.storage.jdbc.init.OracleDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.init.PgSQLDBInitializer;
import org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.HSQLDBConnectionFactory;
+import org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db.MySQLConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.update.StorageUpdateManager;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
Added: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLConnectionFactory.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLConnectionFactory.java (rev 0)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLConnectionFactory.java 2009-12-24 08:18:30 UTC (rev 1158)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
+
+import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+
+import java.io.File;
+import java.sql.SQLException;
+
+import javax.jcr.RepositoryException;
+import javax.sql.DataSource;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * 16.03.2007
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter Nedonosko</a>
+ * @version $Id: MySQLConnectionFactory.java 34801 2009-07-31 15:44:50Z dkatayev $
+ */
+public class MySQLConnectionFactory extends GenericConnectionFactory
+{
+
+ /**
+ * MySQLConnectionFactory constructor.
+ *
+ *@param dataSource
+ * - DataSource
+ * @param dbDriver
+ * - JDBC Driver
+ * @param dbUrl
+ * - JDBC URL
+ * @param dbUserName
+ * - database username
+ * @param dbPassword
+ * - database user password
+ * @param containerName
+ * - Container name (see configuration)
+ * @param multiDb
+ * - multidatabase state flag
+ * @param valueStorageProvider
+ * - external Value Storages provider
+ * @param maxBufferSize
+ * - Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * - Swap directory (see configuration)
+ * @param swapCleaner
+ * - Swap cleaner (internal FileCleaner).
+ * @throws RepositoryException
+ * if error eccurs
+ */
+ public MySQLConnectionFactory(String dbDriver, String dbUrl, String dbUserName, String dbPassword,
+ String containerName, boolean multiDb, ValueStoragePluginProvider valueStorageProvider, int maxBufferSize,
+ File swapDirectory, FileCleaner swapCleaner) throws RepositoryException
+ {
+
+ super(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb, valueStorageProvider, maxBufferSize,
+ swapDirectory, swapCleaner);
+ }
+
+ /**
+ * MySQLConnectionFactory constructor.
+ *
+ * @param dataSource
+ * - DataSource
+ * @param containerName
+ * - Container name (see configuration)
+ * @param multiDb
+ * - multidatabase state flag
+ * @param valueStorageProvider
+ * - external Value Storages provider
+ * @param maxBufferSize
+ * - Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * - Swap directory (see configuration)
+ * @param swapCleaner
+ * - Swap cleaner (internal FileCleaner).
+ */
+ public MySQLConnectionFactory(DataSource dbDataSource, String containerName, boolean multiDb,
+ ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
+ {
+
+ super(dbDataSource, containerName, multiDb, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public WorkspaceStorageConnection openConnection(boolean readOnly) throws RepositoryException
+ {
+ try
+ {
+
+ if (multiDb)
+ {
+ return new MySQLMultiDbJDBCConnection(getJdbcConnection(readOnly), readOnly, containerName,
+ valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+ }
+
+ return new MySQLSingleDbJDBCConnection(getJdbcConnection(readOnly), readOnly, containerName,
+ valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+}
Added: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLMultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLMultiDbJDBCConnection.java (rev 0)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLMultiDbJDBCConnection.java 2009-12-24 08:18:30 UTC (rev 1158)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
+
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * 20.03.2007
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter Nedonosko</a>
+ * @version $Id: MySQLMultiDbJDBCConnection.java 34801 2009-07-31 15:44:50Z dkatayev $
+ */
+public class MySQLMultiDbJDBCConnection extends MultiDbJDBCConnection
+{
+
+ /**
+ * MySQL Multidatabase JDBC Connection constructor.
+ *
+ * @param dbConnection
+ * JDBC connection, shoudl be opened before
+ * @param readOnly
+ * boolean if true the dbConnection was marked as READ-ONLY.
+ * @param containerName
+ * Workspace Storage Container name (see configuration)
+ * @param valueStorageProvider
+ * External Value Storages provider
+ * @param maxBufferSize
+ * Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * Swap directory File (see configuration)
+ * @param swapCleaner
+ * Swap cleaner (internal FileCleaner).
+ * @throws SQLException
+ *
+ * @see org.exoplatform.services.jcr.impl.util.io.FileCleaner
+ */
+ public MySQLMultiDbJDBCConnection(Connection dbConnection, boolean readOnly, String containerName,
+ ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
+ throws SQLException
+ {
+
+ super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addNodeRecord(NodeData data) throws SQLException
+ {
+ // check if parent exists
+ if (data.getParentIdentifier() != null)
+ {
+ ResultSet item = findItemByIdentifier(data.getParentIdentifier());
+ try
+ {
+ if (!item.next())
+ throw new SQLException("Parent is not found. Behaviour of " + JCR_FK_ITEM_PARENT);
+ }
+ finally
+ {
+ item.close();
+ }
+ }
+ return super.addNodeRecord(data);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addPropertyRecord(PropertyData data) throws SQLException
+ {
+ // check if parent exists
+ if (data.getParentIdentifier() != null)
+ {
+ ResultSet item = findItemByIdentifier(data.getParentIdentifier());
+ try
+ {
+ if (!item.next())
+ throw new SQLException("Parent is not found. Behaviour of " + JCR_FK_ITEM_PARENT);
+ }
+ finally
+ {
+ item.close();
+ }
+ }
+ return super.addPropertyRecord(data);
+ }
+
+}
Added: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLSingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLSingleDbJDBCConnection.java (rev 0)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MySQLSingleDbJDBCConnection.java 2009-12-24 08:18:30 UTC (rev 1158)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.db;
+
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * 20.03.2007
+ *
+ * @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter Nedonosko</a>
+ * @version $Id: MySQLSingleDbJDBCConnection.java 34801 2009-07-31 15:44:50Z dkatayev $
+ */
+public class MySQLSingleDbJDBCConnection extends SingleDbJDBCConnection
+{
+
+ /**
+ * MySQL Singledatabase JDBC Connection constructor.
+ *
+ * @param dbConnection
+ * JDBC connection, shoudl be opened before
+ * @param readOnly
+ * boolean if true the dbConnection was marked as READ-ONLY.
+ * @param containerName
+ * Workspace Storage Container name (see configuration)
+ * @param valueStorageProvider
+ * External Value Storages provider
+ * @param maxBufferSize
+ * Maximum buffer size (see configuration)
+ * @param swapDirectory
+ * Swap directory File (see configuration)
+ * @param swapCleaner
+ * Swap cleaner (internal FileCleaner).
+ * @throws SQLException
+ *
+ * @see org.exoplatform.services.jcr.impl.util.io.FileCleaner
+ */
+ public MySQLSingleDbJDBCConnection(Connection dbConnection, boolean readOnly, String containerName,
+ ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
+ throws SQLException
+ {
+
+ super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addNodeRecord(NodeData data) throws SQLException
+ {
+ // check if parent exists
+ if (data.getParentIdentifier() != null)
+ {
+ ResultSet item = findItemByIdentifier(getInternalId(data.getParentIdentifier()));
+ try
+ {
+ if (!item.next())
+ throw new SQLException("Parent is not found. Behaviour of " + JCR_FK_ITEM_PARENT);
+ }
+ finally
+ {
+ item.close();
+ }
+ }
+ return super.addNodeRecord(data);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected int addPropertyRecord(PropertyData data) throws SQLException
+ {
+ // check if parent exists
+ if (data.getParentIdentifier() != null)
+ {
+ ResultSet item = findItemByIdentifier(getInternalId(data.getParentIdentifier()));
+ try
+ {
+ if (!item.next())
+ throw new SQLException("Parent is not found. Behaviour of " + JCR_FK_ITEM_PARENT);
+ }
+ finally
+ {
+ item.close();
+ }
+ }
+ return super.addPropertyRecord(data);
+ }
+
+}
16 years, 7 months
exo-jcr SVN: r1157 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow and 3 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-23 11:49:34 -0500 (Wed, 23 Dec 2009)
New Revision: 1157
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
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/persistent/ByteArrayPersistedValueData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java
Log:
EXOJCR-325: Merged Serialization from JBC branch. (Commits were used: 492, 496, 500)
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedItemData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -18,8 +18,15 @@
*/
package org.exoplatform.services.jcr.dataflow.persistent;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.exoplatform.services.jcr.datamodel.IllegalPathException;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
/**
* Created by The eXo Platform SAS. </br>
@@ -30,17 +37,34 @@
* @version $Id: PersistedItemData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public abstract class PersistedItemData implements ItemData
+public abstract class PersistedItemData implements ItemData, Externalizable
{
- protected final String id;
+ /**
+ * SerialVersionUID to serialization.
+ */
+ private static final long serialVersionUID = -3845740801904303663L;
- protected final QPath qpath;
+ protected String id;
- protected final String parentId;
+ protected QPath qpath;
- protected final int version;
+ protected String parentId;
+ protected int version;
+
+ private final int NOT_NULL_VALUE = 1;
+
+ private final int NULL_VALUE = -1;
+
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public PersistedItemData()
+ {
+ }
+
public PersistedItemData(String id, QPath qpath, String parentId, int version)
{
this.id = id;
@@ -104,4 +128,67 @@
return false;
}
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ byte[] buf;
+
+ try
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ String sQPath = new String(buf, Constants.DEFAULT_ENCODING);
+ qpath = QPath.parse(sQPath);
+ }
+ catch (final IllegalPathException e)
+ {
+ throw new IOException("Deserialization error. " + e)
+ {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ id = new String(buf);
+
+ int isNull = in.readInt();
+ if (isNull == NOT_NULL_VALUE)
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ parentId = new String(buf);
+ }
+
+ version = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ byte[] buf = qpath.getAsString().getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+
+ out.writeInt(id.getBytes().length);
+ out.write(id.getBytes());
+
+ if (parentId != null)
+ {
+ out.writeInt(NOT_NULL_VALUE);
+ out.writeInt(parentId.getBytes().length);
+ out.write(parentId.getBytes());
+ }
+ else
+ out.writeInt(NULL_VALUE);
+
+ out.writeInt(version);
+ }
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedNodeData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -18,14 +18,21 @@
*/
package org.exoplatform.services.jcr.dataflow.persistent;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.jcr.RepositoryException;
+
import org.exoplatform.services.jcr.access.AccessControlList;
import org.exoplatform.services.jcr.dataflow.ItemDataVisitor;
+import org.exoplatform.services.jcr.datamodel.IllegalNameException;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
-import javax.jcr.RepositoryException;
-
/**
* Created by The eXo Platform SAS.</br>
*
@@ -35,15 +42,23 @@
* @version $Id: PersistedNodeData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class PersistedNodeData extends PersistedItemData implements NodeData
+public class PersistedNodeData extends PersistedItemData implements NodeData, Externalizable
{
- protected final int orderNumber;
+ /**
+ * serialVersionUID to serialization.
+ */
+ private static final long serialVersionUID = 3033563403958948338L;
- protected final InternalQName primaryTypeName;
+ //TODO remove final
+ protected int orderNumber;
- protected final InternalQName[] mixinTypeNames;
+ //TODO remove final
+ protected InternalQName primaryTypeName;
+ //TODO remove final
+ protected InternalQName[] mixinTypeNames;
+
protected AccessControlList acl;
public PersistedNodeData(String id, QPath qpath, String parentId, int version, int orderNumber,
@@ -123,4 +138,94 @@
return true;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ super.readExternal(in);
+
+ orderNumber = in.readInt();
+
+ // primary type
+ byte[] buf;
+ try
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ primaryTypeName = InternalQName.parse(new String(buf, Constants.DEFAULT_ENCODING));
+ }
+ catch (final IllegalNameException e)
+ {
+ throw new IOException(e.getMessage())
+ {
+ private static final long serialVersionUID = 3489809179234435267L;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+
+ // mixins
+ int count = in.readInt();
+ mixinTypeNames = new InternalQName[count];
+ for (int i = 0; i < count; i++)
+ {
+ try
+ {
+ buf = new byte[in.readInt()];
+ in.readFully(buf);
+ mixinTypeNames[i] = InternalQName.parse(new String(buf, Constants.DEFAULT_ENCODING));
+ }
+ catch (final IllegalNameException e)
+ {
+ throw new IOException(e.getMessage())
+ {
+ private static final long serialVersionUID = 3489809179234435268L; // eclipse
+
+ // gen
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Throwable getCause()
+ {
+ return e;
+ }
+ };
+ }
+ }
+
+ // acl
+ acl.readExternal(in);
+
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ super.writeExternal(out);
+
+ out.writeInt(orderNumber);
+
+ // primary type
+ byte[] ptbuf = primaryTypeName.getAsString().getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(ptbuf.length);
+ out.write(ptbuf);
+
+ // mixins
+ out.writeInt(mixinTypeNames.length);
+ for (int i = 0; i < mixinTypeNames.length; i++)
+ {
+ byte[] buf = mixinTypeNames[i].getAsString().getBytes(Constants.DEFAULT_ENCODING);
+ out.writeInt(buf.length);
+ out.write(buf);
+ }
+
+ acl.writeExternal(out);
+ }
+
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/PersistedPropertyData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -23,6 +23,11 @@
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.ValueData;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
import java.util.List;
import javax.jcr.RepositoryException;
@@ -36,15 +41,30 @@
* @version $Id: PersistedPropertyData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class PersistedPropertyData extends PersistedItemData implements PropertyData
+public class PersistedPropertyData extends PersistedItemData implements PropertyData, Externalizable
{
+ /**
+ * serialVersionUID to serialization.
+ */
+ private static final long serialVersionUID = 2035566403758848232L;
+
+ protected final static int NULL_VALUES = -1;
+
protected List<ValueData> values;
- protected final int type;
+ protected int type;
- protected final boolean multiValued;
+ protected boolean multiValued;
+ /**
+ * Empty constructor to serialization.
+ */
+ public PersistedPropertyData()
+ {
+ super();
+ }
+
public PersistedPropertyData(String id, QPath qpath, String parentId, int version, int type, boolean multiValued)
{
super(id, qpath, parentId, version);
@@ -119,5 +139,42 @@
else
throw new RuntimeException("The values can not be changed ");
}
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ super.writeExternal(out);
+ out.writeInt(type);
+ out.writeBoolean(multiValued);
+
+ if (values != null)
+ {
+ int listSize = values.size();
+ out.writeInt(listSize);
+ for (int i = 0; i < listSize; i++)
+ out.writeObject(values.get(i));
+ }
+ else
+ {
+ out.writeInt(NULL_VALUES);
+ }
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ super.readExternal(in);
+
+ type = in.readInt();
+
+ multiValued = in.readBoolean();
+
+ int listSize = in.readInt();
+ if (listSize != NULL_VALUES)
+ {
+ values = new ArrayList<ValueData>();
+ for (int i = 0; i < listSize; i++)
+ values.add((ValueData)in.readObject());
+ }
+ }
+
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -18,13 +18,14 @@
*/
package org.exoplatform.services.jcr.impl.dataflow;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-
import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
@@ -34,11 +35,28 @@
import javax.jcr.RepositoryException;
-public class EditableValueData extends TransientValueData
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+public class EditableValueData extends TransientValueData implements Externalizable
{
- protected final int maxIOBuffSize;
+ /**
+ * SerialVersionUID to serialization.
+ */
+ private static final long serialVersionUID = -5280857006905550884L;
+
+ protected int maxIOBuffSize;
+ /**
+ * Empty constructor to serialization.
+ */
+ public EditableValueData()
+ {
+ super();
+ maxIOBuffSize = 0;
+ }
+
+
public EditableValueData(byte[] bytes, int orderNumber, FileCleaner fileCleaner, int maxBufferSize,
File tempDirectory) throws IOException
{
@@ -437,4 +455,14 @@
}
}
}
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ maxIOBuffSize = in.readInt();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeInt(maxIOBuffSize);
+ }
}
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-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -928,8 +928,26 @@
}
else
{
+ // write streams
out.writeInt(2);
+ //TODO Need optimization in backup service.
+ byte[] buf = new byte[4*1024];
+
+ if (!spooled)
+ spoolInputStream();
+ InputStream in = (spoolFile == null ? new ByteArrayInputStream(data) : new FileInputStream(spoolFile));
+ long dataLength = (spoolFile == null ? data.length : spoolFile.length());
+ int len;
+
+ //write length of spoolFile
+ out.writeLong(dataLength);
+
+ while ((len = in.read(buf)) > 0)
+ out.write(buf, 0, len);
+
+ in.close();
}
+
out.writeInt(orderNumber);
out.writeInt(maxBufferSize);
}
@@ -946,6 +964,37 @@
data = new byte[in.readInt()];
in.readFully(data);
}
+ else
+ {
+ //read file form stream
+ long lengthSpoolFile = in.readLong();
+
+ //TODO May be optimization.
+ SpoolFile sf = SpoolFile.createTempFile("jcrvd", null, tempDirectory);
+ sf.acquire(this);
+ OutputStream outStream = new FileOutputStream(sf);
+
+ byte[] buf = new byte[4*1024];
+
+ while (lengthSpoolFile > 0) {
+ if (lengthSpoolFile - buf.length > 0)
+ {
+ in.readFully(buf);
+ outStream.write(buf);
+ }
+ else
+ {
+ in.readFully(buf, 0, (int) lengthSpoolFile);
+ outStream.write(buf, 0, (int) lengthSpoolFile);
+ }
+ lengthSpoolFile-=buf.length;
+ }
+ outStream.flush();
+ outStream.close();
+ spoolFile = sf;
+ spooled = true;
+ }
+
orderNumber = in.readInt();
maxBufferSize = in.readInt();
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -22,8 +22,12 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
import javax.jcr.RepositoryException;
@@ -33,10 +37,22 @@
* @author Gennady Azarenkov
* @version $Id: ByteArrayPersistedValueData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class ByteArrayPersistedValueData extends AbstractValueData
+public class ByteArrayPersistedValueData extends AbstractValueData implements Externalizable
{
+ /**
+ * The serialVersionUID.
+ */
+ private static final long serialVersionUID = -9131328056670315388L;
protected byte[] data;
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public ByteArrayPersistedValueData()
+ {
+ super(0);
+ }
/**
* ByteArrayPersistedValueData constructor.
@@ -108,4 +124,20 @@
return false;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ orderNumber = in.readInt();
+
+ data = new byte[in.readInt()];
+ in.readFully(data);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeInt(orderNumber);
+
+ out.writeInt(data.length);
+ out.write(data);
+ }
+
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFileStreamValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -18,15 +18,16 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent;
-import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-import org.exoplatform.services.jcr.impl.util.io.SwapFile;
-
+import java.io.Externalizable;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.jcr.RepositoryException;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.SwapFile;
+
/**
* Created by The eXo Platform SAS. Implementation of FileStream ValueData secures deleting file in
* object finalization
@@ -35,10 +36,23 @@
* @version $Id: CleanableFileStreamValueData.java 35209 2009-08-07 15:32:27Z pnedonosko $
*/
-public class CleanableFileStreamValueData extends FileStreamPersistedValueData
+public class CleanableFileStreamValueData extends FileStreamPersistedValueData implements Externalizable
{
protected final FileCleaner cleaner;
+
+
+ /**
+ * Empty constructor to serialization.
+ *
+ * @throws FileNotFoundException
+ */
+ public CleanableFileStreamValueData() throws FileNotFoundException
+ {
+ super();
+ //TODO
+ cleaner = null;
+ }
/**
* CleanableFileStreamValueData constructor.
@@ -76,7 +90,7 @@
if (log.isDebugEnabled())
{
- log.debug("�ould not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
+ log.debug("�ould not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
+ file.getAbsolutePath());
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java 2009-12-23 16:05:41 UTC (rev 1156)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FileStreamPersistedValueData.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -21,10 +21,14 @@
import org.exoplatform.services.jcr.impl.dataflow.AbstractValueData;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import java.io.Externalizable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
import javax.jcr.RepositoryException;
@@ -35,10 +39,24 @@
* @version $Id: FileStreamPersistedValueData.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class FileStreamPersistedValueData extends AbstractValueData
+public class FileStreamPersistedValueData extends AbstractValueData implements Externalizable
{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -2668587716865690994L;
+
protected final File file;
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public FileStreamPersistedValueData()
+ {
+ super(0);
+ file = null;
+ }
/**
* FileStreamPersistedValueData constructor.
@@ -109,6 +127,18 @@
return false;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
// TODO cleanup
// protected void finalize() throws Throwable {
// try {
Copied: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java (from rev 492, jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java)
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.dataflow;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>
+ * Date: 06.11.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class TestTransientValueDataSerialization
+ extends JcrImplBaseTest
+{
+
+ public void testTVDSerialization() throws Exception
+ {
+ File f = createBLOBTempFile(145);
+ f.deleteOnExit();
+
+ // Create TransientValueData instants
+ TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
+ tvd.setMaxBufferSize(200*1024);
+ tvd.setFileCleaner(new FileCleaner());
+
+
+ File out = File.createTempFile("test", ".data");
+ out.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(tvd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedTransientValueData);
+ assertEquals(tvd.getLength(), deserializedTransientValueData.getLength());
+ assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
+ compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
+ }
+
+ public void testTVDSerialization2M() throws Exception
+ {
+ File f = createBLOBTempFile(2145);
+ f.deleteOnExit();
+
+ // Create TransientValueData instants
+ TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
+ tvd.setMaxBufferSize(200*1024);
+ tvd.setFileCleaner(new FileCleaner());
+
+ File out = File.createTempFile("test", ".data");
+ out.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(tvd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedTransientValueData);
+ assertEquals(tvd.getLength(), deserializedTransientValueData.getLength());
+ assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
+ compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
+ }
+}
Copied: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java (from rev 496, jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java)
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java 2009-12-23 16:49:34 UTC (rev 1157)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.dataflow.persistent;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>
+ * Date: 06.11.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class TestByteArrayPersistedValueDataSerialization
+ extends JcrImplBaseTest
+{
+ public void testBAPVDSerialization() throws Exception
+ {
+
+ byte []buf = new byte[124578];
+
+ for (int i = 0; i< buf.length; i++)
+ buf[i] = (byte) (Math.random()*256);
+
+ // Create ValueData instants
+ ByteArrayPersistedValueData vd = new ByteArrayPersistedValueData(buf, 11);
+
+ File out = File.createTempFile("test", ".data");
+ out.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(vd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ ByteArrayPersistedValueData deserializedValueData = (ByteArrayPersistedValueData) ois.readObject();
+
+ //check
+ assertNotNull(deserializedValueData);
+ assertEquals(vd.getLength(), deserializedValueData.getLength());
+ assertEquals(vd.getOrderNumber(), deserializedValueData.getOrderNumber());
+
+ for (int j = 0; j < vd.getAsByteArray().length; j++)
+ assertEquals(vd.getAsByteArray()[j], deserializedValueData.getAsByteArray()[j]);
+ }
+}
16 years, 7 months
exo-jcr SVN: r1156 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache and 3 other directories.
by do-not-reply@jboss.org
Author: skabashnyuk
Date: 2009-12-23 11:05:41 -0500 (Wed, 23 Dec 2009)
New Revision: 1156
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
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/lucene/MultiIndex.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
Log:
EXOJCR-331 : initial implementation of IndexUpdateMonitor
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2009-12-23 13:42:22 UTC (rev 1155)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2009-12-23 16:05:41 UTC (rev 1156)
@@ -16,18 +16,20 @@
*/
package org.exoplatform.services.jcr.impl.core.query;
-import java.io.IOException;
-import java.util.Iterator;
-
-import javax.jcr.RepositoryException;
-
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.query.lucene.DefaultIndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
/**
* Implements default behaviour for some methods of {@link QueryHandler}.
*/
@@ -70,8 +72,10 @@
/**
* {@link IndexInfos} instance that is passed to {@link MultiIndex}
*/
- private IndexInfos indexInfos;
+ protected IndexInfos indexInfos;
+ private IndexUpdateMonitor indexUpdateMonitor;
+
public boolean isInitialized()
{
return initialized;
@@ -228,4 +232,19 @@
return indexInfos == null ? new IndexInfos() : indexInfos;
}
+ /**
+ * @return the indexUpdateMonitor
+ */
+ public IndexUpdateMonitor getIndexUpdateMonitor()
+ {
+ return indexUpdateMonitor == null ? new DefaultIndexUpdateMonitor() : indexUpdateMonitor;
+ }
+
+ /**
+ * @param indexUpdateMonitor the indexUpdateMonitor to set
+ */
+ public void setIndexUpdateMonitor(IndexUpdateMonitor indexUpdateMonitor)
+ {
+ this.indexUpdateMonitor = indexUpdateMonitor;
+ }
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2009-12-23 13:42:22 UTC (rev 1155)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2009-12-23 16:05:41 UTC (rev 1156)
@@ -21,7 +21,9 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.query.lucene.DefaultIndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
@@ -167,4 +169,14 @@
*/
public IndexInfos getIndexInfos();
+ /**
+ * @return the indexUpdateMonitor
+ */
+ public IndexUpdateMonitor getIndexUpdateMonitor();
+
+ /**
+ * @param indexUpdateMonitor the indexUpdateMonitor to set
+ */
+ public void setIndexUpdateMonitor(IndexUpdateMonitor indexUpdateMonitor);
+
}
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-23 13:42:22 UTC (rev 1155)
+++ 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-23 16:05:41 UTC (rev 1156)
@@ -119,13 +119,17 @@
if (!parentHandler.isInitialized())
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
- // parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
+ //parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
+ //parentHandler.setIndexInfos(new IndexInfos());
+ 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 JbossCacheIndexInfos(cache, false, ioMode));
+ //handler.setIndexInfos(new IndexInfos());
+ handler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache));
handler.init();
}
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java 2009-12-23 16:05:41 UTC (rev 1156)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query.jbosscache;
+
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class JbossCacheIndexUpdateMonitor implements IndexUpdateMonitor
+{
+
+ private final Cache<Serializable, Object> cache;
+
+ private final static Fqn PARAMETER_ROOT = Fqn.fromString("INDEX_UPDATE_MONITOR");
+
+ private final static String PARAMETER_NAME = "index-update-in-progress";
+
+ /**
+ * @param cache instance of JbossCache that is used to deliver index names
+ */
+ public JbossCacheIndexUpdateMonitor(Cache<Serializable, Object> cache)
+ {
+ this.cache = cache;
+ setUpdateInProgress(false);
+
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor#getUpdateInProgress()
+ */
+ public boolean getUpdateInProgress()
+ {
+ Object value = cache.get(PARAMETER_ROOT, PARAMETER_NAME);
+ return value != null ? (Boolean)value : false;
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor#setUpdateInProgress(boolean)
+ */
+ public void setUpdateInProgress(boolean updateInProgress)
+ {
+ cache.put(PARAMETER_ROOT, PARAMETER_NAME, new Boolean(updateInProgress));
+ }
+
+}
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexUpdateMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java 2009-12-23 16:05:41 UTC (rev 1156)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query.lucene;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class DefaultIndexUpdateMonitor implements IndexUpdateMonitor
+{
+ private AtomicBoolean updateInProgress;
+
+ /**
+ * @param semaphore
+ */
+ public DefaultIndexUpdateMonitor()
+ {
+ super();
+ this.updateInProgress = new AtomicBoolean();
+ this.updateInProgress.set(false);
+ }
+
+ /**
+ *
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor#getUpdateInProgress()
+ */
+ public boolean getUpdateInProgress()
+ {
+ return updateInProgress.get();
+ }
+
+ /**
+ *
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor#setUpdateInProgress(boolean)
+ */
+ public void setUpdateInProgress(boolean updateInProgress)
+ {
+ this.updateInProgress.set(updateInProgress);
+ }
+}
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultIndexUpdateMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java 2009-12-23 16:05:41 UTC (rev 1156)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query.lucene;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public interface IndexUpdateMonitor
+{
+ /**
+ * @return the updateInProgress
+ */
+ boolean getUpdateInProgress();
+
+ /**
+ * @param updateInProgress the updateInProgress to set
+ */
+ void setUpdateInProgress(boolean updateInProgress);
+
+}
\ No newline at end of file
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexUpdateMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-23 13:42:22 UTC (rev 1155)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-23 16:05:41 UTC (rev 1156)
@@ -129,8 +129,10 @@
/**
* Flag indicating whether an update operation is in progress.
*/
- private boolean updateInProgress = false;
+ // private boolean updateInProgress = false;
+ private final IndexUpdateMonitor indexUpdateMonitor;
+
/**
* If not <code>null</code> points to a valid <code>IndexReader</code> that
* reads from all indexes, including volatile and persistent indexes.
@@ -225,10 +227,11 @@
* @throws IOException
* if an error occurs
*/
- MultiIndex(SearchIndex handler, IndexingTree indexingTree, IndexerIoMode ioMode, IndexInfos indexInfos)
- throws IOException
+ MultiIndex(SearchIndex handler, IndexingTree indexingTree, IndexerIoMode ioMode, IndexInfos indexInfos,
+ IndexUpdateMonitor indexUpdateMonitor) throws IOException
{
this.ioMode = ioMode;
+ this.indexUpdateMonitor = indexUpdateMonitor;
this.directoryManager = handler.getDirectoryManager();
this.indexDir = directoryManager.getDirectory(".");
this.handler = handler;
@@ -420,7 +423,8 @@
synchronized (updateMonitor)
{
- updateInProgress = true;
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true);
}
try
{
@@ -454,7 +458,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = false;
+ //updateInProgress = false;
+ indexUpdateMonitor.setUpdateInProgress(false);
updateMonitor.notifyAll();
releaseMultiReader();
}
@@ -500,7 +505,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = true;
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true);
}
int num;
try
@@ -532,7 +538,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = false;
+ //updateInProgress = false;
+ indexUpdateMonitor.setUpdateInProgress(false);
updateMonitor.notifyAll();
releaseMultiReader();
}
@@ -717,7 +724,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = true;
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true);
}
try
{
@@ -764,7 +772,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = false;
+ //updateInProgress = false;
+ indexUpdateMonitor.setUpdateInProgress(false);
updateMonitor.notifyAll();
releaseMultiReader();
}
@@ -819,7 +828,7 @@
}
// no reader available
// wait until no update is in progress
- while (updateInProgress)
+ while (indexUpdateMonitor.getUpdateInProgress())
{
try
{
@@ -1369,7 +1378,8 @@
log.debug("Flushing index after being idle for " + idleTime + " ms.");
synchronized (updateMonitor)
{
- updateInProgress = true;
+ //updateInProgress = true;
+ indexUpdateMonitor.setUpdateInProgress(true);
}
try
{
@@ -1379,7 +1389,8 @@
{
synchronized (updateMonitor)
{
- updateInProgress = false;
+ //updateInProgress = false;
+ indexUpdateMonitor.setUpdateInProgress(false);
updateMonitor.notifyAll();
releaseMultiReader();
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-23 13:42:22 UTC (rev 1155)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-23 16:05:41 UTC (rev 1156)
@@ -515,7 +515,7 @@
indexingConfig = createIndexingConfiguration(nsMappings);
analyzer.setIndexingConfig(indexingConfig);
- index = new MultiIndex(this, context.getIndexingTree(), ioMode, getIndexInfos());
+ index = new MultiIndex(this, context.getIndexingTree(), ioMode, getIndexInfos(), getIndexUpdateMonitor());
// if RW mode, create initial index and start check
if (ioMode == IndexerIoMode.READ_WRITE)
{
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java 2009-12-23 16:05:41 UTC (rev 1156)
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.cluster.prepare;
+
+import junit.framework.TestCase;
+
+import org.exoplatform.services.jcr.impl.core.query.jbosscache.JbossCacheIndexUpdateMonitor;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+
+import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk@exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class TestIndexUpdateMonitor extends TestCase
+{
+ /**
+ * Logger instance for this class
+ */
+ private final Log log = ExoLogger.getLogger(TestIndexUpdateMonitor.class);
+
+ private IndexUpdateMonitor indexUpdateMonitor;
+
+ /**
+ * @see org.exoplatform.services.jcr.BaseStandaloneTest#setUp()
+ */
+ @Override
+ public void setUp() throws Exception
+ {
+ // TODO Auto-generated method stub
+ super.setUp();
+ indexUpdateMonitor = new JbossCacheIndexUpdateMonitor(createCache());
+ }
+
+ public void testSimpleBoolean() throws Exception
+ {
+ //test default
+ assertFalse(indexUpdateMonitor.getUpdateInProgress());
+
+ //test set false
+ indexUpdateMonitor.setUpdateInProgress(false);
+ assertFalse(indexUpdateMonitor.getUpdateInProgress());
+
+ //test set true
+ indexUpdateMonitor.setUpdateInProgress(true);
+ assertTrue(indexUpdateMonitor.getUpdateInProgress());
+
+ //test set false
+ indexUpdateMonitor.setUpdateInProgress(false);
+ assertFalse(indexUpdateMonitor.getUpdateInProgress());
+
+ }
+
+ public void testMultiThread() throws Exception
+ {
+ AtomicBoolean atomicBoolean = new AtomicBoolean();
+ ThreadGroup chengers = new ThreadGroup("Changers");
+ ThreadGroup checkers = new ThreadGroup("Checkers");
+ Thread[] changersArray = new Thread[10];
+ Thread[] checkerArray = new Thread[10];
+
+ for (int i = 0; i < changersArray.length; i++)
+ {
+ changersArray[i] = new Thread(chengers, new UpdateMonitorChanger(atomicBoolean));
+ changersArray[i].start();
+ }
+
+ for (int i = 0; i < checkerArray.length; i++)
+ {
+ checkerArray[i] = new Thread(checkers, new UpdateMonitorChecker(atomicBoolean));
+ checkerArray[i].start();
+ }
+
+ // Thread changer = new Thread(new UpdateMonitorChanger(atomicBoolean));
+ // changer.start();
+ // Thread checker = new Thread(new UpdateMonitorChecker(atomicBoolean));
+ // checker.start();
+
+ Thread.sleep(4 * 60 * 1000);
+ chengers.destroy();
+ checkers.destroy();
+ }
+
+ private class UpdateMonitorChanger implements Runnable
+ {
+ private AtomicBoolean atomicBoolean;
+
+ /**
+ * @param atomicBoolean
+ */
+ public UpdateMonitorChanger(AtomicBoolean atomicBoolean)
+ {
+ super();
+ this.atomicBoolean = atomicBoolean;
+ }
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run()
+ {
+ while (!Thread.currentThread().isInterrupted())
+ {
+
+ synchronized (atomicBoolean)
+ {
+ assertEquals(atomicBoolean.get(), indexUpdateMonitor.getUpdateInProgress());
+ boolean oldValue = atomicBoolean.get();
+
+ indexUpdateMonitor.setUpdateInProgress(!oldValue);
+
+ if (!atomicBoolean.compareAndSet(oldValue, !oldValue))
+ {
+ log.warn("Fail to change monitor");
+ }
+ }
+ }
+
+ }
+ }
+
+ private class UpdateMonitorChecker implements Runnable
+ {
+
+ /**
+ * @param atomicBoolean
+ */
+ public UpdateMonitorChecker(AtomicBoolean atomicBoolean)
+ {
+ super();
+ this.atomicBoolean = atomicBoolean;
+ }
+
+ private final AtomicBoolean atomicBoolean;
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run()
+ {
+
+ while (!Thread.currentThread().isInterrupted())
+ {
+
+ synchronized (atomicBoolean)
+ {
+ //assertEquals(atomicBoolean.get(), indexUpdateMonitor.getUpdateInProgress());
+ if (atomicBoolean.get() == indexUpdateMonitor.getUpdateInProgress())
+ {
+ System.out.println("check ok");
+ }
+ else
+ {
+ System.out.println("check fail");
+ }
+
+ }
+
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException e)
+ {
+ return;
+ }
+ }
+
+ }
+ }
+
+ private Cache<Serializable, Object> createCache()
+ {
+ String jbcConfig = "conf/standalone/test-jbosscache-config.xml";
+ CacheFactory<Serializable, Object> factory = new DefaultCacheFactory<Serializable, Object>();
+ log.info("JBoss Cache configuration used: " + jbcConfig);
+ Cache<Serializable, Object> cache = factory.createCache(jbcConfig, false);
+
+ cache.create();
+ cache.start();
+ return cache;
+ }
+
+}
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestIndexUpdateMonitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2009-12-23 13:42:22 UTC (rev 1155)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2009-12-23 16:05:41 UTC (rev 1156)
@@ -74,6 +74,9 @@
<query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws" />
+ <!-- property name="changesfilter-class" value="org.exoplatform.services.jcr.impl.core.query.jbosscache.JbossCacheIndexChangesFilter" />
+ <property name="changesfilter-config-path" value="conf/standalone/test-jbosscache-config.xml" /-->
+
</properties>
</query-handler>
<lock-manager>
16 years, 7 months
exo-jcr SVN: r1155 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query: jbosscache and 1 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-23 08:42:22 -0500 (Wed, 23 Dec 2009)
New Revision: 1155
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
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/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
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-327: ADefault index infos, shouldn't have ioMode or system flag: fixed. If no IndexInfos defined for QueryHandler, indexInfos (default impl) is used.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2009-12-23 13:17:28 UTC (rev 1154)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2009-12-23 13:42:22 UTC (rev 1155)
@@ -225,7 +225,7 @@
*/
public IndexInfos getIndexInfos()
{
- return indexInfos;
+ return indexInfos == null ? new IndexInfos() : indexInfos;
}
}
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java 2009-12-23 13:17:28 UTC (rev 1154)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java 2009-12-23 13:42:22 UTC (rev 1155)
@@ -20,7 +20,6 @@
import org.exoplatform.services.jcr.config.QueryHandlerEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -59,12 +58,10 @@
if (!parentHandler.isInitialized())
{
- parentHandler.setIndexInfos(new IndexInfos(true, IndexerIoMode.READ_WRITE));
parentHandler.init();
}
if (!handler.isInitialized())
{
- handler.setIndexInfos(new IndexInfos(false, IndexerIoMode.READ_WRITE));
handler.init();
}
}
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-23 13:17:28 UTC (rev 1154)
+++ 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-23 13:42:22 UTC (rev 1155)
@@ -118,12 +118,14 @@
if (!parentHandler.isInitialized())
{
- parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
+ // TODO: uncomment it, when JbossCacheIndexInfos is finished.
+ // parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
parentHandler.init();
}
if (!handler.isInitialized())
{
- handler.setIndexInfos(new JbossCacheIndexInfos(cache, false, ioMode));
+ // TODO: uncomment it, when JbossCacheIndexInfos is finished.
+ // handler.setIndexInfos(new JbossCacheIndexInfos(cache, false, ioMode));
handler.init();
}
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-23 13:17:28 UTC (rev 1154)
+++ 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-23 13:42:22 UTC (rev 1155)
@@ -43,15 +43,25 @@
private final Log log = ExoLogger.getLogger(this.getClass().getName());
- public static final String INDEX_NAMES = "$names".intern();
+ private static final String INDEX_NAMES = "$names".intern();
- public static final String SYSINDEX_NAMES = "$sysNames".intern();
+ private static final String SYSINDEX_NAMES = "$sysNames".intern();
- public static final String LIST = "$list".intern();
+ private static final String LIST = "$list".intern();
private final Cache<Serializable, Object> cache;
/**
+ * Flag notifies if this IndexInfos is from system search manager or not.
+ */
+ private boolean system;
+
+ /**
+ * {@link IndexerIoMode} is used to define current mode.
+ */
+ private IndexerIoMode ioMode = IndexerIoMode.READ_WRITE;
+
+ /**
* This FQN points to cache node, where list of indexes for this {@link IndexInfos} instance is stored.
*/
private final Fqn namesFqn;
@@ -70,24 +80,21 @@
*/
public JbossCacheIndexInfos(String fileName, Cache<Serializable, Object> cache, boolean system, IndexerIoMode ioMode)
{
- super(fileName, system, ioMode);
+ super(fileName);
this.cache = cache;
namesFqn = Fqn.fromString(system ? SYSINDEX_NAMES : INDEX_NAMES);
- }
-
- @Override
- public void write() throws IOException
- {
- boolean dirty = isDirty();
- // write to FS
- super.write();
- // write to cache
- if (dirty)
+ if (ioMode == IndexerIoMode.READ_ONLY)
{
- // send to cache new list.
+ // Currently READ_ONLY is set, so new lists should be fired to multiIndex.
+ cache.addCacheListener(this);
}
}
+ /**
+ * 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)
{
@@ -107,10 +114,27 @@
}
}
+ /**
+ * @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 (getIoMode() != ioMode)
+ if (this.ioMode != ioMode)
{
super.setIoMode(ioMode);
if (ioMode == IndexerIoMode.READ_WRITE)
@@ -118,6 +142,8 @@
// Now is read-write. Index list is actual and shouldn't be refreshed.
// Remove listener to avoid asserting if ioMode is RO on each cache event
cache.removeCacheListener(this);
+ // re-read from FS current actual list.
+ refresh();
}
else
{
@@ -127,4 +153,20 @@
}
}
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#write()
+ */
+ @Override
+ public void write() throws IOException
+ {
+ boolean dirty = isDirty();
+ // write to FS
+ super.write();
+ // write to cache
+ if (dirty)
+ {
+ // send to cache new list.
+ }
+ }
+
}
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-23 13:17:28 UTC (rev 1154)
+++ 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-23 13:42:22 UTC (rev 1155)
@@ -78,18 +78,11 @@
private MultiIndex multiIndex;
/**
- * {@link IndexerIoMode} is used to define current mode.
- */
- private IndexerIoMode ioMode;
-
- private final boolean system;
-
- /**
* Creates a new IndexInfos using <code>"indexes"</code> as a filename.
*/
- public IndexInfos(boolean system, IndexerIoMode ioMode)
+ public IndexInfos()
{
- this(DEFALUT_NAME, system, ioMode);
+ this(DEFALUT_NAME);
}
/**
@@ -97,11 +90,9 @@
*
* @param fileName the name of the file where infos are stored.
*/
- public IndexInfos(String fileName, boolean system, IndexerIoMode ioMode)
+ public IndexInfos(String fileName)
{
this.name = fileName;
- this.system = system;
- this.ioMode = ioMode;
}
/**
@@ -135,6 +126,7 @@
*/
public void read() throws IOException
{
+ // clear current lists
InputStream in = new IndexInputStream(dir.openInput(name));
try
{
@@ -154,6 +146,20 @@
}
/**
+ * 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.
@@ -295,19 +301,7 @@
*/
public void setIoMode(IndexerIoMode ioMode) throws IOException
{
- if (this.ioMode != ioMode)
- {
- this.ioMode = ioMode;
- if (ioMode == IndexerIoMode.READ_WRITE)
- {
- names.clear();
- indexes.clear();
- if (exists())
- {
- read();
- }
- }
- }
+ // do nothing
}
/**
@@ -316,7 +310,7 @@
*/
public IndexerIoMode getIoMode()
{
- return ioMode;
+ return IndexerIoMode.READ_WRITE;
}
/**
@@ -352,15 +346,6 @@
}
/**
- * Returns true if this {@link IndexInfos} corresponds to SystemSearchManager
- * @return
- */
- public boolean isSystem()
- {
- return system;
- }
-
- /**
* Returns true, if changes weren't saved to FS.
* @return
*/
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-23 13:17:28 UTC (rev 1154)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-23 13:42:22 UTC (rev 1155)
@@ -2434,7 +2434,7 @@
// release reader if any
releaseMultiReader();
// get new indexInfo
- IndexInfos newIndexNames = new IndexInfos(indexNames.isSystem(), ioMode);
+ IndexInfos newIndexNames = new IndexInfos();
newIndexNames.setMultiIndex(this);
newIndexNames.setDirectory(indexDir);
if (newIndexNames.exists())
16 years, 7 months
exo-jcr SVN: r1154 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-12-23 08:17:28 -0500 (Wed, 23 Dec 2009)
New Revision: 1154
Modified:
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: Added check exists() on setIoMode in IndexInfos, before read().
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-23 13:11:55 UTC (rev 1153)
+++ 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-23 13:17:28 UTC (rev 1154)
@@ -302,7 +302,10 @@
{
names.clear();
indexes.clear();
- read();
+ if (exists())
+ {
+ read();
+ }
}
}
}
16 years, 7 months