use of javax.jcr.Repository in project jackrabbit by apache.
the class RegistryHelper method registerRepository.
/**
* Binds a configured repository to the given JNDI context.
* This method creates a {@link BindableRepository BindableRepository}
* instance using the given configuration information, and binds
* it to the given JNDI context.
*
* @param ctx context where the repository should be registered (i.e. bound)
* @param name the name to register the repository with
* @param configFilePath path to the configuration file of the repository
* @param repHomeDir repository home directory
* @param overwrite if <code>true</code>, any existing binding with the given
* name will be overwritten; otherwise a <code>NamingException</code> will
* be thrown if the name is already bound
* @throws RepositoryException if the repository cannot be created
* @throws NamingException if the repository cannot be registered in JNDI
*/
public static void registerRepository(Context ctx, String name, String configFilePath, String repHomeDir, boolean overwrite) throws NamingException, RepositoryException {
Reference reference = new Reference(Repository.class.getName(), BindableRepositoryFactory.class.getName(), // no classpath defined
null);
reference.add(new StringRefAddr(BindableRepository.CONFIGFILEPATH_ADDRTYPE, configFilePath));
reference.add(new StringRefAddr(BindableRepository.REPHOMEDIR_ADDRTYPE, repHomeDir));
// always create instance by using BindableRepositoryFactory
// which maintains an instance cache;
// see http://issues.apache.org/jira/browse/JCR-411 for details
Object obj = new BindableRepositoryFactory().getObjectInstance(reference, null, null, null);
if (overwrite) {
ctx.rebind(name, obj);
} else {
ctx.bind(name, obj);
}
}
use of javax.jcr.Repository in project jackrabbit by apache.
the class PersistenceManagerIteratorTest method testGetAllNodeIds.
public void testGetAllNodeIds() throws Exception {
Node root = testRootNode;
Session session = root.getSession();
Repository rep = session.getRepository();
if (!(rep instanceof RepositoryImpl)) {
log("Test skipped. Required repository class: " + RepositoryImpl.class + " got: " + rep.getClass());
return;
}
RepositoryImpl r = (RepositoryImpl) rep;
RepositoryConfig conf = r.getConfig();
Collection<WorkspaceConfig> coll = conf.getWorkspaceConfigs();
String[] names = new String[coll.size()];
Iterator<WorkspaceConfig> wspIt = coll.iterator();
for (int i = 0; wspIt.hasNext(); i++) {
WorkspaceConfig wsc = wspIt.next();
names[i] = wsc.getName();
}
for (int i = 0; i < names.length && i < 1; i++) {
Session s = getHelper().getSuperuserSession(names[i]);
try {
Method m = r.getClass().getDeclaredMethod("getWorkspaceInfo", new Class[] { String.class });
m.setAccessible(true);
Object info = m.invoke(r, names[i]);
m = info.getClass().getDeclaredMethod("getPersistenceManager", new Class[0]);
m.setAccessible(true);
PersistenceManager pm = (PersistenceManager) m.invoke(info, new Object[0]);
if (!(pm instanceof AbstractBundlePersistenceManager)) {
log("PM skipped: " + pm.getClass());
continue;
}
AbstractBundlePersistenceManager apm = (AbstractBundlePersistenceManager) pm;
log("PM: " + pm.getClass().getName());
log("All nodes in one step");
NodeId after = null;
NodeId first = null;
for (NodeId id : apm.getAllNodeIds(null, 0)) {
log(" " + id);
if (first == null) {
// initialize first node id
first = id;
}
if (after != null) {
assertFalse(id.compareTo(after) == 0);
}
after = id;
}
// start with first
after = first;
log("All nodes using batches");
while (true) {
log(" bigger than: " + after);
Iterator<NodeId> it = apm.getAllNodeIds(after, 2).iterator();
if (!it.hasNext()) {
break;
}
while (it.hasNext()) {
NodeId id = it.next();
log(" " + id);
assertFalse(id.compareTo(after) == 0);
after = id;
}
}
log("Random access");
for (int j = 0; j < 50; j++) {
after = NodeId.randomId();
log(" bigger than: " + after);
for (NodeId id : apm.getAllNodeIds(after, 2)) {
log(" " + id);
assertFalse(id.compareTo(after) == 0);
after = id;
}
}
} finally {
s.logout();
}
}
}
use of javax.jcr.Repository in project jackrabbit by apache.
the class ConnectionFactoryTest method testTransactionSupport.
/**
* Test if the session supports transactions
*/
public void testTransactionSupport() throws Exception {
// Create the connection factory
Object cf = mcf.createConnectionFactory();
assertTrue(cf instanceof JCARepositoryHandle);
Repository repository = (Repository) cf;
// Open a session
Session session = repository.login(JCR_SUPERUSER);
assertTrue(session instanceof XAResource);
session.logout();
}
use of javax.jcr.Repository in project jackrabbit by apache.
the class ConnectionFactoryTest method testAllocation.
/**
* Test the connection factory allocation.
*/
public void testAllocation() throws Exception {
// Create the connection factory
Object cf = mcf.createConnectionFactory();
assertTrue(cf instanceof JCARepositoryHandle);
Repository repository = (Repository) cf;
// Open a new session
Session session = repository.login(JCR_SUPERUSER);
assertTrue(session != null);
assertTrue(session instanceof JCASessionHandle);
// Logout session
session.logout();
}
use of javax.jcr.Repository in project jackrabbit by apache.
the class RepositoryFactoryImplTest method testGetSpi2jcrRepository.
public void testGetSpi2jcrRepository() throws RepositoryException {
Repository coreRepo = factory.getRepository(null);
HashMap<String, Object> parameters = new HashMap<String, Object>();
parameters.put("org.apache.jackrabbit.spi.RepositoryServiceFactory", "org.apache.jackrabbit.spi2jcr.Spi2jcrRepositoryServiceFactory");
parameters.put("org.apache.jackrabbit.spi2jcr.Repository", coreRepo);
Repository jcr2spiRepo = factory.getRepository(parameters);
assertNotNull(jcr2spiRepo);
assertEquals("Jackrabbit", jcr2spiRepo.getDescriptor(Repository.REP_NAME_DESC));
}
Aggregations