mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-09 17:45:10 +00:00
Added getRepository() and getRepositories() to AVMService, removed getRepositoryNames()
from same. These new methods return a RepositoryDescriptor and a List of RepositoryDescriptors. Note, Hibernate mapping has changed. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3207 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
parent
91e39c8fd6
commit
ff4fe08d04
@ -146,10 +146,10 @@ public class AVMInteractiveConsole
|
||||
}
|
||||
else if (command[0].equals("lsrep"))
|
||||
{
|
||||
List<String> repos = fService.getRepositoryNames();
|
||||
for (String name : repos)
|
||||
List<RepositoryDescriptor> repos = fService.getRepositories();
|
||||
for (RepositoryDescriptor repo : repos)
|
||||
{
|
||||
System.out.println(name);
|
||||
System.out.println(repo);
|
||||
}
|
||||
}
|
||||
else if (command[0].equals("lsver"))
|
||||
|
@ -25,8 +25,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This is the service interface for the [Alfresco|Addled|Advanced|Apotheosed] Versioning
|
||||
* Model. It specifies methods that are close in functionality to the underlying
|
||||
* This is the service interface for the [Alfresco|Addled|Advanced|Aleatoric|Apotheosed|Awful]
|
||||
* Versioning Model. It specifies methods that are close in functionality to the underlying
|
||||
* implementation, and is intended as both a first class Alfresco service and an
|
||||
* aid in creating new implementations of existing services.
|
||||
* Paths are of the form repositoryname:/foo/bar/baz
|
||||
@ -199,10 +199,17 @@ public interface AVMService
|
||||
public List<VersionDescriptor> getRepositoryVersions(String name, Date from, Date to);
|
||||
|
||||
/**
|
||||
* Get the names of all repositories.
|
||||
* @return A List of all names.
|
||||
* Get the descriptors of all repositories.
|
||||
* @return A List of all repositories.
|
||||
*/
|
||||
public List<String> getRepositoryNames();
|
||||
public List<RepositoryDescriptor> getRepositories();
|
||||
|
||||
/**
|
||||
* Get a descriptor for a repository.
|
||||
* @param name The repository's name.
|
||||
* @return A Descriptor.
|
||||
*/
|
||||
public RepositoryDescriptor getRepository(String name);
|
||||
|
||||
/**
|
||||
* Get the specified root of a repository.
|
||||
|
@ -764,21 +764,47 @@ public class AVMServiceImpl implements AVMService
|
||||
fTransaction.perform(doit, true);
|
||||
}
|
||||
|
||||
public List<String> getRepositoryNames()
|
||||
/**
|
||||
* Get a list of all Repositories.
|
||||
* @return The repositories.
|
||||
*/
|
||||
public List<RepositoryDescriptor> getRepositories()
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public List<String> names;
|
||||
public List<RepositoryDescriptor> reps;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.setSession(session);
|
||||
names = fSuperRepository.getRepositoryNames();
|
||||
reps = fSuperRepository.getRepositories();
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit, false);
|
||||
return doit.names;
|
||||
return doit.reps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reposotory.
|
||||
* @param name The name of the repository to get.
|
||||
* @return The repositories.
|
||||
*/
|
||||
public RepositoryDescriptor getRepository(final String name)
|
||||
{
|
||||
class HTxnCallback implements HibernateTxnCallback
|
||||
{
|
||||
public RepositoryDescriptor desc;
|
||||
|
||||
public void perform(Session session)
|
||||
{
|
||||
fSuperRepository.setSession(session);
|
||||
desc = fSuperRepository.getRepository(name);
|
||||
}
|
||||
}
|
||||
HTxnCallback doit = new HTxnCallback();
|
||||
fTransaction.perform(doit, false);
|
||||
return doit.desc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -856,10 +856,10 @@ public class AVMServiceTest extends AVMServiceTestBase
|
||||
{
|
||||
setupBasicTree();
|
||||
fService.createRepository("second");
|
||||
List<String> repoNames = fService.getRepositoryNames();
|
||||
assertEquals(2, repoNames.size());
|
||||
assertTrue(repoNames.contains("main"));
|
||||
assertTrue(repoNames.contains("second"));
|
||||
List<RepositoryDescriptor> repos = fService.getRepositories();
|
||||
assertEquals(2, repos.size());
|
||||
System.out.println(repos.get(0));
|
||||
System.out.println(repos.get(1));
|
||||
fService.createBranch(-1, "main:/", "second:/", "main");
|
||||
fService.createSnapshot("second");
|
||||
System.out.println(recursiveList("second", -1, true));
|
||||
@ -1833,4 +1833,34 @@ public class AVMServiceTest extends AVMServiceTestBase
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test repository functions.
|
||||
*/
|
||||
public void testRepsitory()
|
||||
{
|
||||
try
|
||||
{
|
||||
// First check that we get the right error when we try to create a
|
||||
// repository that exists.
|
||||
try
|
||||
{
|
||||
fService.createRepository("main");
|
||||
fail();
|
||||
}
|
||||
catch (AVMExistsException ae)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
// Now make sure getRepository() works.
|
||||
RepositoryDescriptor desc = fService.getRepository("main");
|
||||
assertNotNull(desc);
|
||||
System.out.println(desc);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace(System.err);
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,4 +215,34 @@ interface Repository
|
||||
* @param version
|
||||
*/
|
||||
public void purgeVersion(int version);
|
||||
|
||||
/**
|
||||
* Set the creator.
|
||||
* @param creator
|
||||
*/
|
||||
public void setCreator(String creator);
|
||||
|
||||
/**
|
||||
* Get the creator.
|
||||
* @return The creator.
|
||||
*/
|
||||
public String getCreator();
|
||||
|
||||
/**
|
||||
* Set the create date.
|
||||
* @param date
|
||||
*/
|
||||
public void setCreateDate(long date);
|
||||
|
||||
/**
|
||||
* Get the create date.
|
||||
* @return The create date.
|
||||
*/
|
||||
public long getCreateDate();
|
||||
|
||||
/**
|
||||
* Get the descriptor for this.
|
||||
* @return The descriptor.
|
||||
*/
|
||||
public RepositoryDescriptor getDescriptor();
|
||||
}
|
80
source/java/org/alfresco/repo/avm/RepositoryDescriptor.java
Normal file
80
source/java/org/alfresco/repo/avm/RepositoryDescriptor.java
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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.repo.avm;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* A value class for Data about a repository.
|
||||
* @author britt
|
||||
*/
|
||||
public class RepositoryDescriptor
|
||||
{
|
||||
/**
|
||||
* The name.
|
||||
*/
|
||||
private String fName;
|
||||
|
||||
/**
|
||||
* The creator.
|
||||
*/
|
||||
private String fCreator;
|
||||
|
||||
/**
|
||||
* The create date.
|
||||
*/
|
||||
private long fCreateDate;
|
||||
|
||||
public RepositoryDescriptor(String name,
|
||||
String creator,
|
||||
long createDate)
|
||||
{
|
||||
fName = name;
|
||||
fCreator = creator;
|
||||
fCreateDate = createDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fCreateDate
|
||||
*/
|
||||
public long getCreateDate()
|
||||
{
|
||||
return fCreateDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fCreator
|
||||
*/
|
||||
public String getCreator()
|
||||
{
|
||||
return fCreator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fName
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "[" + fName + ":" + fCreator + ":" + new Date(fCreateDate) + "]";
|
||||
}
|
||||
}
|
@ -64,6 +64,16 @@ class RepositoryImpl implements Repository, Serializable
|
||||
*/
|
||||
transient private SuperRepository fSuper;
|
||||
|
||||
/**
|
||||
* The creator.
|
||||
*/
|
||||
private String fCreator;
|
||||
|
||||
/**
|
||||
* The create date.
|
||||
*/
|
||||
private long fCreateDate;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
@ -84,6 +94,8 @@ class RepositoryImpl implements Repository, Serializable
|
||||
fName = name;
|
||||
fNextVersionID = 0;
|
||||
fRoot = null;
|
||||
fCreator = "britt";
|
||||
fCreateDate = System.currentTimeMillis();
|
||||
fSuper.getSession().save(this);
|
||||
// Make up the initial version record and save.
|
||||
long time = System.currentTimeMillis();
|
||||
@ -778,4 +790,49 @@ class RepositoryImpl implements Repository, Serializable
|
||||
fRoot = vRoot.getRoot();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the create date.
|
||||
* @return The create date.
|
||||
*/
|
||||
public long getCreateDate()
|
||||
{
|
||||
return fCreateDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the creator.
|
||||
* @return The creator.
|
||||
*/
|
||||
public String getCreator()
|
||||
{
|
||||
return fCreator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the create date.
|
||||
* @param date
|
||||
*/
|
||||
public void setCreateDate(long date)
|
||||
{
|
||||
fCreateDate = date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the creator.
|
||||
* @param creator
|
||||
*/
|
||||
public void setCreator(String creator)
|
||||
{
|
||||
fCreator = creator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the descriptor for this.
|
||||
* @return
|
||||
*/
|
||||
public RepositoryDescriptor getDescriptor()
|
||||
{
|
||||
return new RepositoryDescriptor(fName, fCreator, fCreateDate);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
|
||||
{
|
||||
try
|
||||
{
|
||||
int n = 4;
|
||||
int n = 2;
|
||||
int m = 1;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
fService.createDirectory("main:/", "d" + i);
|
||||
@ -41,7 +42,7 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
|
||||
Thread [] threads = new Thread[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
Loader loader = new Loader("source", "main:/d" + i);
|
||||
Loader loader = new Loader("source", "main:/d" + i, m);
|
||||
threads[i] = new Thread(loader);
|
||||
threads[i].start();
|
||||
}
|
||||
@ -74,21 +75,31 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
|
||||
*/
|
||||
private String fDestination;
|
||||
|
||||
/**
|
||||
* The number of copies of stuff to make serially.
|
||||
*/
|
||||
private int fCount;
|
||||
|
||||
/**
|
||||
* Set up.
|
||||
* @param source Source directory.
|
||||
* @param destination Destination path.
|
||||
*/
|
||||
public Loader(String source, String destination)
|
||||
public Loader(String source, String destination, int count)
|
||||
{
|
||||
fLoader = new BulkLoader(fService);
|
||||
fSource = source;
|
||||
fDestination = destination;
|
||||
fCount = count;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
fLoader.recursiveLoad(fSource, fDestination);
|
||||
for (int i = 0; i < fCount; i++)
|
||||
{
|
||||
fService.createDirectory(fDestination, "" + i);
|
||||
fLoader.recursiveLoad(fSource, fDestination + "/" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,15 @@ class SuperRepository
|
||||
*/
|
||||
public void createRepository(String name)
|
||||
{
|
||||
// TODO need to check for repository existence first.
|
||||
try
|
||||
{
|
||||
getRepositoryByName(name, false);
|
||||
throw new AVMExistsException("Repository exists: " + name);
|
||||
}
|
||||
catch (AVMNotFoundException anf)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
// Newing up the object causes it to be written to the db.
|
||||
@SuppressWarnings("unused")
|
||||
Repository rep = new RepositoryImpl(this, name);
|
||||
@ -564,12 +572,29 @@ class SuperRepository
|
||||
* @return A list of names.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getRepositoryNames()
|
||||
public List<RepositoryDescriptor> getRepositories()
|
||||
{
|
||||
Query query = fSession.get().createQuery("select r.name from RepositoryImpl r");
|
||||
return (List<String>)query.list();
|
||||
Query query = fSession.get().createQuery("from RepositoryImpl r");
|
||||
List<Repository> l = (List<Repository>)query.list();
|
||||
List<RepositoryDescriptor> result = new ArrayList<RepositoryDescriptor>();
|
||||
for (Repository rep : l)
|
||||
{
|
||||
result.add(rep.getDescriptor());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a descriptor for a repository.
|
||||
* @param name The name to get.
|
||||
* @return The descriptor.
|
||||
*/
|
||||
public RepositoryDescriptor getRepository(String name)
|
||||
{
|
||||
Repository rep = getRepositoryByName(name, false);
|
||||
return rep.getDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all version for a given repository.
|
||||
* @param name The name of the repository.
|
||||
@ -668,9 +693,14 @@ class SuperRepository
|
||||
*/
|
||||
private Repository getRepositoryByName(String name, boolean write)
|
||||
{
|
||||
return (Repository)fSession.get().get(RepositoryImpl.class,
|
||||
Repository rep = (Repository)fSession.get().get(RepositoryImpl.class,
|
||||
name /* ,
|
||||
write ? LockMode.UPGRADE : LockMode.READ */);
|
||||
if (rep == null)
|
||||
{
|
||||
throw new AVMNotFoundException("Repository not found: " + name);
|
||||
}
|
||||
return rep;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -832,6 +862,16 @@ class SuperRepository
|
||||
return history;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the RepositoryDescriptor for a Repository.
|
||||
* @param name The name of the Repository.
|
||||
* @return The descriptor.
|
||||
*/
|
||||
public RepositoryDescriptor getRepositoryDescriptor(String name)
|
||||
{
|
||||
return getRepositoryByName(name, false).getDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the single instance of SuperRepository.
|
||||
* @return
|
||||
|
@ -120,6 +120,8 @@
|
||||
<version name="vers" column="vers" type="long"/>
|
||||
<property type="int" name="nextVersionID"
|
||||
column="next_version_id" not-null="true"/>
|
||||
<property type="string" name="creator" column="creator" not-null="true"/>
|
||||
<property type="long" name="createDate" column="create_date" not-null="true"/>
|
||||
<!-- Every Repository has a root directory that is the current root directory. -->
|
||||
<!-- This should be not-null but hibernate (or my own idiocy) makes that difficult. -->
|
||||
<many-to-one name="root" class="DirectoryNodeImpl"
|
||||
|
@ -112,11 +112,11 @@ public class HibernateTxn
|
||||
{
|
||||
if (t instanceof StaleStateException)
|
||||
{
|
||||
System.err.println("Lost Race");
|
||||
// System.err.println("Lost Race");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println("Deadlock");
|
||||
// System.err.println("Deadlock");
|
||||
try
|
||||
{
|
||||
long interval;
|
||||
|
Loading…
x
Reference in New Issue
Block a user