jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r779228 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ nodetype/ query/lucene/ query/lucene/constraint/
Date Wed, 27 May 2009 16:18:21 GMT
Author: stefan
Date: Wed May 27 16:18:21 2009
New Revision: 779228

URL: http://svn.apache.org/viewvc?rev=779228&view=rev
Log:
JCR-1609:  new Property Types (WIP...)



Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ItemImpl.java
Wed May 27 16:18:21 2009
@@ -506,12 +506,18 @@
                          * be checked)
                          */
                         if (constraints.length > 0
-                                && propDef.getRequiredType() == PropertyType.REFERENCE)
{
+                                && (propDef.getRequiredType() == PropertyType.REFERENCE
+                                    || propDef.getRequiredType() == PropertyType.WEAKREFERENCE))
{
                             for (int i = 0; i < values.length; i++) {
                                 boolean satisfied = false;
                                 String constraintViolationMsg = null;
                                 try {
                                     UUID targetUUID = values[i].getUUID();
+                                    if (propDef.getRequiredType() == PropertyType.WEAKREFERENCE
+                                        && !itemMgr.itemExists(new NodeId(targetUUID)))
{
+                                        // target of weakref doesn;t exist, skip
+                                        continue;
+                                    }
                                     Node targetNode = session.getNodeByUUID(targetUUID);
                                     /**
                                      * constraints are OR-ed, i.e. at least one
@@ -519,7 +525,7 @@
                                      */
                                     for (int j = 0; j < constraints.length; j++) {
                                         /**
-                                         * a REFERENCE value constraint specifies
+                                         * a [WEAK]REFERENCE value constraint specifies
                                          * the name of the required node type of
                                          * the target node
                                          */
@@ -547,7 +553,9 @@
                                     }
                                 } catch (RepositoryException re) {
                                     String msg = itemMgr.safeGetJCRPath(propId)
-                                            + ": failed to check REFERENCE value constraint";
+                                            + ": failed to check "
+                                            + ((propDef.getRequiredType() == PropertyType.REFERENCE)
? "REFERENCE" : "WEAKREFERENCE")
+                                            + " value constraint";
                                     log.debug(msg);
                                     throw new ConstraintViolationException(msg, re);
                                 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Wed May 27 16:18:21 2009
@@ -4594,6 +4594,7 @@
         try {
             Query q = session.getWorkspace().getQueryManager().createQuery(
                     "//*[jcr:contains(., '" + data.getId() + "')]",
+                    //"//*[@*='" + data.getId() + "']",
                     Query.XPATH);
             QueryResult result = q.execute();
             ArrayList l = new ArrayList<Property>();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Wed May 27 16:18:21 2009
@@ -557,19 +557,19 @@
     }
 
     public BigDecimal getDecimal() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException("JCR-1609");
+        return getValue().getDecimal();
     }
 
     public void setValue(BigDecimal value) throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException("JCR-1609");
+        setValue(session.getValueFactory().createValue(value));
     }
 
     public Binary getBinary() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException("JCR-2056");
+        return getValue().getBinary();
     }
 
     public void setValue(Binary value) throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException("JCR-2056");
+        setValue(session.getValueFactory().createValue(value));
     }
 
     public void setValue(Calendar value) throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeDef.java
Wed May 27 16:18:21 2009
@@ -104,8 +104,9 @@
             // property definitions
             for (Iterator iter = propDefs.iterator(); iter.hasNext();) {
                 PropDef pd = (PropDef) iter.next();
-                // REFERENCE value constraints
-                if (pd.getRequiredType() == PropertyType.REFERENCE) {
+                // [WEAK]REFERENCE value constraints
+                if (pd.getRequiredType() == PropertyType.REFERENCE
+                        || pd.getRequiredType() == PropertyType.WEAKREFERENCE) {
                     ValueConstraint[] ca = pd.getValueConstraints();
                     if (ca != null) {
                         for (int j = 0; j < ca.length; j++) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
Wed May 27 16:18:21 2009
@@ -1576,13 +1576,16 @@
                  * the specified node type must be registered, with one notable
                  * exception: the node type just being registered
                  */
-                if (pd.getRequiredType() == PropertyType.REFERENCE) {
+                if (pd.getRequiredType() == PropertyType.REFERENCE
+                        || pd.getRequiredType() == PropertyType.WEAKREFERENCE) {
                     for (int j = 0; j < constraints.length; j++) {
                         ReferenceConstraint rc = (ReferenceConstraint) constraints[j];
                         Name ntName = rc.getNodeTypeName();
                         if (!name.equals(ntName) && !ntdCache.containsKey(ntName))
{
                             String msg = "[" + name + "#" + pd.getName()
-                                    + "] invalid REFERENCE value constraint '"
+                                    + "] invalid "
+                                    + (pd.getRequiredType() == PropertyType.REFERENCE ? "REFERENCE"
: "WEAKREFERENCE") 
+                                    + " value constraint '"
                                     + ntName + "' (unknown node type)";
                             log.debug(msg);
                             throw new InvalidNodeTypeDefException(msg);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/ValueConstraint.java
Wed May 27 16:18:21 2009
@@ -698,20 +698,24 @@
         }
         switch (value.getType()) {
             case PropertyType.REFERENCE:
-                // @todo check REFERENCE value constraint (requires a session)
+            case PropertyType.WEAKREFERENCE:
+                // @todo check [WEAK]REFERENCE value constraint (requires a session)
 /*
                 UUID targetUUID = (UUID) value.internalValue();
+                if (value.getType() == PropertyType.WEAKREFERENCE && !session.itemExists(new
NodeId(targetUUID))) {
+                    return;
+                }
                 NodeImpl targetNode = (NodeImpl) session.getNodeByUUID(targetUUID.toString());
                 if (!targetNode.isNodeType(ntName)) {
                     throw new ConstraintViolationException("the node with uuid "
                             + targetUUID + " does not satisfy the constraint '" + definition
+ "'");
                 }
 */
-                log.info("validation of REFERENCE constraint is not yet implemented");
+                log.info("validation of [WEAK]REFERENCE constraint is not yet implemented");
                 return;
 
             default:
-                String msg = "REFERENCE constraint can not be applied to value of type: "
+                String msg = "[WEAK]REFERENCE constraint can not be applied to value of type:
"
                         + PropertyType.nameFromValue(value.getType());
                 log.debug(msg);
                 throw new RepositoryException(msg);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
Wed May 27 16:18:21 2009
@@ -50,6 +50,7 @@
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Date;
+import java.net.URI;
 
 /**
  * Creates a lucene <code>Document</code> object from a {@link javax.jcr.Node}.
@@ -321,7 +322,12 @@
                 break;
             case PropertyType.REFERENCE:
                 if (isIndexed(name)) {
-                    addReferenceValue(doc, fieldName, value.getUUID());
+                    addReferenceValue(doc, fieldName, value.getUUID(), false);
+                }
+                break;
+            case PropertyType.WEAKREFERENCE:
+                if (isIndexed(name)) {
+                    addReferenceValue(doc, fieldName, value.getUUID(), true);
                 }
                 break;
             case PropertyType.PATH:
@@ -329,6 +335,11 @@
                     addPathValue(doc, fieldName, value.getPath());
                 }
                 break;
+            case PropertyType.URI:
+                if (isIndexed(name)) {
+                    addURIValue(doc, fieldName, value.getURI());
+                }
+                break;
             case PropertyType.STRING:
                 if (isIndexed(name)) {
                     // never fulltext index jcr:uuid String
@@ -351,8 +362,11 @@
                     addNameValue(doc, fieldName, value.getQName());
                 }
                 break;
+            // TODO support indexing of BigDecimal (JCR-1609: new Property Types)
+            case PropertyType.DECIMAL:
+
             default:
-                throw new IllegalArgumentException("illegal internal value type");
+                throw new IllegalArgumentException("illegal internal value type: " + value.getType());
         }
 
         // add length
@@ -549,12 +563,13 @@
      * @param doc           The document to which to add the field
      * @param fieldName     The name of the field to add
      * @param internalValue The value for the field to add to the document.
+     * @param weak          Flag indicating whether it's a WEAKREFERENCE (true) or a REFERENCE
(flase)
      */
-    protected void addReferenceValue(Document doc, String fieldName, Object internalValue)
{
+    protected void addReferenceValue(Document doc, String fieldName, Object internalValue,
boolean weak) {
         UUID value = (UUID) internalValue;
         String uuid = value.toString();
         doc.add(createFieldWithoutNorms(fieldName, uuid,
-                PropertyType.REFERENCE));
+                weak ? PropertyType.WEAKREFERENCE : PropertyType.REFERENCE));
         doc.add(new Field(FieldNames.PROPERTIES,
                 FieldNames.createNamedValue(fieldName, uuid),
                 Field.Store.YES, Field.Index.NO, Field.TermVector.NO));
@@ -582,6 +597,19 @@
     }
 
     /**
+     * Adds the uri value to the document as the named field.
+     *
+     * @param doc           The document to which to add the field
+     * @param fieldName     The name of the field to add
+     * @param internalValue The value for the field to add to the document.
+     */
+    protected void addURIValue(Document doc, String fieldName, Object internalValue) {
+        URI uri = (URI) internalValue;
+        doc.add(createFieldWithoutNorms(fieldName, uri.toString(),
+                PropertyType.URI));
+    }
+
+    /**
      * Adds the string value to the document both as the named field and for
      * full text indexing.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
Wed May 27 16:18:21 2009
@@ -28,6 +28,7 @@
 import java.util.Iterator;
 import java.util.regex.Pattern;
 import java.io.IOException;
+import java.math.BigDecimal;
 
 import javax.jcr.PropertyType;
 import javax.jcr.Value;
@@ -152,14 +153,17 @@
                 return new Double(value.getDouble());
             case PropertyType.LONG:
                 return new Long(value.getLong());
+            case PropertyType.DECIMAL:
+                return value.getDecimal();
             case PropertyType.NAME:
                 return value.getName().toString();
             case PropertyType.PATH:
                 return value.getPath().toString();
+            case PropertyType.URI:
+            case PropertyType.WEAKREFERENCE:
             case PropertyType.REFERENCE:
             case PropertyType.STRING:
                 return value.getString();
-            // TODO: JSR 283 adds new property types
             default:
                 return null;
         }
@@ -187,8 +191,12 @@
                 return new Double(value.getDouble());
             case PropertyType.LONG:
                 return new Long(value.getLong());
+            case PropertyType.DECIMAL:
+                return value.getDecimal();
             case PropertyType.NAME:
             case PropertyType.PATH:
+            case PropertyType.URI:
+            case PropertyType.WEAKREFERENCE:
             case PropertyType.REFERENCE:
             case PropertyType.STRING:
                 return value.getString();
@@ -263,13 +271,17 @@
             case PropertyType.LONG:
                 c2 = new Long(v2.getLong());
                 break;
+            case PropertyType.DECIMAL:
+                c2 = v2.getDecimal();
+                break;
             case PropertyType.NAME:
             case PropertyType.PATH:
             case PropertyType.REFERENCE:
+            case PropertyType.WEAKREFERENCE:
+            case PropertyType.URI:
             case PropertyType.STRING:
                 c2 = v2.getString();
                 break;
-                // TODO: JSR 283 now node types
             default:
                 throw new RepositoryException("Unsupported type: "
                         + PropertyType.nameFromValue(v2.getType()));

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java?rev=779228&r1=779227&r2=779228&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
Wed May 27 16:18:21 2009
@@ -259,12 +259,12 @@
                     break;
                 case PropertyType.DATE:
                 case PropertyType.DOUBLE:
-                    // TODO case PropertyType.DECIMAL:
+                    // TODO case PropertyType.DECIMAL: // JCR-1609
                 case PropertyType.LONG:
                 case PropertyType.BOOLEAN:
                 case PropertyType.REFERENCE:
-                // TODO case PropertyType.WEAKREFERENCE:
-                // TODO case PropertyType.URI
+                // TODO case PropertyType.WEAKREFERENCE: // JCR-1609
+                // TODO case PropertyType.URI // JCR-1609
                     throw new InvalidQueryException(staticValue.getString() +
                             " cannot be converted into a NAME value");
             }



Mime
View raw message