Skip to content

Commit

Permalink
+ improved sessionHolderProvider discovery mechanism (declarative lis…
Browse files Browse the repository at this point in the history
…t or

JDK 1.3 META-INF/services supported out-of-the-box)
+ TransactionAwareRepository added
+ refactored JcrOperations in different interfaces to mirror
+ added complete JCR exception convertor
+ changed the contract of SessionFactory interface
  • Loading branch information
costin committed Nov 11, 2005
1 parent 370c272 commit a83c00f
Show file tree
Hide file tree
Showing 24 changed files with 1,518 additions and 575 deletions.
134 changes: 78 additions & 56 deletions src/java/org/springmodules/jcr/JcrAccessor.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Created on Sep 12, 2005
*
* $Id: JcrAccessor.java,v 1.1 2005/10/21 08:17:02 costin Exp $
* $Revision: 1.1 $
* $Id: JcrAccessor.java,v 1.2 2005/11/11 15:47:11 costin Exp $
* $Revision: 1.2 $
*/
package org.springmodules.jcr;

Expand All @@ -12,11 +12,14 @@
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
import org.springmodules.jcr.support.DefaultSessionHolderProvider;
import org.springmodules.jcr.support.ServiceSessionHolderProviderManager;

/**
* Base class for JcrTemplate and JcrInterceptor, defining common properties
* like JcrSessionFactory.
* The required properties are sessionFactory.
* If the sessionHolderProvider is not set the sessionProviderManager property is used.
* If it's null the ServiceSessionHolderProviderManager will be used by default.
*
* <p>
* Not intended to be used directly. See JcrTemplate and JcrInterceptor.
Expand All @@ -27,64 +30,83 @@
*/
public abstract class JcrAccessor implements InitializingBean {

protected final Log logger = LogFactory.getLog(getClass());
protected final Log logger = LogFactory.getLog(getClass());

private SessionFactory sessionFactory;

private SessionHolderProvider sessionHolderProvider;
private SessionFactory sessionFactory;

/**
* Eagerly initialize the session holder provider, creating a default one
* if one is not set.
*/
public void afterPropertiesSet(){
if (getSessionFactory() == null) {
throw new IllegalArgumentException("jcrSessionFactory is required");
}
if (getSessionHolderProvider() == null)
setSessionHolderProvider(new DefaultSessionHolderProvider());
}
private SessionHolderProvider sessionHolderProvider;

/**
* Convert the given RepositoryException to an appropriate exception from
* the <code>org.springframework.dao</code> hierarchy.
* <p>
* May be overridden in subclasses.
*
* @param ex
* RepositoryException that occured
* @return the corresponding DataAccessException instance
*/
public DataAccessException convertJcrAccessException(RepositoryException ex) {
return SessionFactoryUtils.translateException(ex);
}
private SessionHolderProviderManager providerManager;

/**
* @return Returns the sessionFactory.
*/
public SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* Eagerly initialize the session holder provider, creating a default one
* if one is not set.
*/
public void afterPropertiesSet() {
if (getSessionFactory() == null) {
throw new IllegalArgumentException("jcrSessionFactory is required");
}
if (getSessionHolderProvider() == null) {
if (providerManager == null)
providerManager = new ServiceSessionHolderProviderManager();
// use the provider manager
setSessionHolderProvider(providerManager.getSessionProvider(sessionFactory));
}
}

/**
* @param sessionFactory The sessionFactory to set.
*/
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
/**
* Convert the given RepositoryException to an appropriate exception from
* the <code>org.springframework.dao</code> hierarchy.
* <p>
* May be overridden in subclasses.
*
* @param ex
* RepositoryException that occured
* @return the corresponding DataAccessException instance
*/
public DataAccessException convertJcrAccessException(RepositoryException ex) {
return SessionFactoryUtils.translateException(ex);
}

/**
* @return Returns the sessionHolderProvider.
*/
public SessionHolderProvider getSessionHolderProvider() {
return sessionHolderProvider;
}
/**
* @return Returns the sessionFactory.
*/
public SessionFactory getSessionFactory() {
return sessionFactory;
}

/**
* Not required - by default it uses a default session holder provider.
* @param sessionHolderProvider The sessionHolderProvider to set.
*/
public void setSessionHolderProvider(SessionHolderProvider sessionHolderProvider) {
this.sessionHolderProvider = sessionHolderProvider;
}
/**
* @param sessionFactory The sessionFactory to set.
*/
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

/**
* @return Returns the providerManager.
*/
public SessionHolderProviderManager getProviderManager() {
return providerManager;
}

/**
* @param providerManager The providerManager to set.
*/
public void setProviderManager(SessionHolderProviderManager providerManager) {
this.providerManager = providerManager;
}

/**
* @return Returns the sessionHolderProvider.
*/
public SessionHolderProvider getSessionHolderProvider() {
return sessionHolderProvider;
}

/**
* @param sessionHolderProvider The sessionHolderProvider to set.
*/
public void setSessionHolderProvider(SessionHolderProvider sessionHolderProvider) {
this.sessionHolderProvider = sessionHolderProvider;
}
}
144 changes: 144 additions & 0 deletions src/java/org/springmodules/jcr/JcrModel1Operations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package org.springmodules.jcr;

import java.util.List;
import java.util.Map;

import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.ValueFactory;
import javax.jcr.query.QueryResult;

import org.xml.sax.ContentHandler;

/**
* Interface used for delimiting Jcr operations based on what the underlying repository supports
* (in this case model 1 operations).
*
* Normally not used but useful for casting to restrict access in some situations.
* @author Costin Leau
*
*/
public interface JcrModel1Operations {

/**
* @see javax.jcr.Session#getAttribute(java.lang.String)
*/
public Object getAttribute(String name);

/**
* @see javax.jcr.Session#getAttributeNames()
*/
public String[] getAttributeNames();

/**
* @see javax.jcr.Session#getImportContentHandler(java.lang.String, int)
*/
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior);

/**
* @see javax.jcr.Session#getItem(java.lang.String)
*/
public Item getItem(String absPath);

/**
* @see javax.jcr.Session#getNamespacePrefix(java.lang.String)
*/
public String getNamespacePrefix(String uri);

/**
* @see javax.jcr.Session#getNamespacePrefixes()
*/
public String[] getNamespacePrefixes();

/**
* @see javax.jcr.Session#getNamespaceURI(java.lang.String)
*/
public String getNamespaceURI(String prefix);

/**
* @see javax.jcr.Session#getNodeByUUID(java.lang.String)
*/
public Node getNodeByUUID(String uuid);

/**
* @see javax.jcr.Session#getRootNode();
*/
public Node getRootNode();

/**
* @see javax.jcr.Session#getUserID()
*/
public String getUserID();

/**
* @see javax.jcr.Session#getValueFactory()
*/
public ValueFactory getValueFactory();

/**
* @see javax.jcr.Session#isLive()
*/
public boolean isLive();

/**
* @see javax.jcr.Session#itemExists(java.lang.String)
*/
public boolean itemExists(String absPath);

/**
* Execute a persistent query from the given node.
*
* @see javax.jcr.query.QueryManager#getQuery(javax.jcr.Node)
* @param node node to be dumped
* @return query result
*/
public QueryResult query(Node node);

/**
* Execute a query with the given strings with XPATH as default language.
* It's the same as #query(java.lang.String, java.lang.String)
*
* @see javax.jcr.query.QueryManager#createQuery(java.lang.String, java.lang.String)
* @param statement query statement
* @return query result
*/
public QueryResult query(String statement);

/**
* Execute a query with the given strings.
*
* @see javax.jcr.query.QueryManager#createQuery(java.lang.String, java.lang.String)
* @param statement query statement
* @param language language statement
* @return query result
*/
public QueryResult query(String statement, String language);

/**
* Default method for doing multiple queries. It assumes the language is
* XPATH and that errors will not be ignored.
*
* @param list a list of queries that will be executed against the
* repository
* @return a map containing the queries as keys and results as values
*/
public Map query(final List list);

/**
* Utility method for executing a list of queries against the repository.
* Reads the queries given and returns the results in a map.
*
* <p/> If possible the map will be a LinkedHashSet on JDK 1.4+, otherwise
* LinkedHashSet from Commons collections 3.1 if the package is found. If
* the above fails a HashMap will be returned.
*
* @see org.springframework.core.CollectionFactory
*
* @param list list of queries
* @param language language of the queries. If null XPATH is assumed.
* @param ignoreErrors if true it will populate unfound nodes with null
* @return a map containing the queries as keys and results as values
*/
public Map query(final List list, final String language, final boolean ignoreErrors);

}
85 changes: 85 additions & 0 deletions src/java/org/springmodules/jcr/JcrModel2Operations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.springmodules.jcr;

import java.io.File;
import java.io.InputStream;

import javax.jcr.Node;


/**
* Interface used for delimiting Jcr operations based on what the underlying repository supports (in this
* case model 2 operations).
* Normally not used but useful for casting to restrict access in some situations.
*
* @author Costin Leau
*
*/
public interface JcrModel2Operations extends JcrModel1Operations {

/**
* Import a File in the current workspace on the given node. If the
* parentNode is null the root node will be used.
*
* <strong>Note</strong> this method has been mainly inspired from the
* contrib/examples package inside JackRabbit repository.
*
* @param parentNode
* Parent Repository Node
* @param file
* File to be imported
*
* @return the child node to which the file belongs to
*/
public Node importFile(Node parentNode, File file);

/**
* Import a Folder using the current session on the given node. If the
* parentNode is null the root node will be used.
*
* <strong>Note</strong> this method has been mainly inspired from the
* contrib/examples package inside JackRabbit repository.
*
* @param parentnode
* Parent Repository Node
* @param directory
* Directory to be traversed
* @param includeStartDir
* true if the given directory should be included or just it's
* entries
*/

public Node importFolder(Node parentnode, File directory, boolean includeStartDirectory);

/**
* @see javax.jcr.Session#hasPendingChanges()
*/
public boolean hasPendingChanges();

/**
* @see javax.jcr.Session#importXML(java.lang.String, java.io.InputStream,
* int)
*/
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior);

/**
* @see javax.jcr.Session#refresh(boolean)
*/
public void refresh(boolean keepChanges);

/**
* @see javax.jcr.Session#setNamespacePrefix(java.lang.String,
* java.lang.String)
*/
public void setNamespacePrefix(String prefix, String uri);

/**
* @see javax.jcr.Session#move(java.lang.String, java.lang.String)
*/
public void move(String srcAbsPath, String destAbsPath);

/**
* @see javax.jcr.Session#save()
*/
public void save();

}
Loading

0 comments on commit a83c00f

Please sign in to comment.