Author: mic...@jb... Date: 2005-12-28 00:15:43 -0500 (Wed, 28 Dec 2005) New Revision: 1943 Removed: trunk/labs/jbossrules/drools-repository/conf/jaas.config trunk/labs/jbossrules/drools-repository/conf/repository.xml trunk/labs/jbossrules/drools-repository/doc/RepositorySpec.odt trunk/labs/jbossrules/drools-repository/doc/model.vsd trunk/labs/jbossrules/drools-repository/lib/commons-collections-3.1.jar trunk/labs/jbossrules/drools-repository/lib/concurrent-1.3.4.jar trunk/labs/jbossrules/drools-repository/lib/derby-10.1.1.0.jar trunk/labs/jbossrules/drools-repository/lib/geronimo-spec-jta-1.0-M1.jar trunk/labs/jbossrules/drools-repository/lib/jackrabbit-1.0-SNAPSHOT.jar trunk/labs/jbossrules/drools-repository/lib/jcr-1.0.jar trunk/labs/jbossrules/drools-repository/lib/junit-3.8.1.jar trunk/labs/jbossrules/drools-repository/lib/log4j-1.2.8.jar trunk/labs/jbossrules/drools-repository/lib/lucene-1.4.3.jar trunk/labs/jbossrules/drools-repository/lib/xercesImpl-2.6.2.jar trunk/labs/jbossrules/drools-repository/lib/xmlParserAPIs-2.0.2.jar trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/DRLSourceFile.java trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/DublinCore.java trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/RuleDefinition.java trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RepositoryService.java trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RepositoryServiceFactory.java trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RuleRepositoryException.java trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/jcr/JCRSessionUtil.java trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/jcr/RepositoryServiceImpl.java trunk/labs/jbossrules/drools-repository/src/test/org/drools/repo/jcr/RepositoryServiceImplTest.java Log: Deleted: trunk/labs/jbossrules/drools-repository/conf/jaas.config =================================================================== --- trunk/labs/jbossrules/drools-repository/conf/jaas.config 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/conf/jaas.config 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,3 +0,0 @@ -Jackrabbit { - org.apache.jackrabbit.core.security.SimpleLoginModule required anonymousId="anonymous"; -}; \ No newline at end of file Deleted: trunk/labs/jbossrules/drools-repository/conf/repository.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/conf/repository.xml 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/conf/repository.xml 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<Repository> - <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem"> - <param name="path" value="${rep.home}/repository"/> - </FileSystem> - <Security appName="Jackrabbit"> - <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager"/> - </Security> - <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" /> - <Workspace name="${wsp.name}"> - <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem"> - <param name="path" value="${wsp.home}"/> - </FileSystem> - <PersistenceManager class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager" /> - <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex"> - <param name="path" value="${wsp.home}/index"/> - </SearchIndex> - </Workspace> - <Versioning rootPath="${rep.home}/versions"> - <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem"> - <param name="path" value="${rep.home}/versions"/> - </FileSystem> - <PersistenceManager class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager" /> - </Versioning> -</Repository> \ No newline at end of file Deleted: trunk/labs/jbossrules/drools-repository/doc/RepositorySpec.odt =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/doc/model.vsd =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/commons-collections-3.1.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/concurrent-1.3.4.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/derby-10.1.1.0.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/geronimo-spec-jta-1.0-M1.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/jackrabbit-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/jcr-1.0.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/junit-3.8.1.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/log4j-1.2.8.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/lucene-1.4.3.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/xercesImpl-2.6.2.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/lib/xmlParserAPIs-2.0.2.jar =================================================================== (Binary files differ) Deleted: trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/DRLSourceFile.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/DRLSourceFile.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/DRLSourceFile.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,32 +0,0 @@ -package org.drools.metamodel; - -/** - * This represents the content for a ruleset which is managed as one unit. - * @author <a href="mailto:mic...@gm..."> Michael Neale</a> - * - */ -public class DRLSourceFile -{ - - private String content; - private String name; - - public DRLSourceFile(String content, String name) { - this.name = name; - this.content = content; - - } - - public String getContent() - { - return content; - } - - public void setContent(String content) - { - this.content = content; - } - - - -} Deleted: trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/DublinCore.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/DublinCore.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/DublinCore.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,155 +0,0 @@ -package org.drools.metamodel; - -/** - * This is based on the <a href="http://dublincore.org/documents/dces/"> Dublin - * Core</a> specification, plus a little bit more, and a little bit less. Not - * all of these fields will be used. - */ -public class DublinCore -{ - - private String title; - private String creator; - private String subject; - private String description; - private String publisher; - private String contributor; - private java.util.Date dateCreated; - private String format; - private String source; - private String language; - private String relation; - private String coverage; - private String rights; - - public String getContributor() - { - return contributor; - } - - public void setContributor(String contributor) - { - this.contributor = contributor; - } - - public String getCoverage() - { - return coverage; - } - - public void setCoverage(String coverage) - { - this.coverage = coverage; - } - - public String getCreator() - { - return creator; - } - - public void setCreator(String creator) - { - this.creator = creator; - } - - public java.util.Date getDateCreated() - { - return dateCreated; - } - - public void setDateCreated(java.util.Date dateCreated) - { - this.dateCreated = dateCreated; - } - - public String getDescription() - { - return description; - } - - public void setDescription(String description) - { - this.description = description; - } - - public String getFormat() - { - return format; - } - - public void setFormat(String format) - { - this.format = format; - } - - public String getLanguage() - { - return language; - } - - public void setLanguage(String language) - { - this.language = language; - } - - public String getName() - { - return title; - } - - public void setName(String name) - { - this.title = name; - } - - public String getPublisher() - { - return publisher; - } - - public void setPublisher(String publisher) - { - this.publisher = publisher; - } - - public String getRelation() - { - return relation; - } - - public void setRelation(String relation) - { - this.relation = relation; - } - - public String getRights() - { - return rights; - } - - public void setRights(String rights) - { - this.rights = rights; - } - - public String getSource() - { - return source; - } - - public void setSource(String source) - { - this.source = source; - } - - public String getSubject() - { - return subject; - } - - public void setSubject(String subject) - { - this.subject = subject; - } - -} Deleted: trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/RuleDefinition.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/RuleDefinition.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/main/org/drools/metamodel/RuleDefinition.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,45 +0,0 @@ -package org.drools.metamodel; - -public class RuleDefinition -{ - private String ruleName; - private String fragment; - - - public String getFragment() - { - return fragment; - } - - public RuleDefinition(String ruleName, - String fragment){ - super( ); - // TODO Auto-generated constructor stub - this.ruleName = ruleName; - this.fragment = fragment; - - } - - public void setFragment(String fragment) - { - this.fragment = fragment; - } - - - - - public String getRuleName() - { - return ruleName; - } - - public void setRuleName(String ruleName) - { - this.ruleName = ruleName; - } - - public RuleDefinition() {} - - - -} Deleted: trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RepositoryService.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RepositoryService.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RepositoryService.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,133 +0,0 @@ -package org.drools.repo; - -import java.util.List; -import java.util.Properties; - -import org.drools.metamodel.RuleDefinition; - - - -public interface RepositoryService -{ - /** - * Nodes are represented with a "drools:..." prefix to prevent namespace collisions for people - * using a shared repository (shared with a CMS for instance). - */ - public static final String RULE_NAMESPACE_PREFIX = "drools"; - public static final String RULE_NAMESPACE = "http://www.drools.org/repo"; - - - /** - * This will mark the asset as checked out by the current user. - * - * The idea is to prevent anyone else working on it at the same time. - * Assets needs to be checked out, so when they are checked in their versions are updated. - * This may also lock the asset, not sure... - * Can provide seperate explicit lock methods if needed. - */ -// public RuleSetFile checkoutFile(String ruleBaseName, String ruleSetName); -// public RuleSetConfig checkoutRuleSetConfig(String ruleBaseName, String ruleSetName); -// public Rule checkoutRule(String ruleBaseName, String ruleSetName, String ruleName); - - - /** - * These methods add brand new assets to the repository. - * Exceptions thrown if you don't fill out the right stuff etc. - * The names must be unique of course, or exceptions will be thrown. - */ -// public RuleSetFile addNewFile(String ruleBaseName, RuleSetFile file); -// public RuleSet addNewRuleSet(String ruleBaseName, RuleSet ruleSet); -// public Rule addNewRule(String ruleBaseName, String ruleSetName, Rule rule); - - -// /** -// * This method updates the asset in the repository, and -// * increment the version number etc. -// * If someone else beat you to it, it will chuck a wobbly. Whereby you -// * can tell the poor user, they are going to have to find out who it was, -// * and throw a phone at their heads, russle crowe style. -// * Of course, with checkouts, it should stop anyone else checking it out. -// */ -// public VersionInfo checkin(Asset asset, String comment); -// -// /** -// * This will change the status flag on the latest version of the asset. -// * It will make sure that your version is up to date before allowing it. -// */ -// public VersionInfo changeStatus(Asset asset, String newStatus); -// -// -// /** -// * Returns a list of rulebase names in the repository. -// */ -// public List listRuleBaseName(); -// -// -// /** -// * This returns a list of rule-set names for a given rulebase. -// */ -// public List listRuleSetNames(String ruleBase); -// -// -// /** -// * This will deeply load the whole RuleSet. -// */ -// public RuleSet retrieveRuleSet(String ruleBaseName, String ruleSetName); - -// -// /** -// * This will load a RuleSetFile. -// */ -// public RuleSetFile retrieveRuleSetFile(String ruleBaseName, String ruleSetName); - - -// /** -// * Haven't really defined how to search for things, -// * but will be on most fields. -// * Can return a list of assets that match, which could be rules, rulesets etc... -// * Probably need some canned queries, as well as some XPath ones. -// * Can do things like search for rules modified on a certain date, in various states etc. -// * TODO: get a list of basic functionality to support. -// */ -// public List searchRules(Properties searchProperties); - - - - /** - * Sets up a virgin repository. Only needs to be called once. - */ - public void createNewRepo(); - - /** - * This will add a new rule to the repository. - * If it already exists, and exception will be thrown. - * You need to explicitly checkin a new version of a rule. This - * method is only for adding a brand new rule. - * - * The RuleBase and RuleSet will be implicitly created if they don't already exist. - */ - public RuleDefinition addNewRule(String ruleBase, String ruleSet, RuleDefinition rule); - - /** - * This will permanently delete a rule. - * Only use when you really don't want it anymore. - */ - public void removeRule(String ruleBase, String ruleSet, String ruleName); - - /** Retrieve a rule */ - public RuleDefinition retrieveRule(String ruleBase, String ruleSet, String ruleName); - - - /** - * This will remove a ruleset, and all the contained rules. - */ - public void removeRuleSet(String ruleBase, String ruleSet); - - /** - * Applies changes that were made. - * Some actions have implicit saves, but it is best to - */ - public void save(); - - -} Deleted: trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RepositoryServiceFactory.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RepositoryServiceFactory.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RepositoryServiceFactory.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,31 +0,0 @@ -package org.drools.repo; - -import javax.jcr.RepositoryException; -import javax.naming.NamingException; - -import org.drools.repo.jcr.JCRSessionUtil; -import org.drools.repo.jcr.RepositoryServiceImpl; - -public class RepositoryServiceFactory -{ - - public static RepositoryService getRepositoryService() { - JCRSessionUtil factory = new JCRSessionUtil(); - RepositoryService service = null; - try - { - service = new RepositoryServiceImpl(factory.getSession()); - } - catch ( NamingException e ) - { - throw new RuleRepositoryException(e); - } - catch ( RepositoryException e ) - { - throw new RuleRepositoryException(e); - } - return service; - } - - -} Deleted: trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RuleRepositoryException.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RuleRepositoryException.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/RuleRepositoryException.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,17 +0,0 @@ -package org.drools.repo; - -public class RuleRepositoryException extends RuntimeException -{ - public RuleRepositoryException(Throwable cause) { - super(cause); - } - - public RuleRepositoryException(String message, Throwable cause) { - super(message, cause); - } - - public RuleRepositoryException(String message) { - super(message); - } - -} Deleted: trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/jcr/JCRSessionUtil.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/jcr/JCRSessionUtil.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/jcr/JCRSessionUtil.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,73 +0,0 @@ -package org.drools.repo.jcr; - -import java.util.Hashtable; - -import javax.jcr.Repository; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.SimpleCredentials; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; - -import org.apache.jackrabbit.core.jndi.RegistryHelper; - -/** - * This is a dirty hack of a class while I get the hang of using JCR in and - * outside of containers. - * @author <a href="mailto:mic...@gm..."> Michael Neale</a> - * - */ -public class JCRSessionUtil -{ - - public static final String REPO_JNDI_NAME = "repo"; - - /** - * At the moment this is all hard coded to be un-authenticated and local - * It is looking for a jaas.config, as well as the repository.xml to setup the repository. - * @return - * @throws NamingException - * @throws RepositoryException - */ - public Session getSession() throws NamingException, RepositoryException { - - - System.setProperty("java.security.auth.login.config", "c:/jaas.config"); - String configFile = "conf/repository.xml"; - String repHomeDir = "drools-repository"; - - Hashtable env = new Hashtable( ); - env.put( Context.INITIAL_CONTEXT_FACTORY, - "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory" ); - env.put( Context.PROVIDER_URL, - "localhost" ); - - InitialContext ctx = new InitialContext( env ); - - registerNewRepoInJNDI( configFile, - repHomeDir, - ctx ); - Repository r = (Repository) ctx.lookup( REPO_JNDI_NAME ); - - Session session = r.login( new SimpleCredentials( "userid", - "".toCharArray( ) ), - null ); - return session; - - } - - private void registerNewRepoInJNDI(String configFile, - String repHomeDir, - InitialContext ctx) throws NamingException, - RepositoryException - { - //configure repo, if its not already - RegistryHelper.registerRepository( ctx, - REPO_JNDI_NAME, - configFile, - repHomeDir, - true ); - } - -} Deleted: trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/jcr/RepositoryServiceImpl.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/jcr/RepositoryServiceImpl.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/main/org/drools/repo/jcr/RepositoryServiceImpl.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,296 +0,0 @@ -package org.drools.repo.jcr; - -import java.util.ArrayList; -import java.util.List; - -import javax.jcr.ItemExistsException; -import javax.jcr.NamespaceRegistry; -import javax.jcr.Node; -import javax.jcr.NodeIterator; -import javax.jcr.PathNotFoundException; -import javax.jcr.RepositoryException; -import javax.jcr.Session; -import javax.jcr.lock.LockException; -import javax.jcr.nodetype.ConstraintViolationException; -import javax.jcr.version.VersionException; - -import org.drools.metamodel.DRLSourceFile; -import org.drools.metamodel.RuleDefinition; -import org.drools.repo.RepositoryService; -import org.drools.repo.RuleRepositoryException; - -public class RepositoryServiceImpl - implements - RepositoryService { - private Session session; - - public RepositoryServiceImpl(Session session){ - this.session = session; - - } - - public void createNamespace(){ - try { - NamespaceRegistry reg = this.session.getWorkspace( ).getNamespaceRegistry( ); - if ( nameSpaceExists( reg ) ) { - return; - } - else { - log( "Registering new Namespace" ); - reg.registerNamespace( RepositoryService.RULE_NAMESPACE_PREFIX, - RepositoryService.RULE_NAMESPACE ); - } - } - catch ( RepositoryException e ) { - throw new RuleRepositoryException( e ); - } - - } - - /** - * This will create a brand new repository. All rules are stored in the - * drools:repository node. - */ - public void createNewRepo(){ - createNamespace( ); - createRuleRepoNode( ); - } - - /** - * This creates the root drools repository node, if it doesn't already - * exist. - * - */ - private void createRuleRepoNode(){ - try { - Node rn = this.session.getRootNode( ); - if ( !rn.hasNode( nodeNameOf( "repository" ) ) ) { - this.session.getRootNode( ).addNode( nodeNameOf( "repository" ) ); - } - } - catch ( Exception e ) { - throw new RuleRepositoryException( "Unable to create new repository root node.", - e ); - } - } - - private String nodeNameOf(String string){ - return RepositoryService.RULE_NAMESPACE_PREFIX + ":" + string; - } - - private void log(String string){ - System.out.println( "REPO:" + string ); - } - - private boolean nameSpaceExists(NamespaceRegistry registry) throws RepositoryException{ - String[] uris = registry.getURIs( ); - for ( int i = 0; i < uris.length; i++ ) { - if ( uris[i].equals( RepositoryService.RULE_NAMESPACE ) ) { - log( "Name space already exists." ); - return true; - } - } - return false; - - } - - public void xxxxsaveNewRuleset(String name, - String content){ - Node repo = getRepository( ); - try { - Node ruleset = repo.addNode( nodeNameOf( "ruleset" ) ); - ruleset.setProperty( "content", - content ); - ruleset.setProperty( "ruleset-name", - name ); - session.save( ); - } - catch ( Exception e ) { - throw new RuleRepositoryException( "Unable to add a new Ruleset called: " + name, - e ); - } - } - - private Node getRepository(){ - try { - return session.getRootNode( ).getNode( nodeNameOf( "repository" ) ); - } - catch ( PathNotFoundException e ) { - throw new RuleRepositoryException( "Unable to find repository root node. Repository may not have been setup correctly.", - e ); - } - catch ( RepositoryException e ) { - throw new RuleRepositoryException( e ); - } - } - - public List xxxxfindAllRuleSetDRL(){ - List rulesets = new ArrayList( ); - Node repo = getRepository( ); - try { - NodeIterator nodeIt = repo.getNodes( ); - while ( nodeIt.hasNext( ) ) { - Node rulesetNode = nodeIt.nextNode( ); - String content = rulesetNode.getProperty( "content" ).getString( ); - String name = rulesetNode.getProperty( "ruleset-name" ).getString( ); - DRLSourceFile drl = new DRLSourceFile( content, - name ); - rulesets.add( drl ); - } - } - catch ( RepositoryException e ) { - throw new RuleRepositoryException( "Unable to list rulesets.", - e ); - } - return rulesets; - } - - public void xxxxeraseAllRuleSetDRL(){ - - Node repo = this.getRepository( ); - NodeIterator it; - try { - it = repo.getNodes( ); - while ( it.hasNext( ) ) { - it.nextNode( ).remove( ); - } - session.save( ); - } - catch ( RepositoryException e ) { - throw new RuleRepositoryException( "Unable to delete DRL nodes.", - e ); - } - } - - public RuleDefinition addNewRule(String ruleBase, - String ruleSet, - RuleDefinition rule){ - try { - Node ruleSetNode = getOrCreateRuleSetNode( ruleBase, - ruleSet ); - if ( ruleSetNode.hasNode( nodeNameOf( rule.getRuleName( ) ) ) ) { - throw new RuleRepositoryException( "Rule with that name [" + rule.getRuleName( ) - + "] already exists in ruleset [" - + ruleSet + "]" ); - } - Node newRuleNode = ruleSetNode.addNode( nodeNameOf( rule.getRuleName( ) ) ); - newRuleNode.setProperty( nodeNameOf( "fragment" ), - rule.getFragment( ) ); - - - } - catch ( PathNotFoundException e ) { - throw new RuleRepositoryException( "Not able to locate ruleset or base to store rule.", - e ); - } - catch ( RepositoryException e ) { - throw new RuleRepositoryException( e ); - } - - return rule; - } - - private Node getOrCreateRuleSetNode(String ruleBase, - String ruleSet) throws PathNotFoundException, - ItemExistsException, - VersionException, - ConstraintViolationException, - LockException, - RepositoryException{ - Node ruleBaseNode = getOrCreateRuleBaseNode( ruleBase ); - if ( ruleBaseNode.hasNode( nodeNameOf( ruleSet ) ) ) { - return ruleBaseNode.getNode( nodeNameOf( ruleSet ) ); - } - else { - return ruleBaseNode.addNode( nodeNameOf( ruleSet ) ); - } - } - - private Node getOrCreateRuleBaseNode(String ruleBase) throws PathNotFoundException, - ItemExistsException, - VersionException, - ConstraintViolationException, - LockException, - RepositoryException{ - Node repo = getRepository( ); - String nodeName = nodeNameOf( ruleBase ); - if ( repo.hasNode( nodeName ) ) { - return repo.getNode( nodeName ); - } - else { - return repo.addNode( nodeName ); - } - } - - public void save(){ - try { - session.save( ); - } - catch ( Exception e ) { - throw new RuleRepositoryException( "Unable to save the session.", - e ); - } - } - - public void removeRule(String ruleBase, - String ruleSet, - String ruleName){ - try { - String path = calcPath( new String[]{ruleBase, ruleSet, ruleName} ); - Node ruleNode = getRepository( ).getNode( path ); - ruleNode.remove( ); - } - catch ( PathNotFoundException e ) { - throw new RuleRepositoryException( "Unable to find rule to remove.", - e ); - } - catch ( RepositoryException e ) { - throw new RuleRepositoryException( e ); - } - - } - - public void removeRuleSet(String ruleBase, - String ruleSet){ - String[] path = new String[] {ruleBase, ruleSet}; - try { - getRepository().getNode(calcPath(path)).remove(); - } - catch ( Exception e ) { - throw new RuleRepositoryException("Unable to remove the ruleset [" + ruleSet + "]", e); - } - } - - /** - * convert a list of names to a path to retrieve. - */ - String calcPath(String[] names){ - StringBuffer buf = new StringBuffer( ); - for ( int i = 0; i < names.length; i++ ) { - buf.append( nodeNameOf( names[i] ) ); - if ( i != names.length - 1 ) { - buf.append( '/' ); - } - } - return buf.toString( ); - } - - public RuleDefinition retrieveRule(String ruleBase, - String ruleSet, - String ruleName){ - try { - Node ruleNode = getRepository().getNode(calcPath(new String[] {ruleBase, ruleSet, ruleName})); - RuleDefinition rule = new RuleDefinition(); - rule.setFragment(ruleNode.getProperty(nodeNameOf("fragment")).getString()); - - return rule; - } - catch ( PathNotFoundException e ) { - throw new RuleRepositoryException("Rule does not exist.", e); - } - catch ( RepositoryException e ) { - throw new RuleRepositoryException(e); - } - } - -} Deleted: trunk/labs/jbossrules/drools-repository/src/test/org/drools/repo/jcr/RepositoryServiceImplTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/org/drools/repo/jcr/RepositoryServiceImplTest.java 2005-12-28 02:07:48 UTC (rev 1942) +++ trunk/labs/jbossrules/drools-repository/src/test/org/drools/repo/jcr/RepositoryServiceImplTest.java 2005-12-28 05:15:43 UTC (rev 1943) @@ -1,111 +0,0 @@ -package org.drools.repo.jcr; - -import junit.framework.TestCase; - -import org.drools.metamodel.RuleDefinition; -import org.drools.repo.RepositoryService; -import org.drools.repo.RepositoryServiceFactory; - -public class RepositoryServiceImplTest extends TestCase -{ - - private static RepositoryServiceImpl instance; - private long startTime; - - - - - - public void testAddRemoveNewRuleAndRuleSet() { - - RuleDefinition rule = new RuleDefinition("nami", "rule blah {}"); - - getRepo().addNewRule("rb", "rs", rule); - getRepo().save(); - RuleDefinition rule2 = getRepo().retrieveRule("rb", "rs", "nami"); - getRepo().removeRule("rb", "rs", rule.getRuleName()); - getRepo().removeRuleSet("rb", "rs"); - - assertEquals(rule.getFragment(), rule2.getFragment()); - getRepo().save(); - - } - - public void testLargeNumberOfRules() { - startTimer(); - //setup 5000 rules in ruleset 1 - RepositoryService repo = getRepo(); - for (int i = 0; i < 5000; i ++) { - RuleDefinition rule = new RuleDefinition("rule" + i, "MyRule_" + i); - repo.addNewRule("rulebase", "ruleset1", rule); - if (i % 10 == 0) repo.save(); - } - System.out.println("Time for first 5000: " + lapTime()); - repo.save(); - - //ruleset2 - for (int i = 0; i < 5000; i ++) { - RuleDefinition rule = new RuleDefinition("rule" + i, "MyRule_" + i); - repo.addNewRule("rulebase", "ruleset2", rule); - if (i % 10 == 0) repo.save(); - } - System.out.println("Time for second 5000: " + lapTime()); - - repo.save(); - //rulebase2 - for (int i = 0; i < 5000; i ++) { - RuleDefinition rule = new RuleDefinition("rule" + i, "MyRule_" + i); - repo.addNewRule("rulebase2", "ruleset", rule); - if (i % 10 == 0) repo.save(); - } - System.out.println("Time for third 5000: " + lapTime()); - repo.save(); - - startTimer(); - - RuleDefinition rule1 = repo.retrieveRule("rulebase", "ruleset1", "rule1000"); - System.out.println("Retrieve 1 :" + lapTime()); - RuleDefinition rule2 = repo.retrieveRule("rulebase", "ruleset2", "rule1000"); - System.out.println("Retrieve 2 :" + lapTime()); - RuleDefinition rule3 = repo.retrieveRule("rulebase2", "ruleset", "rule1000"); - System.out.println("Retrieve 3 :" + lapTime()); - - repo.removeRuleSet("rulebase", "ruleset1"); - repo.removeRuleSet("rulebase", "ruleset2"); - repo.removeRuleSet("rulebase2", "ruleset"); - repo.save(); - System.out.println("Remove all:" + lapTime()); - - assertEquals("MyRule_1000", rule1.getFragment()); - assertEquals("MyRule_1000", rule2.getFragment()); - assertEquals("MyRule_1000", rule3.getFragment()); - - - } - - private long lapTime(){ - long elapsed = System.currentTimeMillis() - startTime; - startTime = System.currentTimeMillis(); - return elapsed; - } - - private void startTimer(){ - this.startTime = System.currentTimeMillis(); - - } - - public void testCalcPath() { - String result = getRepo().calcPath(new String[] {"one", "two", "three"}); - assertEquals("drools:one/drools:two/drools:three", result); - } - - private RepositoryServiceImpl getRepo() { - if (instance == null) { - instance = (RepositoryServiceImpl) RepositoryServiceFactory.getRepositoryService( ); - instance.createNewRepo( ); - instance.save(); - } - return instance; - } - -} |