Refine search
/** * Set the autoexport:enabled property to false in the repository. This method should only be called in an exception * handler, as it assumes the current session state is garbage and aggressively clears it. * @throws RepositoryException */ private void disableAutoExportJcrProperty() throws RepositoryException { // this method is almost certainly being called while current session state is somehow unreliable // therefore, before attempting to work with the repo, we should attempt to reset to a good state eventProcessorSession.refresh(false); final Property autoExportEnableProperty = autoExportConfigNode.getProperty(AutoExportConstants.CONFIG_ENABLED_PROPERTY_NAME); autoExportEnableProperty.setValue(false); eventProcessorSession.save(); }
public void run() { try { for(int i=0; i<NODES_PER_THREAD; i++) { session.refresh(false); int level1 = random.nextInt(PARENT_COUNT); Node level1Node = session.getNode("/"+ROOT_NODE_NAME+"/testNode/level1_"+level1); String randomName = UUID.randomUUID().toString(); Node newNode = level1Node.addNode(randomName); newNode.setProperty("indexedProperty", randomName); session.save(); } } catch (RepositoryException e) { throw new RuntimeException(e); } }
protected void addContentToCustomer( Session session, String pathToCustomer, String childName ) throws Exception { // Add a child under the node ... session.refresh(false); Node customer = session.getNode(pathToCustomer); Node deck = customer.addNode(childName, "acme:DeckClassType"); assertThat(deck, is(notNullValue())); }
@Override public void run() { try { int numNodes = NODE_COUNT.get(); long time = System.currentTimeMillis(); session.refresh(false); Node root = session.getNode(path); Node node = root.addNode("node" + count++); for (int j = 0; j < NODE_COUNT_LEVEL2; j++) { node.addNode("node" + j); session.save(); NODE_COUNT.incrementAndGet(); } numNodes = NODE_COUNT.get() - numNodes; time = System.currentTimeMillis() - time; if (this == writer && VERBOSE) { long perSecond = numNodes * 1000 / time; System.out.println("Created " + numNodes + " in " + time + " ms. (" + perSecond + " nodes/sec)"); } } catch (RepositoryException e) { e.printStackTrace(); throw new RuntimeException(e); } }
/** * Saves all pending changes. * @throws ObjectBeanPersistenceException */ public void save() throws ObjectBeanPersistenceException { try { session.save(); // also do a refresh, because it is possible that through workflow another jcr session made the changes, and that the current // has no changes, hence a session.save() does not trigger a refresh session.refresh(false); } catch (Exception e) { throw new ObjectBeanPersistenceException(e); } }
private void testName(String name) throws RepositoryException { Exception exception = null; try { session.getRootNode().addNode(name); } catch (RepositoryException e) { exception = e; } finally { session.refresh(false); } session.setNamespacePrefix("foo", "http://foo.bar"); try { session.getRootNode().addNode(name); assertNull("name = " + name, exception); } catch (RepositoryException e) { assertNotNull("name = " + name, exception); } } }
/** * Move a node in a shared set. */ public void testMoveShareableNode() throws Exception { // setup parent nodes and first children Node a1 = testRootNode.addNode("a1"); Node a2 = testRootNode.addNode("a2"); Node b = a1.addNode("b"); testRootNode.getSession().save(); // add mixin ensureMixinType(b, mixShareable); b.getSession().save(); // move Workspace workspace = b.getSession().getWorkspace(); // move shareable node String newPath = a2.getPath() + "/b"; workspace.move(b.getPath(), newPath); // move was performed using the workspace, so refresh the session b.getSession().refresh(false); assertEquals(newPath, b.getPath()); }
@Override public void run() { try { parent.getSession().refresh(false); Node file = JcrUtils.putFile( parent, "file-" + counter++, "application/octet-stream", new TestInputStream(FILE_SIZE * 1024)); parent.getSession().save(); addPath(file.getPath()); } catch (Exception e) { e.printStackTrace(); } }
/** * @since oak */ @Test public void testRegisterPrivilegeWithPendingChanges() throws RepositoryException { try { session.getRootNode().addNode("test"); assertTrue(session.hasPendingChanges()); privilegeManager.registerPrivilege("new", true, new String[0]); fail("Privileges may not be registered while there are pending changes."); } catch (InvalidItemStateException e) { // success } finally { superuser.refresh(false); } }
@Override public void beforeSuite() throws RepositoryException { session = getRepository().login(getCredentials()); try { ensurePropertyIndex(); } catch (InvalidItemStateException e) { // some other oak instance probably created the same // index definition concurrently. refresh and try again // do not catch exception if it fails again. session.refresh(false); ensurePropertyIndex(); } root = session.getRootNode().addNode("testroot" + TEST_ID, "nt:unstructured"); for (int i = 0; i < NODE_COUNT; i++) { Node node = root.addNode("node" + i, "nt:unstructured"); for (int j = 0; j < NODE_COUNT; j++) { Node child = node.addNode("node" + j, "nt:unstructured"); child.setProperty("testcount", j); } session.save(); } }
/** * Removes node property. * * @param nodePath Absolute path to node. * @param propertyName Property name. * @throws RepositoryException if problem with jcr repository occurred */ public void removeNodeProperty(String nodePath, String propertyName) throws RepositoryException { LOG.debug("Removing property '{}' from node '{}'", propertyName, nodePath); session.refresh(true); session.getNode(nodePath).getProperty(propertyName).setValue((String) null); session.save(); }
/** * Tries to register a namespace. */ public void testRegisterNamespace() throws RepositoryException { nsp.registerNamespace(namespacePrefix, namespaceUri); assertEquals("Namespace prefix was not registered.", namespacePrefix, nsp.getPrefix(namespaceUri)); assertEquals("Namespace URI was not registered.", namespaceUri, nsp.getURI(namespacePrefix)); Item created; try { created = testRootNode.addNode(namespacePrefix + ":root"); testRootNode.getSession().save(); } catch (RepositoryException ex) { // that didn't work; maybe the repository allows a property here? testRootNode.getSession().refresh(false); created = testRootNode.setProperty(namespacePrefix + ":root", "test"); testRootNode.getSession().save(); } // Need to remove it here, otherwise teardown can't unregister the NS. testRootNode.getSession().getItem(created.getPath()).remove(); testRootNode.getSession().save(); }
private void moveToHistory(final Node node) { try { // the updater node was modified externally by the executor session.refresh(false); final String srcPath = node.getPath(); final Node history = session.getNode(UPDATE_HISTORY_PATH); String name = node.getName(); int count = 2; while (history.hasNode(name)) { name = node.getName() + "-" + count++; } final String destPath = UPDATE_HISTORY_PATH + "/" + name; session.move(srcPath, destPath); session.save(); } catch (RepositoryException e) { log.error("Failed to remove updater from queue", e); } }
@Override public void beforeSuite() throws RepositoryException { session = getRepository().login(getCredentials()); try { ensurePropertyIndexes(); } catch (InvalidItemStateException e) { // some other oak instance probably created the same // index definition concurrently. refresh and try again // do not catch exception if it fails again. session.refresh(false); ensurePropertyIndexes(); } root = session.getRootNode().addNode("testroot" + TEST_ID, "nt:unstructured"); for (int i = 0; i < NODE_COUNT; i++) { Node node = root.addNode("node" + i, "nt:unstructured"); node.setProperty("jcr:uuid", createUUID(i)); session.save(); } String lookupMode = lookupByQuery ? "query" : "Session#getNodeByIdentifier"; System.out.printf("No of indexes (%s) %d, Lookup by (%s)[%s] %n",noOfIndex, noOfIndex, "lookupByQuery", lookupMode); }
private void markExecuted(final ModuleRegistration registration) { final String moduleName = registration.getModuleName(); final String nodePath = MODULES_PATH + "/" + moduleName; try { final Node node = session.getNode(nodePath); node.setProperty(HippoNodeType.HIPPO_EXECUTED, Calendar.getInstance()); session.save(); } catch (RepositoryException e) { log.error("Failed to mark module {} as executed", moduleName); try { session.refresh(false); } catch (RepositoryException e1) { log.error("Failed to refresh session", e1); } } } }
public void testSetRetentionPolicyBelow() throws RepositoryException, NotExecutableException { Node childN = testRootNode.addNode(nodeName2); superuser.save(); try { retentionMgr.setRetentionPolicy(testNodePath, getApplicableRetentionPolicy()); retentionMgr.setRetentionPolicy(childN.getPath(), getApplicableRetentionPolicy()); superuser.save(); } finally { superuser.refresh(false); if (retentionMgr.getRetentionPolicy(testNodePath) != null) { retentionMgr.removeRetentionPolicy(testNodePath); } if (retentionMgr.getRetentionPolicy(childN.getPath()) != null) { retentionMgr.removeRetentionPolicy(childN.getPath()); } superuser.save(); } }
@Override protected Node doExecute(Node node) throws Exception { GalleryWorkflow workflow = getGalleryWorkflow(node); String nodeName = "asset"; do { nodeName += random.nextInt(10); } while (node.hasNode(nodeName)); Document document = workflow.createGalleryItem(nodeName, "hippogallery:exampleAssetSet"); node.getSession().refresh(false); Node assetNode = document.getNode(node.getSession()); InputStream istream = getClass().getClassLoader().getResourceAsStream("org/onehippo/repository/concurrent/action/Hippo.pdf"); makeImage(assetNode, istream, "application/pdf"); node.getSession().save(); return assetNode; }
private static void ensureIndex(Node root, String propertyName) throws RepositoryException { Node indexDef = root.getNode(IndexConstants.INDEX_DEFINITIONS_NAME); if (indexDef.hasNode(propertyName)) { return; } Node index = indexDef.addNode(propertyName, IndexConstants.INDEX_DEFINITIONS_NODE_TYPE); index.setProperty(IndexConstants.TYPE_PROPERTY_NAME, PropertyIndexEditorProvider.TYPE); index.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true); index.setProperty(IndexConstants.PROPERTY_NAMES, new String[] { propertyName }, PropertyType.NAME); try { root.getSession().save(); } catch (RepositoryException e) { // created by other thread -> ignore root.getSession().refresh(false); } }