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"))
|
else if (command[0].equals("lsrep"))
|
||||||
{
|
{
|
||||||
List<String> repos = fService.getRepositoryNames();
|
List<RepositoryDescriptor> repos = fService.getRepositories();
|
||||||
for (String name : repos)
|
for (RepositoryDescriptor repo : repos)
|
||||||
{
|
{
|
||||||
System.out.println(name);
|
System.out.println(repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command[0].equals("lsver"))
|
else if (command[0].equals("lsver"))
|
||||||
|
@ -25,8 +25,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the service interface for the [Alfresco|Addled|Advanced|Apotheosed] Versioning
|
* This is the service interface for the [Alfresco|Addled|Advanced|Aleatoric|Apotheosed|Awful]
|
||||||
* Model. It specifies methods that are close in functionality to the underlying
|
* 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
|
* implementation, and is intended as both a first class Alfresco service and an
|
||||||
* aid in creating new implementations of existing services.
|
* aid in creating new implementations of existing services.
|
||||||
* Paths are of the form repositoryname:/foo/bar/baz
|
* 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);
|
public List<VersionDescriptor> getRepositoryVersions(String name, Date from, Date to);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the names of all repositories.
|
* Get the descriptors of all repositories.
|
||||||
* @return A List of all names.
|
* @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.
|
* Get the specified root of a repository.
|
||||||
|
@ -764,21 +764,47 @@ public class AVMServiceImpl implements AVMService
|
|||||||
fTransaction.perform(doit, true);
|
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
|
class HTxnCallback implements HibernateTxnCallback
|
||||||
{
|
{
|
||||||
public List<String> names;
|
public List<RepositoryDescriptor> reps;
|
||||||
|
|
||||||
public void perform(Session session)
|
public void perform(Session session)
|
||||||
{
|
{
|
||||||
fSuperRepository.setSession(session);
|
fSuperRepository.setSession(session);
|
||||||
names = fSuperRepository.getRepositoryNames();
|
reps = fSuperRepository.getRepositories();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HTxnCallback doit = new HTxnCallback();
|
HTxnCallback doit = new HTxnCallback();
|
||||||
fTransaction.perform(doit, false);
|
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();
|
setupBasicTree();
|
||||||
fService.createRepository("second");
|
fService.createRepository("second");
|
||||||
List<String> repoNames = fService.getRepositoryNames();
|
List<RepositoryDescriptor> repos = fService.getRepositories();
|
||||||
assertEquals(2, repoNames.size());
|
assertEquals(2, repos.size());
|
||||||
assertTrue(repoNames.contains("main"));
|
System.out.println(repos.get(0));
|
||||||
assertTrue(repoNames.contains("second"));
|
System.out.println(repos.get(1));
|
||||||
fService.createBranch(-1, "main:/", "second:/", "main");
|
fService.createBranch(-1, "main:/", "second:/", "main");
|
||||||
fService.createSnapshot("second");
|
fService.createSnapshot("second");
|
||||||
System.out.println(recursiveList("second", -1, true));
|
System.out.println(recursiveList("second", -1, true));
|
||||||
@ -1833,4 +1833,34 @@ public class AVMServiceTest extends AVMServiceTestBase
|
|||||||
fail();
|
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
|
* @param version
|
||||||
*/
|
*/
|
||||||
public void purgeVersion(int 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;
|
transient private SuperRepository fSuper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The creator.
|
||||||
|
*/
|
||||||
|
private String fCreator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The create date.
|
||||||
|
*/
|
||||||
|
private long fCreateDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
@ -84,6 +94,8 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
fName = name;
|
fName = name;
|
||||||
fNextVersionID = 0;
|
fNextVersionID = 0;
|
||||||
fRoot = null;
|
fRoot = null;
|
||||||
|
fCreator = "britt";
|
||||||
|
fCreateDate = System.currentTimeMillis();
|
||||||
fSuper.getSession().save(this);
|
fSuper.getSession().save(this);
|
||||||
// Make up the initial version record and save.
|
// Make up the initial version record and save.
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
@ -778,4 +790,49 @@ class RepositoryImpl implements Repository, Serializable
|
|||||||
fRoot = vRoot.getRoot();
|
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
|
try
|
||||||
{
|
{
|
||||||
int n = 4;
|
int n = 2;
|
||||||
|
int m = 1;
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
fService.createDirectory("main:/", "d" + i);
|
fService.createDirectory("main:/", "d" + i);
|
||||||
@ -41,7 +42,7 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
|
|||||||
Thread [] threads = new Thread[n];
|
Thread [] threads = new Thread[n];
|
||||||
for (int i = 0; i < n; i++)
|
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] = new Thread(loader);
|
||||||
threads[i].start();
|
threads[i].start();
|
||||||
}
|
}
|
||||||
@ -74,21 +75,31 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
|
|||||||
*/
|
*/
|
||||||
private String fDestination;
|
private String fDestination;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of copies of stuff to make serially.
|
||||||
|
*/
|
||||||
|
private int fCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up.
|
* Set up.
|
||||||
* @param source Source directory.
|
* @param source Source directory.
|
||||||
* @param destination Destination path.
|
* @param destination Destination path.
|
||||||
*/
|
*/
|
||||||
public Loader(String source, String destination)
|
public Loader(String source, String destination, int count)
|
||||||
{
|
{
|
||||||
fLoader = new BulkLoader(fService);
|
fLoader = new BulkLoader(fService);
|
||||||
fSource = source;
|
fSource = source;
|
||||||
fDestination = destination;
|
fDestination = destination;
|
||||||
|
fCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
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)
|
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.
|
// Newing up the object causes it to be written to the db.
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
Repository rep = new RepositoryImpl(this, name);
|
Repository rep = new RepositoryImpl(this, name);
|
||||||
@ -564,12 +572,29 @@ class SuperRepository
|
|||||||
* @return A list of names.
|
* @return A list of names.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<String> getRepositoryNames()
|
public List<RepositoryDescriptor> getRepositories()
|
||||||
{
|
{
|
||||||
Query query = fSession.get().createQuery("select r.name from RepositoryImpl r");
|
Query query = fSession.get().createQuery("from RepositoryImpl r");
|
||||||
return (List<String>)query.list();
|
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.
|
* Get all version for a given repository.
|
||||||
* @param name The name of the repository.
|
* @param name The name of the repository.
|
||||||
@ -668,9 +693,14 @@ class SuperRepository
|
|||||||
*/
|
*/
|
||||||
private Repository getRepositoryByName(String name, boolean write)
|
private Repository getRepositoryByName(String name, boolean write)
|
||||||
{
|
{
|
||||||
return (Repository)fSession.get().get(RepositoryImpl.class,
|
Repository rep = (Repository)fSession.get().get(RepositoryImpl.class,
|
||||||
name /* ,
|
name /* ,
|
||||||
write ? LockMode.UPGRADE : LockMode.READ */);
|
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;
|
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.
|
* Get the single instance of SuperRepository.
|
||||||
* @return
|
* @return
|
||||||
|
@ -120,6 +120,8 @@
|
|||||||
<version name="vers" column="vers" type="long"/>
|
<version name="vers" column="vers" type="long"/>
|
||||||
<property type="int" name="nextVersionID"
|
<property type="int" name="nextVersionID"
|
||||||
column="next_version_id" not-null="true"/>
|
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. -->
|
<!-- 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. -->
|
<!-- This should be not-null but hibernate (or my own idiocy) makes that difficult. -->
|
||||||
<many-to-one name="root" class="DirectoryNodeImpl"
|
<many-to-one name="root" class="DirectoryNodeImpl"
|
||||||
|
@ -112,11 +112,11 @@ public class HibernateTxn
|
|||||||
{
|
{
|
||||||
if (t instanceof StaleStateException)
|
if (t instanceof StaleStateException)
|
||||||
{
|
{
|
||||||
System.err.println("Lost Race");
|
// System.err.println("Lost Race");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.err.println("Deadlock");
|
// System.err.println("Deadlock");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
long interval;
|
long interval;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user