mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- Incorporate JCR project into Repository project
- Single configuration entry point for JCR and non-JCR clients (i.e. application-context.xml) - Addition of build-war, incremental-war build targets (no deploy) - Remove build of JCR TCK war file by default git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2777 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.jcr.query;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.jcr.NodeIterator;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
import javax.jcr.nodetype.PropertyDefinition;
|
||||
import javax.jcr.query.Query;
|
||||
import javax.jcr.query.QueryResult;
|
||||
import javax.jcr.query.RowIterator;
|
||||
|
||||
import org.alfresco.jcr.item.NodeRefNodeIteratorImpl;
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.jcr.util.JCRProxyFactory;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Query Result based a NodeRef List
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class NodeRefListQueryResultImpl implements QueryResult
|
||||
{
|
||||
/** Session */
|
||||
private SessionImpl session;
|
||||
|
||||
/** The node refs in the result set */
|
||||
private List<NodeRef> nodeRefs;
|
||||
|
||||
/** Node Service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Column Names */
|
||||
private Map<QName, PropertyDefinition> columns = null;
|
||||
|
||||
/** Proxy */
|
||||
private QueryResult proxy = null;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param nodeRefs list of node references
|
||||
*/
|
||||
public NodeRefListQueryResultImpl(SessionImpl session, List<NodeRef> nodeRefs)
|
||||
{
|
||||
this.session = session;
|
||||
this.nodeRefs = nodeRefs;
|
||||
this.nodeService = session.getRepositoryImpl().getServiceRegistry().getNodeService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get proxied JCR Query Result
|
||||
*
|
||||
* @return proxy
|
||||
*/
|
||||
public QueryResult getProxy()
|
||||
{
|
||||
if (proxy == null)
|
||||
{
|
||||
proxy = (QueryResult)JCRProxyFactory.create(this, QueryResult.class, session);
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.QueryResult#getColumnNames()
|
||||
*/
|
||||
public String[] getColumnNames() throws RepositoryException
|
||||
{
|
||||
Map<QName, PropertyDefinition> columns = getColumnDefinitions();
|
||||
String[] names = new String[columns.size()];
|
||||
int i = 0;
|
||||
for (QName columnName : columns.keySet())
|
||||
{
|
||||
names[i++] = columnName.toPrefixString(session.getNamespaceResolver());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.QueryResult#getRows()
|
||||
*/
|
||||
public RowIterator getRows() throws RepositoryException
|
||||
{
|
||||
return new NodeRefRowIteratorImpl(session, getColumnDefinitions(), nodeRefs).getProxy();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.QueryResult#getNodes()
|
||||
*/
|
||||
public NodeIterator getNodes() throws RepositoryException
|
||||
{
|
||||
return new NodeRefNodeIteratorImpl(session, nodeRefs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get list of column definitions
|
||||
*
|
||||
* @return list of column definitions
|
||||
*/
|
||||
private Map<QName, PropertyDefinition> getColumnDefinitions()
|
||||
throws RepositoryException
|
||||
{
|
||||
if (columns == null)
|
||||
{
|
||||
columns = new HashMap<QName, PropertyDefinition>();
|
||||
|
||||
// build list of column names from result set
|
||||
if (nodeRefs.size() > 0)
|
||||
{
|
||||
// Base column list on first node ref
|
||||
// TODO: determine on a more formal basis
|
||||
QName type = nodeService.getType(nodeRefs.get(0));
|
||||
NodeType nodeType = session.getTypeManager().getNodeType(type.toPrefixString(session.getNamespaceResolver()));
|
||||
PropertyDefinition[] propDefs = nodeType.getPropertyDefinitions();
|
||||
for (PropertyDefinition propDef : propDefs)
|
||||
{
|
||||
if (!propDef.isMultiple())
|
||||
{
|
||||
columns.put(QName.createQName(propDef.getName(), session.getNamespaceResolver()), propDef);
|
||||
}
|
||||
}
|
||||
Set<QName>aspects = nodeService.getAspects(nodeRefs.get(0));
|
||||
for (QName aspect : aspects)
|
||||
{
|
||||
NodeType nodeAspect = session.getTypeManager().getNodeType(aspect.toPrefixString(session.getNamespaceResolver()));
|
||||
propDefs = nodeAspect.getPropertyDefinitions();
|
||||
for (PropertyDefinition propDef : propDefs)
|
||||
{
|
||||
if (!propDef.isMultiple())
|
||||
{
|
||||
columns.put(QName.createQName(propDef.getName(), session.getNamespaceResolver()), propDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add JCR required columns
|
||||
columns.put(QueryManagerImpl.JCRPATH_COLUMN, null);
|
||||
columns.put(QueryManagerImpl.JCRSCORE_COLUMN, null);
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
}
|
104
source/java/org/alfresco/jcr/query/NodeRefRowIteratorImpl.java
Normal file
104
source/java/org/alfresco/jcr/query/NodeRefRowIteratorImpl.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.jcr.query;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jcr.nodetype.PropertyDefinition;
|
||||
import javax.jcr.query.Query;
|
||||
import javax.jcr.query.Row;
|
||||
import javax.jcr.query.RowIterator;
|
||||
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.jcr.util.AbstractRangeIterator;
|
||||
import org.alfresco.jcr.util.JCRProxyFactory;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Row Iterator based on a list of Node References
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class NodeRefRowIteratorImpl extends AbstractRangeIterator implements RowIterator
|
||||
{
|
||||
private SessionImpl session;
|
||||
private Map<QName, PropertyDefinition> columns;
|
||||
private List<NodeRef> nodeRefs;
|
||||
private RowIterator proxy = null;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param session
|
||||
* @param columnNames
|
||||
* @param nodeRefs
|
||||
*/
|
||||
public NodeRefRowIteratorImpl(SessionImpl session, Map<QName, PropertyDefinition> columns, List<NodeRef> nodeRefs)
|
||||
{
|
||||
this.session = session;
|
||||
this.columns = columns;
|
||||
this.nodeRefs = nodeRefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get proxied JCR Query
|
||||
*
|
||||
* @return proxy
|
||||
*/
|
||||
public RowIterator getProxy()
|
||||
{
|
||||
if (proxy == null)
|
||||
{
|
||||
proxy = (RowIterator)JCRProxyFactory.create(this, RowIterator.class, session);
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.RowIterator#nextRow()
|
||||
*/
|
||||
public Row nextRow()
|
||||
{
|
||||
long position = skip();
|
||||
NodeRef nodeRef = nodeRefs.get((int)position);
|
||||
NodeService nodeService = session.getRepositoryImpl().getServiceRegistry().getNodeService();
|
||||
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
|
||||
return new PropertyMapRowImpl(session, columns, nodeRef, properties);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.RangeIterator#getSize()
|
||||
*/
|
||||
public long getSize()
|
||||
{
|
||||
return nodeRefs.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public Object next()
|
||||
{
|
||||
return nextRow();
|
||||
}
|
||||
|
||||
}
|
129
source/java/org/alfresco/jcr/query/PropertyMapRowImpl.java
Normal file
129
source/java/org/alfresco/jcr/query/PropertyMapRowImpl.java
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.jcr.query;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jcr.ItemNotFoundException;
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.PropertyType;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.Value;
|
||||
import javax.jcr.nodetype.PropertyDefinition;
|
||||
import javax.jcr.query.Row;
|
||||
|
||||
import org.alfresco.jcr.item.NodeImpl;
|
||||
import org.alfresco.jcr.item.ValueImpl;
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Node Ref based Row
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class PropertyMapRowImpl implements Row
|
||||
{
|
||||
private SessionImpl session;
|
||||
private Map<QName, PropertyDefinition> columns;
|
||||
private NodeRef nodeRef;
|
||||
private Map<QName, Serializable> properties;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param session
|
||||
* @param columnNames
|
||||
* @param properties
|
||||
*/
|
||||
public PropertyMapRowImpl(SessionImpl session, Map<QName, PropertyDefinition> columns, NodeRef nodeRef, Map<QName, Serializable> properties)
|
||||
{
|
||||
this.session = session;
|
||||
this.columns = columns;
|
||||
this.nodeRef = nodeRef;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.Row#getValues()
|
||||
*/
|
||||
public Value[] getValues() throws RepositoryException
|
||||
{
|
||||
Value[] values = new Value[columns.size() + 2];
|
||||
|
||||
int i = 0;
|
||||
for (QName propertyName : columns.keySet())
|
||||
{
|
||||
values[i++] = createValue(propertyName);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.Row#getValue(java.lang.String)
|
||||
*/
|
||||
public Value getValue(String propertyName) throws ItemNotFoundException, RepositoryException
|
||||
{
|
||||
QName propertyQName = QName.createQName(propertyName, session.getNamespaceResolver());
|
||||
if (!columns.containsKey(propertyQName))
|
||||
{
|
||||
throw new ItemNotFoundException("Column " + propertyName + " does not exist");
|
||||
}
|
||||
return createValue(propertyQName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Value for specified property name
|
||||
*
|
||||
* @param propertyName
|
||||
* @return
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
private Value createValue(QName propertyName)
|
||||
throws RepositoryException
|
||||
{
|
||||
Value value = null;
|
||||
if (propertyName.equals(QueryManagerImpl.JCRPATH_COLUMN))
|
||||
{
|
||||
// derive path from node ref
|
||||
Node node = new NodeImpl(session, nodeRef).getProxy();
|
||||
value = new ValueImpl(session, PropertyType.STRING, node.getPath());
|
||||
}
|
||||
else if (propertyName.equals(QueryManagerImpl.JCRSCORE_COLUMN))
|
||||
{
|
||||
// TODO:
|
||||
// create dummy score
|
||||
value = new ValueImpl(session, PropertyType.LONG, (long)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// create value from node properties
|
||||
Object objValue = properties.get(propertyName);
|
||||
if (objValue != null)
|
||||
{
|
||||
PropertyDefinition propDef = columns.get(propertyName);
|
||||
value = new ValueImpl(session, propDef.getRequiredType(), objValue);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
118
source/java/org/alfresco/jcr/query/QueryImpl.java
Normal file
118
source/java/org/alfresco/jcr/query/QueryImpl.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.jcr.query;
|
||||
|
||||
import javax.jcr.ItemExistsException;
|
||||
import javax.jcr.ItemNotFoundException;
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.PathNotFoundException;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.UnsupportedRepositoryOperationException;
|
||||
import javax.jcr.lock.LockException;
|
||||
import javax.jcr.nodetype.ConstraintViolationException;
|
||||
import javax.jcr.query.InvalidQueryException;
|
||||
import javax.jcr.query.Query;
|
||||
import javax.jcr.version.VersionException;
|
||||
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.jcr.util.JCRProxyFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Alfresco implementation of JCR Query
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public abstract class QueryImpl implements Query
|
||||
{
|
||||
/** Session */
|
||||
private SessionImpl session;
|
||||
|
||||
/** Query Statement */
|
||||
private String statement;
|
||||
|
||||
/** Proxy */
|
||||
private Query proxy = null;
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param statement query language
|
||||
*/
|
||||
public QueryImpl(SessionImpl session, String statement)
|
||||
{
|
||||
this.session = session;
|
||||
this.statement = statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get proxied JCR Query
|
||||
*
|
||||
* @return proxy
|
||||
*/
|
||||
public Query getProxy()
|
||||
{
|
||||
if (proxy == null)
|
||||
{
|
||||
proxy = (Query)JCRProxyFactory.create(this, Query.class, session);
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Session
|
||||
*
|
||||
* @return session
|
||||
*/
|
||||
public SessionImpl getSession()
|
||||
{
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the statement valid?
|
||||
*
|
||||
* @throws InvalidQueryException
|
||||
*/
|
||||
public abstract void isValidStatement() throws InvalidQueryException;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.Query#getStatement()
|
||||
*/
|
||||
public String getStatement()
|
||||
{
|
||||
return statement;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.Query#getStoredQueryPath()
|
||||
*/
|
||||
public String getStoredQueryPath() throws ItemNotFoundException, RepositoryException
|
||||
{
|
||||
throw new ItemNotFoundException("This query has not been saved to the Repository");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.Query#storeAsNode(java.lang.String)
|
||||
*/
|
||||
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException
|
||||
{
|
||||
throw new UnsupportedRepositoryOperationException();
|
||||
}
|
||||
|
||||
}
|
124
source/java/org/alfresco/jcr/query/QueryManagerImpl.java
Normal file
124
source/java/org/alfresco/jcr/query/QueryManagerImpl.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.jcr.query;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.query.InvalidQueryException;
|
||||
import javax.jcr.query.Query;
|
||||
import javax.jcr.query.QueryManager;
|
||||
|
||||
import org.alfresco.jcr.dictionary.JCRNamespace;
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
|
||||
/**
|
||||
* Alfresco implementation of JCR Query Manager
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class QueryManagerImpl implements QueryManager
|
||||
{
|
||||
public static QName JCRPATH_COLUMN = QName.createQName(JCRNamespace.JCR_URI, "path");
|
||||
public static QName JCRSCORE_COLUMN = QName.createQName(JCRNamespace.JCR_URI, "score");
|
||||
|
||||
/** supported query languages */
|
||||
private static Map<String, Class<? extends QueryImpl>> supportedLanguages = new HashMap<String, Class<? extends QueryImpl>>();
|
||||
static
|
||||
{
|
||||
supportedLanguages.put(Query.XPATH, XPathQueryImpl.class);
|
||||
}
|
||||
|
||||
private SessionImpl session;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param session session
|
||||
*/
|
||||
public QueryManagerImpl(SessionImpl session)
|
||||
{
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.QueryManager#createQuery(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public Query createQuery(String statement, String language) throws InvalidQueryException, RepositoryException
|
||||
{
|
||||
// is the language known?
|
||||
if (!isSupportedLanguage(language))
|
||||
{
|
||||
throw new InvalidQueryException("Query language " + language + " is not supported");
|
||||
}
|
||||
|
||||
// construct the query
|
||||
Class<? extends QueryImpl> queryClass = supportedLanguages.get(language);
|
||||
try
|
||||
{
|
||||
Constructor<? extends QueryImpl> constructor = queryClass.getConstructor(new Class[] { SessionImpl.class, String.class } );
|
||||
QueryImpl queryImpl = constructor.newInstance(new Object[] { session, statement } );
|
||||
queryImpl.isValidStatement();
|
||||
return queryImpl.getProxy();
|
||||
}
|
||||
catch (InstantiationException e)
|
||||
{
|
||||
throw new RepositoryException("Failed to create query " + statement + " (language: " + language + ")");
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
throw new RepositoryException("Failed to create query " + statement + " (language: " + language + ")");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RepositoryException("Failed to create query " + statement + " (language: " + language + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.QueryManager#getQuery(javax.jcr.Node)
|
||||
*/
|
||||
public Query getQuery(Node node) throws InvalidQueryException, RepositoryException
|
||||
{
|
||||
throw new InvalidQueryException("Persistent queries are not supported by the Repository.");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.QueryManager#getSupportedQueryLanguages()
|
||||
*/
|
||||
public String[] getSupportedQueryLanguages() throws RepositoryException
|
||||
{
|
||||
return supportedLanguages.keySet().toArray(new String[supportedLanguages.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is supported language?
|
||||
*
|
||||
* @param language language to check
|
||||
* @return true => supported
|
||||
*/
|
||||
private boolean isSupportedLanguage(String language)
|
||||
{
|
||||
return supportedLanguages.containsKey(language);
|
||||
}
|
||||
|
||||
}
|
87
source/java/org/alfresco/jcr/query/QueryManagerImplTest.java
Normal file
87
source/java/org/alfresco/jcr/query/QueryManagerImplTest.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package org.alfresco.jcr.query;
|
||||
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.NodeIterator;
|
||||
import javax.jcr.Property;
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
import javax.jcr.Value;
|
||||
import javax.jcr.query.Query;
|
||||
import javax.jcr.query.QueryManager;
|
||||
import javax.jcr.query.QueryResult;
|
||||
import javax.jcr.query.Row;
|
||||
import javax.jcr.query.RowIterator;
|
||||
|
||||
import org.alfresco.jcr.test.BaseJCRTest;
|
||||
|
||||
public class QueryManagerImplTest extends BaseJCRTest
|
||||
{
|
||||
|
||||
protected Session superuserSession;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
SimpleCredentials superuser = new SimpleCredentials("superuser", "".toCharArray());
|
||||
superuserSession = repository.login(superuser, getWorkspace());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
superuserSession.logout();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
public void testQuery()
|
||||
throws Exception
|
||||
{
|
||||
QueryManager queryMgr = superuserSession.getWorkspace().getQueryManager();
|
||||
String[] languages = queryMgr.getSupportedQueryLanguages();
|
||||
assertEquals(1, languages.length);
|
||||
assertEquals(Query.XPATH, languages[0]);
|
||||
|
||||
Query query = queryMgr.createQuery("//*", Query.XPATH);
|
||||
QueryResult result = query.execute();
|
||||
String[] columnNames = result.getColumnNames();
|
||||
|
||||
// iterate via row iterator
|
||||
int rowCnt = 0;
|
||||
RowIterator rowIterator = result.getRows();
|
||||
while(rowIterator.hasNext())
|
||||
{
|
||||
Row row = rowIterator.nextRow();
|
||||
for (String columnName : columnNames)
|
||||
{
|
||||
Value value = row.getValue(columnName);
|
||||
if (value != null)
|
||||
{
|
||||
String strValue = value.getString();
|
||||
assertNotNull(strValue);
|
||||
}
|
||||
}
|
||||
rowCnt++;
|
||||
}
|
||||
|
||||
// iterate via node iterator
|
||||
int nodeCnt = 0;
|
||||
NodeIterator nodeIterator = result.getNodes();
|
||||
while(nodeIterator.hasNext())
|
||||
{
|
||||
Node node = nodeIterator.nextNode();
|
||||
Property property = node.getProperty("sys:node-uuid");
|
||||
Value value = property.getValue();
|
||||
String uuid = value.getString();
|
||||
assertNotNull(uuid);
|
||||
nodeCnt++;
|
||||
}
|
||||
|
||||
// check same number of items returned from each iterator
|
||||
assertEquals(rowCnt, nodeCnt);
|
||||
}
|
||||
|
||||
|
||||
}
|
76
source/java/org/alfresco/jcr/query/XPathQueryImpl.java
Normal file
76
source/java/org/alfresco/jcr/query/XPathQueryImpl.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.jcr.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.query.InvalidQueryException;
|
||||
import javax.jcr.query.Query;
|
||||
import javax.jcr.query.QueryResult;
|
||||
|
||||
import org.alfresco.jcr.session.SessionImpl;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
|
||||
|
||||
/**
|
||||
* Alfresco implementation of XPath Query
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class XPathQueryImpl extends QueryImpl
|
||||
{
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param statement the xpath statement
|
||||
*/
|
||||
public XPathQueryImpl(SessionImpl session, String statement)
|
||||
{
|
||||
super(session, statement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isValidStatement() throws InvalidQueryException
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.Query#execute()
|
||||
*/
|
||||
public QueryResult execute() throws RepositoryException
|
||||
{
|
||||
SearchService search = getSession().getRepositoryImpl().getServiceRegistry().getSearchService();
|
||||
NodeService nodes = getSession().getRepositoryImpl().getServiceRegistry().getNodeService();
|
||||
NodeRef root = nodes.getRootNode(getSession().getWorkspaceStore());
|
||||
List<NodeRef> nodeRefs = search.selectNodes(root, getStatement(), null, getSession().getNamespaceResolver(), false, SearchService.LANGUAGE_JCR_XPATH);
|
||||
return new NodeRefListQueryResultImpl(getSession(), nodeRefs).getProxy();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.jcr.query.Query#getLanguage()
|
||||
*/
|
||||
public String getLanguage()
|
||||
{
|
||||
return Query.XPATH;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user