You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by df...@apache.org on 2005/12/13 17:27:38 UTC

svn commit: r356527 - in /jakarta/slide/trunk/src: share/org/apache/slide/store/ResourceId.java stores/org/apache/slide/index/lucene/expressions/AbstractLuceneExpression.java

Author: dflorey
Date: Tue Dec 13 08:27:30 2005
New Revision: 356527

URL: http://svn.apache.org/viewcvs?rev=356527&view=rev
Log:
Improved generation of binding uuri, 
so that folders will be generated based on 
the current date in a readable format.
Using sequence-store if available to generate unique id.
Implemented very easy scope matching for binding DASL requests

Modified:
    jakarta/slide/trunk/src/share/org/apache/slide/store/ResourceId.java
    jakarta/slide/trunk/src/stores/org/apache/slide/index/lucene/expressions/AbstractLuceneExpression.java

Modified: jakarta/slide/trunk/src/share/org/apache/slide/store/ResourceId.java
URL: http://svn.apache.org/viewcvs/jakarta/slide/trunk/src/share/org/apache/slide/store/ResourceId.java?rev=356527&r1=356526&r2=356527&view=diff
==============================================================================
--- jakarta/slide/trunk/src/share/org/apache/slide/store/ResourceId.java (original)
+++ jakarta/slide/trunk/src/share/org/apache/slide/store/ResourceId.java Tue Dec 13 08:27:30 2005
@@ -23,6 +23,9 @@
 
 package org.apache.slide.store;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Enumeration;
 import org.apache.slide.common.Namespace;
 import org.apache.slide.common.Scope;
@@ -41,249 +44,255 @@
 import org.jdom.Element;
 
 /**
- * Uniquely identifies a resource. The main operation with ResourceIds is equals. Immutable.
- *
- * Technically, ResourceId extends Uri, but the only reason to do so is compatibility with
- * existing store interfaces. Logically, a ResourceId is *not* an Uri: Uris have a structure,
- * resourceId have not. Consequently, almost all Uri methods in this class throw
- * UnsupportedOperation exceptions.
- *
- * @version   $Revision$
+ * Uniquely identifies a resource. The main operation with ResourceIds is
+ * equals. Immutable.
+ * 
+ * Technically, ResourceId extends Uri, but the only reason to do so is
+ * compatibility with existing store interfaces. Logically, a ResourceId is
+ * *not* an Uri: Uris have a structure, resourceId have not. Consequently,
+ * almost all Uri methods in this class throw UnsupportedOperation exceptions.
+ * 
+ * @version $Revision$
  */
 public final class ResourceId extends Uri {
-    
-    public static String RESOURCE_ID_SCHEMA = "urn:uuid:";
-    
-    
-    /**
-     ** There are probably no two jvm's working on the same database that initialitzing this
-     ** class at the same mill second
-     **/
-    private static final String TIMESTAMP =  String.valueOf(System.currentTimeMillis());
-    
-    /**
-     ** Number of uuri created in this JVM session
-     **/
-    private static int counter1 = 0;
-    private static int counter2 = 0;
-    
-    /**
-     * @pre  uriStr has to contain store prefix, i.e. extractStoreUri has to succeed
-     */
-    public static ResourceId createNew(Uri uri) {
-        String newUuri;
-        boolean useBinding = Configuration.useBinding(uri.getStore());
-        
-        if (useBinding) {
-            StringBuffer b = new StringBuffer();
-            b.append(uri.getScope().toString());
-            if (b.length() > 1) b.append("/");
-            
-            if (!uri.isStoreRoot()) {
-                synchronized (ResourceId.class) { 
-                    b.append(TIMESTAMP).append("/").append(counter2)
-                        .append("/") .append(counter1++);
-                    if (counter1 > 500) {
-                        counter1 = 0;
-                        counter2++;
-                    }
-                }
-            }
-            newUuri = b.toString();
-        } else {
-            newUuri = uri.toString();
-        }
-        return new ResourceId(uri, newUuri);
-    }
-    
-    public static ResourceId create(Uri uri, String uuri) {
-        return new ResourceId(uri, uuri);
-    }
-    
-    private static String resourceIdSchema(Store store) {
-        if (Configuration.useBinding(store)) {
-            return RESOURCE_ID_SCHEMA;
-        }
-        else {
-            return "";
-        }
-    }
-    
-    private final String uuri;
-    
-    /**
-     * Constructor
-     *
-     * @param    uri                 an Uri
-     * @param    id                  /scope/identifier
-     *
-     */
-    private ResourceId(Uri uri, String uuri) {
-        super(uri.getToken(), uri.getNamespace(), uri.toString());
-        this.uuri = uuri;
-        parseUuri(uuri);
-    }
-    
-    /**
-     * Tests equivalence of two ResourceIds.
-     *
-     * @param obj Object to test
-     * @return boolean
-     */
-    public boolean equals(Object obj) {
-        ResourceId resourceId;
-        
-        if (obj instanceof ResourceId) {
-            resourceId = (ResourceId) obj;
-            return getNamespace() == resourceId.getNamespace() &&
-                getStore() == resourceId.getStore() && uuri.equals(resourceId.uuri);
-        } else {
-            return false;
-        }
-    }
-    
-    public String toString() {
-        return uuri;
-    }
-    
-    /**
-     * Intentionally does not return anything like the origianl uri.
-     *
-     * @return String
-     */
-    public String getUuri() {
-        return uuri;
-    }
-    
-    /**
-     * Hash code.
-     *
-     * @return int hash code
-     */
-    public int hashCode() {
-        return this.uuri.hashCode();
-    }
-    
-    public Scope getScope() {
-        return super.getScope();
-    }
-    
-    public Store getStore() {
-        return super.getStore();
-    }
-    
-    public SlideToken getToken() {
-        return super.getToken();
-    }
-    
-    public Namespace getNamespace() {
-        return super.getNamespace();
-    }
-    
-    public boolean isStoreRoot() {
-        UriPath thisPath = new UriPath(uuri);
-        UriPath scopePath = new UriPath(scope.toString());
-        return thisPath.equals(scopePath);
-    }
-    
-    // -------------------------------------------------------------
-    
-    public void setUri(String uri) {
-        throw new UnsupportedOperationException();
-    }
-    
-    public Enumeration getScopes() {
-        throw new UnsupportedOperationException();
-    }
-    
-    
-    public void setToken(SlideToken token) {
-        throw new UnsupportedOperationException();
-    }
-    
-    public Uri getParentUri() {
-        throw new UnsupportedOperationException();
-    }
-    
-    public void invalidateServices() {
-        throw new UnsupportedOperationException();
-    }
-    
-    public void reconnectServices() {
-        throw new UnsupportedOperationException();
-    }
-    
-    public String getRelative() {
-        throw new UnsupportedOperationException();
-    }
-    
-    /**
-     * Do not clone ResourceId's, use aliasing.
-     */
-    public Uri cloneObject() {
-        throw new UnsupportedOperationException();
-    }
-    
-    public boolean isParent(Uri uri) {
-        throw new UnsupportedOperationException();
-    }
-    
-    public String asXml() {
-        XMLValue r = new XMLValue();
-        Element hrefElm = new Element("href", NodeProperty.NamespaceCache.DEFAULT_NAMESPACE);
-        hrefElm.setText(resourceIdSchema(getStore())+getUuri());
-        r.add(hrefElm);
-        return r.toString();
-    }
-    
-    /**
-     * This function is called by the constructor and when uri is changed.
-     *
-     * @param uri Uri to parse
-     */
-    protected void parseUuri(String uuri) {
-        // We first try to tokenize the uri string.
-        scopes = new ScopeTokenizer(token, namespace, uuri);
-        
-        // Find the qualifiying stuff from the registry.
-        // Then we contentStore the scope of the found Data Source
-        // within scope.
-        store = null;
-        while ((store == null) && (scopes.hasMoreElements())) {
-            Scope courScope = scopes.nextScope();
-            try {
-                if (token == null) {
-                    store = namespace.retrieveStore(courScope, null);
-                } else {
-                    store = namespace.retrieveStore(courScope, token.getCredentialsToken());
-                }
-                
-                if (store != null) {
-                    scope = courScope;
-                }
-            }
-            catch (ServiceConnectionFailedException e) {
-                throw new SlideRuntimeException(e.toString(), true);
-            }
-            catch (ServiceAccessException e) {
-                throw new SlideRuntimeException(e.toString(), true);
-            }
-        }
-        
-        // If descriptorsStore or contentStore is still null, then no valid
-        // scope is defined in the namespace ...
-        if (store == null) {
-            throw new ServiceMissingOnRootNodeException();
-        }
-    }
-    
-    /**
-     * Does nothing, overwrited the {@link Uri#parseUri(String)} method to
-     * avoid its unrequired overhead.
-     */
-    protected void parseUri(String uri) {
-       
-    }
-    
-}
 
+	public static String RESOURCE_ID_SCHEMA = "urn:uuid:";
+
+	private final static String UID_SEQUENCE_NAME = "BindingUID";
+	
+	private final static DateFormat dateFormat = new SimpleDateFormat(
+			"yyyy-MM-dd");
+
+	private final static DateFormat timeFormat = new SimpleDateFormat(
+			"HH-mm");
+
+	private static long fallbackUid = 0;
+
+	/**
+	 * @pre uriStr has to contain store prefix, i.e. extractStoreUri has to
+	 *      succeed
+	 */
+	public static ResourceId createNew(Uri uri) {
+		String newUuri;
+		boolean useBinding = Configuration.useBinding(uri.getStore());
+
+		if (useBinding) {
+			long uid;
+			try {
+				((SequenceStore) uri.getStore()).createSequence(UID_SEQUENCE_NAME);
+				uid = ((SequenceStore) uri.getStore())
+						.nextSequenceValue(UID_SEQUENCE_NAME);
+			} catch (ServiceAccessException e) {
+				uid = fallbackUid++;
+			}
+
+			StringBuffer b = new StringBuffer();
+			b.append(uri.getScope().toString());
+			if (b.length() > 1)
+				b.append("/");
+
+			if (!uri.isStoreRoot()) {
+				Date date = new Date();
+				b.append(dateFormat.format(date)).append("/").append(
+						timeFormat.format(date)).append("/").append(uid);
+			}
+			newUuri = b.toString();
+		} else {
+			newUuri = uri.toString();
+		}
+		return new ResourceId(uri, newUuri);
+	}
+
+	public static ResourceId create(Uri uri, String uuri) {
+		return new ResourceId(uri, uuri);
+	}
+
+	private static String resourceIdSchema(Store store) {
+		if (Configuration.useBinding(store)) {
+			return RESOURCE_ID_SCHEMA;
+		} else {
+			return "";
+		}
+	}
+
+	private final String uuri;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param uri
+	 *            an Uri
+	 * @param id
+	 *            /scope/identifier
+	 * 
+	 */
+	private ResourceId(Uri uri, String uuri) {
+		super(uri.getToken(), uri.getNamespace(), uri.toString());
+		this.uuri = uuri;
+		parseUuri(uuri);
+	}
+
+	/**
+	 * Tests equivalence of two ResourceIds.
+	 * 
+	 * @param obj
+	 *            Object to test
+	 * @return boolean
+	 */
+	public boolean equals(Object obj) {
+		ResourceId resourceId;
+
+		if (obj instanceof ResourceId) {
+			resourceId = (ResourceId) obj;
+			return getNamespace() == resourceId.getNamespace()
+					&& getStore() == resourceId.getStore()
+					&& uuri.equals(resourceId.uuri);
+		} else {
+			return false;
+		}
+	}
+
+	public String toString() {
+		return uuri;
+	}
+
+	/**
+	 * Intentionally does not return anything like the origianl uri.
+	 * 
+	 * @return String
+	 */
+	public String getUuri() {
+		return uuri;
+	}
+
+	/**
+	 * Hash code.
+	 * 
+	 * @return int hash code
+	 */
+	public int hashCode() {
+		return this.uuri.hashCode();
+	}
+
+	public Scope getScope() {
+		return super.getScope();
+	}
+
+	public Store getStore() {
+		return super.getStore();
+	}
+
+	public SlideToken getToken() {
+		return super.getToken();
+	}
+
+	public Namespace getNamespace() {
+		return super.getNamespace();
+	}
+
+	public boolean isStoreRoot() {
+		UriPath thisPath = new UriPath(uuri);
+		UriPath scopePath = new UriPath(scope.toString());
+		return thisPath.equals(scopePath);
+	}
+
+	// -------------------------------------------------------------
+
+	public void setUri(String uri) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Enumeration getScopes() {
+		throw new UnsupportedOperationException();
+	}
+
+	public void setToken(SlideToken token) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Uri getParentUri() {
+		throw new UnsupportedOperationException();
+	}
+
+	public void invalidateServices() {
+		throw new UnsupportedOperationException();
+	}
+
+	public void reconnectServices() {
+		throw new UnsupportedOperationException();
+	}
+
+	public String getRelative() {
+		throw new UnsupportedOperationException();
+	}
+
+	/**
+	 * Do not clone ResourceId's, use aliasing.
+	 */
+	public Uri cloneObject() {
+		throw new UnsupportedOperationException();
+	}
+
+	public boolean isParent(Uri uri) {
+		throw new UnsupportedOperationException();
+	}
+
+	public String asXml() {
+		XMLValue r = new XMLValue();
+		Element hrefElm = new Element("href",
+				NodeProperty.NamespaceCache.DEFAULT_NAMESPACE);
+		hrefElm.setText(resourceIdSchema(getStore()) + getUuri());
+		r.add(hrefElm);
+		return r.toString();
+	}
+
+	/**
+	 * This function is called by the constructor and when uri is changed.
+	 * 
+	 * @param uri
+	 *            Uri to parse
+	 */
+	protected void parseUuri(String uuri) {
+		// We first try to tokenize the uri string.
+		scopes = new ScopeTokenizer(token, namespace, uuri);
+
+		// Find the qualifiying stuff from the registry.
+		// Then we contentStore the scope of the found Data Source
+		// within scope.
+		store = null;
+		while ((store == null) && (scopes.hasMoreElements())) {
+			Scope courScope = scopes.nextScope();
+			try {
+				if (token == null) {
+					store = namespace.retrieveStore(courScope, null);
+				} else {
+					store = namespace.retrieveStore(courScope, token
+							.getCredentialsToken());
+				}
+
+				if (store != null) {
+					scope = courScope;
+				}
+			} catch (ServiceConnectionFailedException e) {
+				throw new SlideRuntimeException(e.toString(), true);
+			} catch (ServiceAccessException e) {
+				throw new SlideRuntimeException(e.toString(), true);
+			}
+		}
+
+		// If descriptorsStore or contentStore is still null, then no valid
+		// scope is defined in the namespace ...
+		if (store == null) {
+			throw new ServiceMissingOnRootNodeException();
+		}
+	}
+
+	/**
+	 * Does nothing, overwrited the {@link Uri#parseUri(String)} method to avoid
+	 * its unrequired overhead.
+	 */
+	protected void parseUri(String uri) {
+
+	}
+
+}

Modified: jakarta/slide/trunk/src/stores/org/apache/slide/index/lucene/expressions/AbstractLuceneExpression.java
URL: http://svn.apache.org/viewcvs/jakarta/slide/trunk/src/stores/org/apache/slide/index/lucene/expressions/AbstractLuceneExpression.java?rev=356527&r1=356526&r2=356527&view=diff
==============================================================================
--- jakarta/slide/trunk/src/stores/org/apache/slide/index/lucene/expressions/AbstractLuceneExpression.java (original)
+++ jakarta/slide/trunk/src/stores/org/apache/slide/index/lucene/expressions/AbstractLuceneExpression.java Tue Dec 13 08:27:30 2005
@@ -88,7 +88,7 @@
 	private IBasicResultSet resultSet = null;
 
 	private Query query;
-	
+
 	private SAXBuilder saxBuilder = new SAXBuilder();
 
 	public AbstractLuceneExpression(Index index) {
@@ -139,25 +139,9 @@
 
 		if (luceneQuery != null)
 			booleanQuery.add(luceneQuery, true, false);
-
-		booleanQuery.add(
-				new TermQuery(new Term(Index.SCOPE_FIELD_NAME, scope)), true,
-				false);
-
-		int queryScopeHrefDepth = getDepth(scope);
-
-		// add depth restriction
-		switch (q.getScope().getDepth()) {
-		case QueryScope.DEPTH_INFINITY:
-			break;
-		case QueryScope.DEPTH_0:
-			booleanQuery.add(
-					new TermQuery(new Term(Index.DEPTH_FIELD_NAME, index
-							.getConfiguration().intToIndexString(
-									getDepth(scope)))), true, false);
-			break;
-		case QueryScope.DEPTH_1:
-		default:
+		if (Configuration.useGlobalBinding()) {
+			booleanQuery.add(new TermQuery(
+					new Term(Index.SCOPE_FIELD_NAME, "/")), true, false);
 			booleanQuery
 					.add(
 							new RangeQuery(
@@ -174,7 +158,33 @@
 																			.getScope()
 																			.getDepth())),
 									true), true, false);
+		} else {
+			booleanQuery.add(new TermQuery(new Term(Index.SCOPE_FIELD_NAME,
+					scope)), true, false);
+
+			int queryScopeHrefDepth = getDepth(scope);
+
+			// add depth restriction
+			switch (q.getScope().getDepth()) {
+			case QueryScope.DEPTH_INFINITY:
+				break;
+			case QueryScope.DEPTH_0:
+				booleanQuery.add(new TermQuery(new Term(Index.DEPTH_FIELD_NAME,
+						index.getConfiguration().intToIndexString(
+								getDepth(scope)))), true, false);
+				break;
+			case QueryScope.DEPTH_1:
+			default:
+				booleanQuery.add(new RangeQuery(new Term(
+						Index.DEPTH_FIELD_NAME, index.getConfiguration()
+								.intToIndexString(getDepth(scope))), new Term(
+						Index.DEPTH_FIELD_NAME, index.getConfiguration()
+								.intToIndexString(
+										getDepth(scope)
+												+ q.getScope().getDepth())),
+						true), true, false);
 
+			}
 		}
 
 		luceneQuery = booleanQuery;
@@ -230,33 +240,55 @@
 				NodeRevisionNumber nodeNumber = new NodeRevisionNumber(number);
 				RequestedResource resource = null;
 
-				// TODO: This is just a quick hack to enable DASL with binding store
+				// TODO: This is just a quick hack to enable DASL with binding
+				// store
 				// Please replace with something less evel!
-				// At least the INDEXED_BINDING_URI_IDENTIFIER prefix should be added at indexing time
+				// At least the INDEXED_BINDING_URI_IDENTIFIER prefix should be
+				// added at indexing time
 				if (Configuration.useGlobalBinding()) {
-					resource = createResource(BindingStore.INDEXED_BINDING_URI_IDENTIFIER.substring(1) + uri, nodeNumber);
+					resource = createResource(
+							BindingStore.INDEXED_BINDING_URI_IDENTIFIER
+									.substring(1)
+									+ uri, nodeNumber);
 					if (resource != null) {
 						try {
 							NodeProperty parentProperty = resource.getProperty(
 									"parent-set",
 									NodeProperty.DEFAULT_NAMESPACE);
-							String parentValue = "<parents>"+parentProperty.getValue()+"</parents>";
+							String parentValue = "<parents>"
+									+ parentProperty.getValue() + "</parents>";
 							// Get bindings for resource
-							org.jdom.Document parentDocument = saxBuilder.build(new StringReader((String)parentValue));
-							List parents = parentDocument.getRootElement().getChildren();
-							for ( Iterator parentIterator = parents.iterator(); parentIterator.hasNext(); ) {
-								Element parent = (Element)parentIterator.next();
-								String href = parent.getChild("href", Namespace.getNamespace("DAV:")).getText();
-								String segment = parent.getChild("segment", Namespace.getNamespace("DAV:")).getText();
-								RequestedResource binding = (RequestedResource)resource.clone();
-								binding.setUri(href+"/"+segment);
-								result.add(binding);
-								counter++;
+							org.jdom.Document parentDocument = saxBuilder
+									.build(new StringReader(
+											(String) parentValue));
+							List parents = parentDocument.getRootElement()
+									.getChildren();
+							for (Iterator parentIterator = parents.iterator(); parentIterator
+									.hasNext();) {
+								Element parent = (Element) parentIterator
+										.next();
+								String href = parent.getChild("href",
+										Namespace.getNamespace("DAV:"))
+										.getText();
+								String segment = parent.getChild("segment",
+										Namespace.getNamespace("DAV:"))
+										.getText();
+								if (href.startsWith(scope)) {
+									RequestedResource binding = (RequestedResource) resource
+											.clone();
+									binding.setUri(href + "/" + segment);
+									result.add(binding);
+									counter++;
+								}
+
 							}
 						} catch (SlideException e) {
-							throw new SearchException("Property 'parent-set' must be present when using binding enabled search", e);
+							throw new SearchException(
+									"Property 'parent-set' must be present when using binding enabled search",
+									e);
 						} catch (JDOMException e) {
-							throw new SearchException("Malformed 'parent-set' property value", e);
+							throw new SearchException(
+									"Malformed 'parent-set' property value", e);
 						}
 					}
 				} else {



---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org