use of javax.jcr.Repository in project jackrabbit by apache.
the class JNDIBindingServlet method init.
/**
* Binds a repository from the servlet context in the configured
* JNDI location.
*
* @throws ServletException if the repository could not be bound in JNDI
*/
public void init() throws ServletException {
try {
Hashtable environment = new Hashtable();
Enumeration names = getInitParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (name.equals("location")) {
location = getInitParameter(name);
} else if (!name.equals(Repository.class.getName())) {
environment.put(name, getInitParameter(name));
}
}
context = new InitialContext(environment);
context.bind(location, new ServletRepository(this));
} catch (NamingException e) {
throw new ServletException("Failed to bind repository to JNDI: " + location, e);
}
}
use of javax.jcr.Repository in project jackrabbit by apache.
the class ServletRepositoryFactory method getRepository.
/**
* Looks up and returns a repository bound in the configured servlet
* context attribute.
*
* @return repository from servlet context
* @throws RepositoryException if the repository is not available
*/
public Repository getRepository() throws RepositoryException {
String name = servlet.getInitParameter(Repository.class.getName());
if (name == null) {
name = Repository.class.getName();
}
ServletContext context = servlet.getServletContext();
Object repository = context.getAttribute(name);
if (repository instanceof Repository) {
return (Repository) repository;
} else if (repository != null) {
throw new RepositoryException("Invalid repository: Attribute " + name + " in servlet context " + context.getServletContextName() + " is an instance of " + repository.getClass().getName());
} else {
throw new RepositoryException("Repository not found: Attribute " + name + " does not exist in servlet context " + context.getServletContextName());
}
}
use of javax.jcr.Repository in project jackrabbit by apache.
the class BundleTest method testJackrabbitBundle.
public void testJackrabbitBundle() throws Exception {
ServiceReference reference = getServiceReference(Repository.class.getName());
Assert.assertNotNull(reference);
Assert.assertEquals("Jackrabbit", reference.getProperty(Repository.REP_NAME_DESC));
Object service = getServiceObject(reference);
assertTrue(service instanceof Repository);
Repository repository = (Repository) service;
Assert.assertEquals("Jackrabbit", repository.getDescriptor(Repository.REP_NAME_DESC));
Session session = repository.login();
try {
assertEquals("/", session.getRootNode().getPath());
} finally {
session.logout();
}
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class JackrabbitRepositoryFixture method setUpCluster.
@Override
public Repository[] setUpCluster(int n) throws Exception {
if (n == 1) {
String name = "Jackrabbit-" + System.currentTimeMillis();
File directory = new File(base, name);
Properties variables = new Properties(System.getProperties());
variables.setProperty(REPOSITORY_HOME_VARIABLE, directory.getPath());
variables.setProperty("bundleCacheSize", Integer.toString(bundleCacheSize));
InputStream xml = getClass().getResourceAsStream("repository.xml");
RepositoryConfig config = RepositoryConfig.create(new InputSource(xml), variables);
// Prevent Derby from polluting the current directory
System.setProperty("derby.stream.error.file", new File(directory, "derby.log").getPath());
RepositoryImpl repository = RepositoryImpl.create(config);
this.cluster = new RepositoryImpl[] { repository };
return new Repository[] { repository };
} else {
throw new UnsupportedOperationException("TODO");
}
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class RevisionGCTest method run.
@Override
public void run(Iterable<RepositoryFixture> fixtures) {
for (RepositoryFixture fixture : fixtures) {
if (fixture.isAvailable(1)) {
System.out.format("%s: RevisionGC benchmark%n", fixture);
try {
final AtomicReference<Oak> whiteboardRef = new AtomicReference<Oak>();
Repository[] cluster;
if (fixture instanceof OakRepositoryFixture) {
cluster = ((OakRepositoryFixture) fixture).setUpCluster(1, new JcrCreator() {
@Override
public Jcr customize(Oak oak) {
whiteboardRef.set(oak);
return new Jcr(oak);
}
});
} else {
System.err.format("%s: RevisionGC benchmark only runs on Oak%n", fixture);
return;
}
try {
run(cluster[0], getNodeStore(whiteboardRef.get()));
} finally {
fixture.tearDownCluster();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Aggregations