use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class ValidNamesTest method setup.
@Before
public void setup() throws RepositoryException {
Repository repo = createRepository(fixture);
Session session = repo.login(getAdminCredentials());
Node root = session.getRootNode();
testNode = root.addNode(TEST_NODE);
session.save();
StringBuilder t = new StringBuilder();
for (String prefix : session.getNamespacePrefixes()) {
int l = t.length();
if (prefix.length() > l) {
t.append((char) (prefix.charAt(l) ^ 1));
} else {
t.append('x');
}
}
unmappedNsPrefix = t.toString();
for (String p : testNode.getSession().getNamespacePrefixes()) {
if (p.length() != 0) {
String u = testNode.getSession().getNamespaceURI(p);
if (u.contains(":")) {
testPrefix = p;
testNsUri = u;
}
}
}
assertNotNull(testPrefix);
assertNotNull(testNsUri);
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class ValidNamesTest method tearDown.
@After
public void tearDown() throws RepositoryException {
Session s = testNode.getSession();
s.removeItem(TEST_PATH);
s.save();
Repository r = s.getRepository();
s.logout();
dispose(r);
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class OakOSGiRepositoryFactory method getRepository.
@SuppressWarnings("unchecked")
public Repository getRepository(Map parameters) throws RepositoryException {
if (parameters == null || !parameters.containsKey(REPOSITORY_HOME)) {
//Required param missing so repository cannot be created
return null;
}
Map config = new HashMap();
config.putAll(parameters);
PojoServiceRegistry registry = initializeServiceRegistry(config);
BundleActivator activator = getApplicationActivator(config);
try {
activator.start(registry.getBundleContext());
} catch (Exception e) {
log.warn("Error occurred while starting activator {}", activator.getClass(), e);
}
//Future which would be used to notify when repository is ready
// to be used
SettableFuture<Repository> repoFuture = SettableFuture.create();
new RunnableJobTracker(registry.getBundleContext());
int timeoutInSecs = PropertiesUtil.toInteger(config.get(REPOSITORY_TIMEOUT_IN_SECS), DEFAULT_TIMEOUT);
//Start the tracker for repository creation
new RepositoryTracker(registry, activator, repoFuture, timeoutInSecs);
// where OSGi runtime fails to start due to bugs (like cycles)
try {
return repoFuture.get(timeoutInSecs, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RepositoryException("Repository initialization was interrupted");
} catch (ExecutionException e) {
throw new RepositoryException(e);
} catch (TimeoutException e) {
try {
if (PropertiesUtil.toBoolean(config.get(REPOSITORY_SHUTDOWN_ON_TIMEOUT), true)) {
shutdown(registry, timeoutInSecs);
log.info("OSGi container shutdown after waiting for repository initialization for {} sec", timeoutInSecs);
} else {
log.warn("[{}] found to be false. Container is not stopped", REPOSITORY_SHUTDOWN_ON_TIMEOUT);
}
} catch (BundleException be) {
log.warn("Error occurred while shutting down the service registry (due to " + "startup timeout) backing the Repository ", be);
}
throw new RepositoryException("Repository could not be started in " + timeoutInSecs + " seconds", e);
}
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class JsonIndexCommand method openSession.
public static Session openSession(NodeStore nodeStore) throws RepositoryException {
if (nodeStore == null) {
return null;
}
StatisticsProvider statisticsProvider = StatisticsProvider.NOOP;
Oak oak = new Oak(nodeStore).with(ManagementFactory.getPlatformMBeanServer());
oak.getWhiteboard().register(StatisticsProvider.class, statisticsProvider, Collections.emptyMap());
LuceneIndexProvider provider = createLuceneIndexProvider();
oak.with((QueryIndexProvider) provider).with((Observer) provider).with(createLuceneIndexEditorProvider());
Jcr jcr = new Jcr(oak);
Repository repository = jcr.createRepository();
return repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
}
use of javax.jcr.Repository in project jackrabbit-oak by apache.
the class UpgradeOldSegmentTest method upgradeFrom10.
@Test
public void upgradeFrom10() throws Exception {
File testFolder = new File(new File("target"), UpgradeOldSegmentTest.class.getSimpleName());
FileUtils.deleteDirectory(testFolder);
File oldRepo = new File(testFolder, "test-repo-1.0");
oldRepo.mkdirs();
try (InputStream in = UpgradeOldSegmentTest.class.getResourceAsStream("/test-repo-1.0.zip")) {
Util.unzip(in, oldRepo);
}
SegmentTarNodeStoreContainer newRepoContainer = new SegmentTarNodeStoreContainer();
OakUpgrade.main("segment-old:" + oldRepo.getPath(), newRepoContainer.getDescription());
Repository repo = new Jcr(newRepoContainer.open()).createRepository();
Session s = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
Node myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager();
assertTrue(ntMgr.hasNodeType("test:MyType"));
NodeType nt = ntMgr.getNodeType("test:MyType");
PropertyDefinition[] pDefs = nt.getDeclaredPropertyDefinitions();
assertEquals(2, pDefs.length);
for (PropertyDefinition pd : pDefs) {
String name = pd.getName();
if (name.equals("test:mandatory")) {
assertTrue(pd.isMandatory());
} else if (name.equals("test:optional")) {
assertFalse(pd.isMandatory());
} else {
fail("Unexpected property definition: " + name);
}
}
// flip mandatory flag for test:mandatory
String cnd = "<'test'='http://www.apache.org/jackrabbit/test'>\n" + "[test:MyType] > nt:unstructured\n" + " - test:mandatory (string)\n" + " - test:optional (string)";
CndImporter.registerNodeTypes(new StringReader(cnd), s, true);
myType = s.getNode("/jcr:system/jcr:nodeTypes/test:MyType");
assertEquals(2, Iterators.size(myType.getNodes("jcr:propertyDefinition")));
nt = ntMgr.getNodeType("test:MyType");
pDefs = nt.getDeclaredPropertyDefinitions();
assertEquals(2, pDefs.length);
for (PropertyDefinition pd : pDefs) {
String name = pd.getName();
if (name.equals("test:mandatory")) {
assertFalse(pd.isMandatory());
} else if (name.equals("test:optional")) {
assertFalse(pd.isMandatory());
} else {
fail("Unexpected property definition: " + name);
}
}
s.logout();
if (repo instanceof JackrabbitRepository) {
((JackrabbitRepository) repo).shutdown();
}
newRepoContainer.close();
newRepoContainer.clean();
deleteRecursive(testFolder);
}
Aggregations