Author: tolusha
Date: 2009-11-17 08:17:40 -0500 (Tue, 17 Nov 2009)
New Revision: 719
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.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/test/java/org/exoplatform/services/jcr/api/core/query/UpperLowerCaseQueryTest.java
Log:
EXOJCR-221: add, getNodes improvement
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2009-11-17
13:13:23 UTC (rev 718)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2009-11-17
13:17:40 UTC (rev 719)
@@ -104,20 +104,15 @@
protected ValueFactoryImpl valueFactory;
/**
- * Hashcode.
- */
- protected final int itemHashCode;
-
- /**
- * ItemImpl constructor.
- *
- * @param data
- * ItemData object
- * @param session
- * Session object
- * @throws RepositoryException
- * if any Exception is occurred
- */
+ * ItemImpl constructor.
+ *
+ * @param data
+ * ItemData object
+ * @param session
+ * Session object
+ * @throws RepositoryException
+ * if any Exception is occurred
+ */
ItemImpl(ItemData data, SessionImpl session) throws RepositoryException
{
@@ -127,8 +122,6 @@
this.dataManager = session.getTransientNodesManager();
this.locationFactory = session.getLocationFactory();
this.valueFactory = session.getValueFactory();
-
- itemHashCode = (session.getWorkspace().getName() +
data.getIdentifier()).hashCode();
}
protected void invalidate()
@@ -803,15 +796,6 @@
return false;
}
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
- {
- return itemHashCode;
- }
-
private ValueData valueData(Value value, int type) throws RepositoryException,
ValueFormatException
{
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-11-17
13:13:23 UTC (rev 718)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2009-11-17
13:17:40 UTC (rev 719)
@@ -466,18 +466,12 @@
public boolean isNew(String identifier)
{
- List<ItemState> states = changesLog.getItemStates(identifier);
- ItemState lastState = states.size() > 0 ? states.get(states.size() - 1) : null;
+ ItemState lastState = changesLog.getItemState(identifier);
if (lastState == null || lastState.isDeleted())
return false;
- for (ItemState state : states)
- {
- if (state.isAdded())
- return true;
- }
- return false;
+ return changesLog.getItemState(identifier, ItemState.ADDED) != null;
}
/**
@@ -534,7 +528,8 @@
// [PN] 21.12.07 use item data
NodeData parent = (NodeData)getItemData(data.getParentIdentifier());
// skip not permitted
- if (accessManager.hasPermission(parent.getACL(), PermissionType.READ,
session.getUserState().getIdentity()))
+ if (accessManager.hasPermission(parent.getACL(), new
String[]{PermissionType.READ}, session.getUserState()
+ .getIdentity()))
{
PropertyImpl item = null;
ItemState state = changesLog.getItemState(identifier);
@@ -587,7 +582,8 @@
session.getActionHandler().postRead(item);
- if (accessManager.hasPermission(data.getACL(), PermissionType.READ,
session.getUserState().getIdentity()))
+ if (accessManager.hasPermission(data.getACL(), new
String[]{PermissionType.READ}, session.getUserState()
+ .getIdentity()))
{
if (pool)
item = (NodeImpl)itemsPool.get(item);
@@ -633,7 +629,8 @@
{
ItemImpl item = itemFactory.createItem(data);
session.getActionHandler().postRead(item);
- if (accessManager.hasPermission(parent.getACL(), PermissionType.READ,
session.getUserState().getIdentity()))
+ if (accessManager.hasPermission(parent.getACL(), new
String[]{PermissionType.READ}, session.getUserState()
+ .getIdentity()))
{
if (pool)
item = itemsPool.get(item);
@@ -676,31 +673,8 @@
*/
public int getChildNodesCount(NodeData parent) throws RepositoryException
{
- int childsCount = changesLog.getChildNodesCount(parent.getIdentifier());
-
- // for (ItemState change : changesLog.getAllStates())
- // {
- // if (change.isNode() && change.isPersisted()
- // &&
parent.getIdentifier().equals(change.getData().getParentIdentifier()))
- // {
- // if (change.isDeleted())
- // {
- // childsCount--;
- // }
- // else if (change.isAdded())
- // {
- // childsCount++;
- // }
- // }
- // }
- //
- // if (childsCount != changesLog.getChildNodesCount(parent.getIdentifier()))
- // {
- // System.out.println("");
- // changesLog.getChildNodesCount(parent.getIdentifier());
- // }
-
- childsCount = transactionableManager.getChildNodesCount(parent) + childsCount;
+ int childsCount =
+ changesLog.getChildNodesCount(parent.getIdentifier()) +
transactionableManager.getChildNodesCount(parent);
if (childsCount < 0)
{
throw new InvalidItemStateException("Node's child nodes were changed in
another Session "
@@ -1303,8 +1277,8 @@
// Remove propery or node
if (changedItem.isDeleted())
{
- if (!accessManager.hasPermission(parent.getACL(), PermissionType.REMOVE,
session.getUserState()
- .getIdentity()))
+ if (!accessManager.hasPermission(parent.getACL(), new
String[]{PermissionType.REMOVE}, session
+ .getUserState().getIdentity()))
throw new AccessDeniedException("Access denied: REMOVE "
+ changedItem.getData().getQPath().getAsString() + " for: " +
session.getUserID() + " item owner "
+ parent.getACL().getOwner());
@@ -1314,8 +1288,8 @@
// add node
if (changedItem.isAdded())
{
- if (!accessManager.hasPermission(parent.getACL(), PermissionType.ADD_NODE,
session.getUserState()
- .getIdentity()))
+ if (!accessManager.hasPermission(parent.getACL(), new
String[]{PermissionType.ADD_NODE}, session
+ .getUserState().getIdentity()))
{
throw new AccessDeniedException("Access denied: ADD_NODE "
+ changedItem.getData().getQPath().getAsString() + " for:
" + session.getUserID() + " item owner "
@@ -1326,8 +1300,8 @@
else if (changedItem.isAdded() || changedItem.isUpdated())
{
// add or update property
- if (!accessManager.hasPermission(parent.getACL(),
PermissionType.SET_PROPERTY, session.getUserState()
- .getIdentity()))
+ if (!accessManager.hasPermission(parent.getACL(), new
String[]{PermissionType.SET_PROPERTY}, session
+ .getUserState().getIdentity()))
throw new AccessDeniedException("Access denied: SET_PROPERTY "
+ changedItem.getData().getQPath().getAsString() + " for: " +
session.getUserID() + " item owner "
+ parent.getACL().getOwner());
@@ -1686,10 +1660,6 @@
{
ret.add(childNode);
- if (log.isDebugEnabled())
- log.debug("Traverse transient (N) " +
childNode.getData().getQPath().getAsString() + " "
- + ItemState.nameFromValue(childNode.getState()));
-
if (deep)
traverseTransientDescendants(childNode.getData(), deep, action, ret);
}
@@ -1700,17 +1670,14 @@
for (ItemState childProp : childProps)
{
ret.add(childProp);
-
- if (log.isDebugEnabled())
- log.debug("Traverse transient (P) " +
childProp.getData().getQPath().getAsString());
}
}
}
}
/**
- * Pool for touched items.
- */
+ * Pool for touched items.
+ */
protected final class ItemReferencePool
{
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/UpperLowerCaseQueryTest.java
===================================================================
---
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/UpperLowerCaseQueryTest.java 2009-11-17
13:13:23 UTC (rev 718)
+++
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/core/query/UpperLowerCaseQueryTest.java 2009-11-17
13:17:40 UTC (rev 719)
@@ -16,9 +16,9 @@
*/
package org.exoplatform.services.jcr.api.core.query;
-
-
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Random;
import java.util.Set;
@@ -32,295 +32,276 @@
* fn:upper-case() in XPath, LOWER() and UPPER() in SQL and UpperCase and
* LowerCase in JQOM.
*/
-public class UpperLowerCaseQueryTest extends AbstractQueryTest {
+public class UpperLowerCaseQueryTest extends AbstractQueryTest
+{
-// /**
-// * Maps operator strings to QueryObjectModelConstants.
-// */
-// private static final Map OPERATORS = new HashMap();
-//
-// static {
-// OPERATORS.put("=", new Integer(OPERATOR_EQUAL_TO));
-// OPERATORS.put(">", new Integer(OPERATOR_GREATER_THAN));
-// OPERATORS.put(">=", new
Integer(OPERATOR_GREATER_THAN_OR_EQUAL_TO));
-// OPERATORS.put("<", new Integer(OPERATOR_LESS_THAN));
-// OPERATORS.put("<=", new Integer(OPERATOR_LESS_THAN_OR_EQUAL_TO));
-// OPERATORS.put("like", new Integer(OPERATOR_LIKE));
-// OPERATORS.put("!=", new Integer(OPERATOR_NOT_EQUAL_TO));
-// }
+ // /**
+ // * Maps operator strings to QueryObjectModelConstants.
+ // */
+ // private static final Map OPERATORS = new HashMap();
+ //
+ // static {
+ // OPERATORS.put("=", new Integer(OPERATOR_EQUAL_TO));
+ // OPERATORS.put(">", new Integer(OPERATOR_GREATER_THAN));
+ // OPERATORS.put(">=", new
Integer(OPERATOR_GREATER_THAN_OR_EQUAL_TO));
+ // OPERATORS.put("<", new Integer(OPERATOR_LESS_THAN));
+ // OPERATORS.put("<=", new
Integer(OPERATOR_LESS_THAN_OR_EQUAL_TO));
+ // OPERATORS.put("like", new Integer(OPERATOR_LIKE));
+ // OPERATORS.put("!=", new Integer(OPERATOR_NOT_EQUAL_TO));
+ // }
- public void testEqualsGeneralComparison() throws RepositoryException {
- check(new String[]{"foo", "Foo", "fOO",
"FOO", "fooBar", "fo", "fooo"},
- "=",
- "foo",
- new boolean[]{true, true, true, true, false, false, false});
- check(new String[]{"foo"}, "=", "", new
boolean[]{false});
- check(new String[]{""}, "=", "", new
boolean[]{true});
- }
+ public void testEqualsGeneralComparison() throws RepositoryException
+ {
+ check(new String[]{"foo", "Foo", "fOO",
"FOO", "fooBar", "fo", "fooo"}, "=",
"foo", new boolean[]{true, true,
+ true, true, false, false, false});
+ check(new String[]{"foo"}, "=", "", new
boolean[]{false});
+ check(new String[]{""}, "=", "", new
boolean[]{true});
+ }
- public void testGreaterThanGeneralComparison() throws RepositoryException {
- // check edges
- check(new String[]{"foo", "FOO", "FoO",
"fOo", "FON", "fon", "fo", "FO"},
- ">",
- "foo",
- new boolean[]{false, false, false, false, false, false, false, false});
- check(new String[]{"foo ", "FOOa", "FoOO",
"fOo1", "FOp", "foP", "fp", "g",
"G"},
- ">",
- "foo",
- new boolean[]{true, true, true, true, true, true, true, true, true});
- // check combinations
- check(new String[]{"foo", "fooo", "FooO",
"fo", "FON", "fon"},
- ">",
- "foo",
- new boolean[]{false, true, true, false, false, false});
- }
+ public void testGreaterThanGeneralComparison() throws RepositoryException
+ {
+ // check edges
+ check(new String[]{"foo", "FOO", "FoO",
"fOo", "FON", "fon", "fo", "FO"},
">", "foo", new boolean[]{false, false,
+ false, false, false, false, false, false});
+ check(new String[]{"foo ", "FOOa", "FoOO",
"fOo1", "FOp", "foP", "fp", "g",
"G"}, ">", "foo", new boolean[]{true,
+ true, true, true, true, true, true, true, true});
+ // check combinations
+ check(new String[]{"foo", "fooo", "FooO",
"fo", "FON", "fon"}, ">", "foo", new
boolean[]{false, true, true,
+ false, false, false});
+ }
- public void testLessThanGeneralComparison() throws RepositoryException {
- // check edges
- check(new String[]{"foo", "FOO", "FoO",
"fOo", "foOo", "foo ", "fooa", "fop"},
- "<",
- "foo",
- new boolean[]{false, false, false, false, false, false, false, false});
- check(new String[]{"fo", "FOn", "FoN",
"fO", "FO1", "fn", "fN", "E",
"e"},
- "<",
- "foo",
- new boolean[]{true, true, true, true, true, true, true, true, true});
- // check combinations
- check(new String[]{"foo", "fooo", "FooO",
"fo", "FON", "fon"},
- "<",
- "foo",
- new boolean[]{false, false, false, true, true, true});
- }
+ public void testLessThanGeneralComparison() throws RepositoryException
+ {
+ // check edges
+ check(new String[]{"foo", "FOO", "FoO",
"fOo", "foOo", "foo ", "fooa", "fop"},
"<", "foo", new boolean[]{false,
+ false, false, false, false, false, false, false});
+ check(new String[]{"fo", "FOn", "FoN",
"fO", "FO1", "fn", "fN", "E",
"e"}, "<", "foo", new boolean[]{true, true,
+ true, true, true, true, true, true, true});
+ // check combinations
+ check(new String[]{"foo", "fooo", "FooO",
"fo", "FON", "fon"}, "<", "foo", new
boolean[]{false, false, false,
+ true, true, true});
+ }
- public void testGreaterEqualsGeneralComparison() throws RepositoryException {
- // check edges
- check(new String[]{"fo", "FO", "Fon",
"fONo", "FON", "fO", "fo", "FO"},
- ">=",
- "foo",
- new boolean[]{false, false, false, false, false, false, false, false});
- check(new String[]{"foo", "FoO", "FoOO",
"fOo1", "FOp", "foP", "fp", "g",
"G"},
- ">=",
- "foo",
- new boolean[]{true, true, true, true, true, true, true, true, true});
- // check combinations
- check(new String[]{"foo", "fooo", "FOo",
"fo", "FON", "fon"},
- ">=",
- "foo",
- new boolean[]{true, true, true, false, false, false});
- }
+ public void testGreaterEqualsGeneralComparison() throws RepositoryException
+ {
+ // check edges
+ check(new String[]{"fo", "FO", "Fon",
"fONo", "FON", "fO", "fo", "FO"},
">=", "foo", new boolean[]{false, false,
+ false, false, false, false, false, false});
+ check(new String[]{"foo", "FoO", "FoOO",
"fOo1", "FOp", "foP", "fp", "g",
"G"}, ">=", "foo", new boolean[]{true,
+ true, true, true, true, true, true, true, true});
+ // check combinations
+ check(new String[]{"foo", "fooo", "FOo",
"fo", "FON", "fon"}, ">=", "foo", new
boolean[]{true, true, true, false,
+ false, false});
+ }
- public void testLessEqualsGeneralComparison() throws RepositoryException {
- // check edges
- check(new String[]{"fooo", "FOoo", "Fop",
"fOpo", "FOP", "fOo ", "fp", "G"},
- "<=",
- "foo",
- new boolean[]{false, false, false, false, false, false, false, false});
- check(new String[]{"foo", "FoO", "Foo",
"fOn", "FO", "fo", "f", "E",
"e"},
- "<=",
- "foo",
- new boolean[]{true, true, true, true, true, true, true, true, true});
- // check combinations
- check(new String[]{"foo", "fo", "FOo",
"fop", "FOP", "fooo"},
- "<=",
- "foo",
- new boolean[]{true, true, true, false, false, false});
- }
+ public void testLessEqualsGeneralComparison() throws RepositoryException
+ {
+ // check edges
+ check(new String[]{"fooo", "FOoo", "Fop",
"fOpo", "FOP", "fOo ", "fp", "G"},
"<=", "foo", new boolean[]{false,
+ false, false, false, false, false, false, false});
+ check(new String[]{"foo", "FoO", "Foo",
"fOn", "FO", "fo", "f", "E",
"e"}, "<=", "foo", new boolean[]{true, true,
+ true, true, true, true, true, true, true});
+ // check combinations
+ check(new String[]{"foo", "fo", "FOo",
"fop", "FOP", "fooo"}, "<=", "foo",
new boolean[]{true, true, true, false,
+ false, false});
+ }
- public void testNotEqualsGeneralComparison() throws RepositoryException {
- // check edges
- check(new String[]{"fooo", "FOoo", "Fop",
"fOpo", "FOP", "fOo ", "fp", "G",
""},
- "!=",
- "foo",
- new boolean[]{true, true, true, true, true, true, true, true, true});
- check(new String[]{"foo", "FoO", "Foo",
"foO", "FOO"},
- "!=",
- "foo",
- new boolean[]{false, false, false, false, false});
- // check combinations
- check(new String[]{"foo", "fo", "FOo",
"fop", "FOP", "fooo"},
- "!=",
- "foo",
- new boolean[]{false, true, false, true, true, true});
- }
+ public void testNotEqualsGeneralComparison() throws RepositoryException
+ {
+ // check edges
+ check(new String[]{"fooo", "FOoo", "Fop",
"fOpo", "FOP", "fOo ", "fp", "G",
""}, "!=", "foo", new boolean[]{true,
+ true, true, true, true, true, true, true, true});
+ check(new String[]{"foo", "FoO", "Foo",
"foO", "FOO"}, "!=", "foo", new boolean[]{false,
false, false, false,
+ false});
+ // check combinations
+ check(new String[]{"foo", "fo", "FOo",
"fop", "FOP", "fooo"}, "!=", "foo", new
boolean[]{false, true, false,
+ true, true, true});
+ }
- public void testLikeComparison() throws RepositoryException {
- check(new String[]{"foo", "Foo", "fOO", "FO
"},
- "like",
- "fo_",
- new boolean[]{true, true, true, true});
- check(new String[]{"foo", "Foo", "fOO",
"FOO"},
- "like",
- "f_o",
- new boolean[]{true, true, true, true});
- check(new String[]{"foo", "Foo", "fOO", "
OO"},
- "like",
- "_oo",
- new boolean[]{true, true, true, true});
- check(new String[]{"foo", "Foa", "fOO",
"FO", "foRm", "fPo", "fno", "FPo",
"Fno"},
- "like",
- "fo%",
- new boolean[]{true, true, true, true, true, false, false, false,
false});
- }
+ public void testLikeComparison() throws RepositoryException
+ {
+ check(new String[]{"foo", "Foo", "fOO", "FO
"}, "like", "fo_", new boolean[]{true, true, true, true});
+ check(new String[]{"foo", "Foo", "fOO",
"FOO"}, "like", "f_o", new boolean[]{true, true, true,
true});
+ check(new String[]{"foo", "Foo", "fOO", "
OO"}, "like", "_oo", new boolean[]{true, true, true, true});
+ check(new String[]{"foo", "Foa", "fOO",
"FO", "foRm", "fPo", "fno", "FPo",
"Fno"}, "like", "fo%", new boolean[]{
+ true, true, true, true, true, false, false, false, false});
+ }
- public void testLikeComparisonRandom() throws RepositoryException {
- String abcd = "abcd";
- Random random = new Random();
- for (int i = 0; i < 50; i++) {
- String pattern = "";
- pattern += getRandomChar(abcd, random);
- pattern += getRandomChar(abcd, random);
+ public void testLikeComparisonRandom() throws RepositoryException
+ {
+ String abcd = "abcd";
+ Random random = new Random();
+ for (int i = 0; i < 50; i++)
+ {
+ String pattern = "";
+ pattern += getRandomChar(abcd, random);
+ pattern += getRandomChar(abcd, random);
- // create 10 random values with 4 characters
- String[] values = new String[10];
- boolean[] matches = new boolean[10];
- for (int n = 0; n < 10; n++) {
- // at least the first character always matches
- String value = String.valueOf(pattern.charAt(0));
- for (int r = 1; r < 4; r++) {
- char c = getRandomChar(abcd, random);
- if (random.nextBoolean()) {
- c = Character.toUpperCase(c);
- }
- value += c;
- }
- matches[n] = value.toLowerCase().startsWith(pattern);
- values[n] = value;
+ // create 10 random values with 4 characters
+ String[] values = new String[10];
+ boolean[] matches = new boolean[10];
+ for (int n = 0; n < 10; n++)
+ {
+ // at least the first character always matches
+ String value = String.valueOf(pattern.charAt(0));
+ for (int r = 1; r < 4; r++)
+ {
+ char c = getRandomChar(abcd, random);
+ if (random.nextBoolean())
+ {
+ c = Character.toUpperCase(c);
+ }
+ value += c;
}
- pattern += "%";
- check(values, "like", pattern, matches);
- }
- }
+ matches[n] = value.toLowerCase().startsWith(pattern);
+ values[n] = value;
+ }
+ pattern += "%";
+ check(values, "like", pattern, matches);
+ }
+ }
- public void testRangeWithEmptyString() throws RepositoryException {
- check(new String[]{" ", "a", "A", "1",
"3", "!", "@"},
- ">",
- "",
- new boolean[]{true, true, true, true, true, true, true});
- check(new String[]{"", "a", "A", "1",
"3", "!", "@"},
- ">=",
- "",
- new boolean[]{true, true, true, true, true, true, true});
- check(new String[]{"", "a", "A", "1",
"3", "!", "@"},
- "<",
- "",
- new boolean[]{false, false, false, false, false, false, false});
- check(new String[]{"", "a", "A", "1",
"3", "!", "@"},
- "<=",
- "",
- new boolean[]{true, false, false, false, false, false, false});
- }
+ public void testRangeWithEmptyString() throws RepositoryException
+ {
+ check(new String[]{" ", "a", "A", "1",
"3", "!", "@"}, ">", "", new
boolean[]{true, true, true, true, true, true,
+ true});
+ check(new String[]{"", "a", "A", "1",
"3", "!", "@"}, ">=", "", new
boolean[]{true, true, true, true, true, true,
+ true});
+ check(new String[]{"", "a", "A", "1",
"3", "!", "@"}, "<", "", new
boolean[]{false, false, false, false, false,
+ false, false});
+ check(new String[]{"", "a", "A", "1",
"3", "!", "@"}, "<=", "", new
boolean[]{true, false, false, false, false,
+ false, false});
+ }
- public void testInvalidQuery() throws RepositoryException {
- try {
- executeXPathQuery("//*[fn:lower-case(@foo) = 123]", new Node[]{});
- fail("must throw InvalidQueryException");
- } catch (InvalidQueryException e) {
- // correct
- }
+ public void testInvalidQuery() throws RepositoryException
+ {
+ try
+ {
+ executeXPathQuery("//*[fn:lower-case(@foo) = 123]", new Node[]{});
+ fail("must throw InvalidQueryException");
+ }
+ catch (InvalidQueryException e)
+ {
+ // correct
+ }
- try {
- executeSQLQuery("select * from nt:base where LOWER(foo) = 123", new
Node[]{});
- fail("must throw InvalidQueryException");
- } catch (InvalidQueryException e) {
- // correct
- }
- }
+ try
+ {
+ executeSQLQuery("select * from nt:base where LOWER(foo) = 123", new
Node[]{});
+ fail("must throw InvalidQueryException");
+ }
+ catch (InvalidQueryException e)
+ {
+ // correct
+ }
+ }
- public void testWrongCaseNeverMatches() throws RepositoryException {
- Node n = testRootNode.addNode("node");
- n.setProperty("foo", "Bar");
- testRootNode.save();
- executeXPathQuery(testPath + "/*[jcr:like(fn:lower-case(@foo),
'BA%')]", new Node[]{});
- }
+ public void testWrongCaseNeverMatches() throws RepositoryException
+ {
+ Node n = testRootNode.addNode("node");
+ n.setProperty("foo", "Bar");
+ testRootNode.save();
+ executeXPathQuery(testPath + "/*[jcr:like(fn:lower-case(@foo),
'BA%')]", new Node[]{});
+ }
- //----------------------------< internal >----------------------------------
+ //----------------------------< internal >----------------------------------
- private void check(String[] values, String operation, String queryTerm, boolean[]
matches)
- throws RepositoryException {
- if (values.length != matches.length) {
- throw new IllegalArgumentException("values and matches must have same
length");
- }
- // create log message
- StringBuffer logMsg = new StringBuffer();
- logMsg.append("queryTerm: ").append(queryTerm);
- logMsg.append(" values: ");
- String separator = "";
- for (int i = 0; i < values.length; i++) {
- logMsg.append(separator);
- separator = ", ";
- if (matches[i]) {
- logMsg.append("+");
- } else {
- logMsg.append("-");
- }
- logMsg.append(values[i]);
- }
- log.println(logMsg.toString());
- for (NodeIterator it = testRootNode.getNodes(); it.hasNext();) {
- it.nextNode().remove();
- }
- Set matchingNodes = new HashSet();
- for (int i = 0; i < values.length; i++) {
- Node n = testRootNode.addNode("node" + i);
- n.setProperty(propertyName1, values[i]);
- if (matches[i]) {
- matchingNodes.add(n);
- }
- }
- testRootNode.save();
+ private void check(String[] values, String operation, String queryTerm, boolean[]
matches)
+ throws RepositoryException
+ {
+ if (values.length != matches.length)
+ {
+ throw new IllegalArgumentException("values and matches must have same
length");
+ }
+ // create log message
+ StringBuffer logMsg = new StringBuffer();
+ logMsg.append("queryTerm: ").append(queryTerm);
+ logMsg.append(" values: ");
+ String separator = "";
+ for (int i = 0; i < values.length; i++)
+ {
+ logMsg.append(separator);
+ separator = ", ";
+ if (matches[i])
+ {
+ logMsg.append("+");
+ }
+ else
+ {
+ logMsg.append("-");
+ }
+ logMsg.append(values[i]);
+ }
+ log.println(logMsg.toString());
+ for (NodeIterator it = testRootNode.getNodes(); it.hasNext();)
+ {
+ it.nextNode().remove();
+ }
+ List matchingNodes = new ArrayList();
+ for (int i = 0; i < values.length; i++)
+ {
+ Node n = testRootNode.addNode("node" + i);
+ n.setProperty(propertyName1, values[i]);
+ if (matches[i])
+ {
+ matchingNodes.add(n);
+ }
+ }
+ testRootNode.save();
- Node[] nodes = (Node[]) matchingNodes.toArray(new Node[matchingNodes.size()]);
- String sqlOperation = operation;
- if (operation.equals("!=")) {
- sqlOperation = "<>";
- }
+ Node[] nodes = (Node[])matchingNodes.toArray(new Node[matchingNodes.size()]);
+ String sqlOperation = operation;
+ if (operation.equals("!="))
+ {
+ sqlOperation = "<>";
+ }
- // run queries with lower-case
- String xpath = testPath;
- if (operation.equals("like")) {
- xpath += "/*[jcr:like(fn:lower-case(@" + propertyName1 +
- "), '" + queryTerm.toLowerCase() +
"')]";
- } else {
- xpath += "/*[fn:lower-case(@" + propertyName1 +
- ") " + operation + " '" +
queryTerm.toLowerCase() + "']";
- }
- executeXPathQuery(xpath, nodes);
+ // run queries with lower-case
+ String xpath = testPath;
+ if (operation.equals("like"))
+ {
+ xpath += "/*[jcr:like(fn:lower-case(@" + propertyName1 + "),
'" + queryTerm.toLowerCase() + "')]";
+ }
+ else
+ {
+ xpath += "/*[fn:lower-case(@" + propertyName1 + ") " +
operation + " '" + queryTerm.toLowerCase() + "']";
+ }
+ executeXPathQuery(xpath, nodes);
- String sql = "select * from nt:base where jcr:path like '" +
- testRoot + "/%' and LOWER(" + propertyName1 + ")
" +
- sqlOperation + " '" + queryTerm.toLowerCase() +
"'";
- executeSQLQuery(sql, nodes);
+ String sql =
+ "select * from nt:base where jcr:path like '" + testRoot +
"/%' and LOWER(" + propertyName1 + ") "
+ + sqlOperation + " '" + queryTerm.toLowerCase() +
"'";
+ executeSQLQuery(sql, nodes);
+ // run queries with upper-case
+ xpath = testPath;
+ if (operation.equals("like"))
+ {
+ xpath += "/*[jcr:like(fn:upper-case(@" + propertyName1 + "),
'" + queryTerm.toUpperCase() + "')]";
+ }
+ else
+ {
+ xpath += "/*[fn:upper-case(@" + propertyName1 + ") " +
operation + " '" + queryTerm.toUpperCase() + "']";
+ }
+ executeXPathQuery(xpath, nodes);
+ sql =
+ "select * from nt:base where jcr:path like '" + testRoot +
"/%' and UPPER(" + propertyName1 + ") "
+ + sqlOperation + " '" + queryTerm.toUpperCase() +
"'";
+ executeSQLQuery(sql, nodes);
- // run queries with upper-case
- xpath = testPath;
- if (operation.equals("like")) {
- xpath += "/*[jcr:like(fn:upper-case(@" + propertyName1 +
- "), '" + queryTerm.toUpperCase() +
"')]";
- } else {
- xpath += "/*[fn:upper-case(@" + propertyName1 +
- ") " + operation + " '" +
queryTerm.toUpperCase() + "']";
- }
- executeXPathQuery(xpath, nodes);
+ }
- sql = "select * from nt:base where jcr:path like '" +
- testRoot + "/%' and UPPER(" + propertyName1 + ")
" +
- sqlOperation + " '" + queryTerm.toUpperCase() +
"'";
- executeSQLQuery(sql, nodes);
+ private char getRandomChar(String pool, Random random)
+ {
+ return pool.charAt(random.nextInt(pool.length()));
+ }
-
- }
-
- private char getRandomChar(String pool, Random random) {
- return pool.charAt(random.nextInt(pool.length()));
- }
-
-// protected static int getOperatorForString(String operator) {
-// Integer i = (Integer) OPERATORS.get(operator);
-// if (i == null) {
-// throw new IllegalArgumentException("unknown operator: " +
operator);
-// }
-// return i.intValue();
-// }
+ // protected static int getOperatorForString(String operator) {
+ // Integer i = (Integer) OPERATORS.get(operator);
+ // if (i == null) {
+ // throw new IllegalArgumentException("unknown operator: " +
operator);
+ // }
+ // return i.intValue();
+ // }
}