javax.jcr.Session.save()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(244)

本文整理了Java中javax.jcr.Session.save()方法的一些代码示例,展示了Session.save()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.save()方法的具体详情如下:
包路径:javax.jcr.Session
类名称:Session
方法名:save

Session.save介绍

[英]Validates all pending changes currently recorded in this Session. If validation of all pending changes succeeds, then this change information is cleared from the Session.

If the save occurs outside a transaction, the changes are dispatched and persisted. Upon being persisted the changes become potentially visible to other Sessions bound to the same persitent workspace.

If the save occurs within a transaction, the changes are dispatched but are not persisted until the transaction is committed.

If validation fails, then no pending changes are dispatched and they remain recorded on the Session. There is no best-effort or partial save.
[中]验证此[$0$]中当前记录的所有挂起的更改。如果所有挂起的更改验证成功,则会从Session中清除此更改信息。
如果save发生在事务之外,则会调度并保留更改。在持久化后,这些更改可能会对绑定到同一持久工作区的其他Sessions可见。
如果save发生在一个事务中,则会发送更改,但在提交事务之前不会持久化。
如果验证失败,则不会发送任何挂起的更改,这些更改将保留在Session上。没有最佳努力或部分save

代码示例

代码示例来源:origin: apache/jackrabbit

public void call() throws RepositoryException {
    testRootNode.addNode(nodeName1, testNodeType).setProperty(propertyName1, "test");
    testRootNode.getSession().save();
  }
}, Event.PROPERTY_ADDED);

代码示例来源:origin: info.magnolia/magnolia-core

protected void version(Node node, Context context) throws RepositoryException {
  if (isVersionManually()) {
    String comment = (String) context.get("comment");
    if (comment == null) {
      comment = "versions.comment.deleted";
    }
    node.setProperty(NodeTypes.Deleted.COMMENT, comment);
    node.getSession().save();
    versionManager.addVersion(node, getRule());
  }
}

代码示例来源:origin: info.magnolia/magnolia-core

private void setupProperties(String prop1Name, String prop1Val, String prop2Name, String prop2Val) throws Exception {
  Session session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
  parent = session.getRootNode().addNode("parent");
  parent.setProperty(prop1Name, prop1Val);
  parent.setProperty(prop2Name, prop2Val);
  child = parent.addNode("child");
  child.setProperty(prop1Name, prop1Val);
  child.setProperty(prop2Name, prop2Val);
  session.save();
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test(expected = AccessDeniedException.class)
public void testExecuteIsDeniedIfUserIsNull() throws Exception {
  // GIVEN
  when(ctx.get(MarkNodeAsDeletedCommand.DELETED_NODE_PROP_NAME)).thenReturn("nodeToDelete");
  Node nodeToDelete = MgnlContext.getJCRSession("website").getRootNode().addNode("nodeToDelete", NodeTypes.Folder.NAME);
  nodeToDelete.getSession().save();
  doReturn(null).when(systemContext).getUser();
  // WHEN
  cmd.execute(ctx);
  // THEN - AccessDeniedException
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testWorkspaceReturnsLogicalName4() throws RepositoryException {
  // GIVEN
  Node root = MgnlContext.getJCRSession("magnolia-mgnlSystem").getRootNode();
  root.addNode("test", NodeTypes.ContentNode.NAME).setProperty("testProp", "testVal");
  root.getSession().save();
  // WHEN
  String name = root.getNode("test").getProperty("testProp").getParent().getSession().getWorkspace().getName();
  // THEN
  assertTrue(name.equals("magnolia-mgnlSystem"));
}

代码示例来源:origin: apache/jackrabbit

@Override
protected void tearDown() throws Exception {
  for (Node c : JcrUtils.getChildNodes(testRootNode)) {
    testRootNode.getSession().removeItem(c.getPath());
  }
  testRootNode.getSession().save();
  super.tearDown();
}

代码示例来源:origin: info.magnolia/magnolia-core

private void prepareGroupData() throws Exception {
  String peopleGroup = "people";
  String employeesGroup = "employees";
  String developersGroup = "developers";
  // Create a group (developers) which has an assigned group (employees) which again has an assigned group (people)
  final Node developersNode = session.getRootNode().addNode(developersGroup, NodeTypes.Group.NAME);
  final Node employeesNode = session.getRootNode().addNode(employeesGroup, NodeTypes.Group.NAME);
  final Node peopleNode = session.getRootNode().addNode(peopleGroup, NodeTypes.Group.NAME);
  developersNode.addNode(RepositoryBackedSecurityManager.GROUPS_NODE_NAME, NodeTypes.ContentNode.NAME).setProperty("0", employeesNode.getIdentifier());
  employeesNode.addNode(RepositoryBackedSecurityManager.GROUPS_NODE_NAME, NodeTypes.ContentNode.NAME).setProperty("0", peopleNode.getIdentifier());
  session.save();
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test(expected = IllegalArgumentException.class)
public void testNodeMultipleWrap() throws RepositoryException {
  // GIVEN
  Node root = MgnlContext.getJCRSession("magnolia-mgnlSystem").getRootNode();
  Node node = root.addNode("test", NodeTypes.ContentNode.NAME);
  root.getSession().save();
  // WHEN
  new MgnlLogicalWorkspaceNameMappingWorkspaceDecorator("magnolia-mgnlSystem", "mgnlSystem").wrapNode(node);
  // THEN
  // exception is thrown
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testWorkspaceReturnsLogicalName3() throws RepositoryException {
  // GIVEN
  Node root = MgnlContext.getJCRSession("magnolia-mgnlSystem").getRootNode();
  root.addNode("test", NodeTypes.ContentNode.NAME).setProperty("testProp", "testVal");
  root.getSession().save();
  // WHEN
  String name = root.getNode("test").getProperty("testProp").getSession().getWorkspace().getName();
  // THEN
  assertTrue(name.equals("magnolia-mgnlSystem"));
}

代码示例来源:origin: apache/jackrabbit

public void call() throws RepositoryException {
    testRootNode.addNode(nodeName1, testNodeType).setProperty(propertyName1, "test");
    testRootNode.getSession().save();
  }
}, Event.PROPERTY_ADDED);

代码示例来源:origin: apache/jackrabbit

@Override
protected void tearDown() throws Exception {
  for (Node c : JcrUtils.getChildNodes(testRootNode)) {
    testRootNode.getSession().removeItem(c.getPath());
  }
  superuser.save();
  super.tearDown();
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void sequenceCreateModifyDelete() throws RepositoryException {
  Node node = session.getRootNode().addNode("new-site");
  node.setProperty("title", "newTitle");
  node.remove();
  session.save();
  assertEquals(0, audit.records.size());
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test(expected = AccessDeniedException.class)
public void testExecuteChecksForUserPermissions() throws Exception {
  // GIVEN
  doReturn(false).when(ami).isGranted(anyString(), anyLong());
  when(ctx.get(MarkNodeAsDeletedCommand.DELETED_NODE_PROP_NAME)).thenReturn("nodeToDelete");
  Node nodeToDelete = MgnlContext.getJCRSession("website").getRootNode().addNode("nodeToDelete", NodeTypes.Folder.NAME);
  nodeToDelete.getSession().save();
  // WHEN
  cmd.execute(ctx);
  // THEN - AccessDeniedException
}

代码示例来源:origin: apache/jackrabbit

/**
 * Creates two nodes with name {@link #nodeName1} and {@link #nodeName2}
 * with nodetype {@link #testNodeType}. The node type must allow a String
 * property with name {@link #propertyName1} which is fulltext indexed.
 */
protected void setUpFullTextTest() throws RepositoryException {
  Node node = testRootNode.addNode(nodeName1, testNodeType);
  node.setProperty(propertyName1, "The quick brown fox jumps over the lazy dog.");
  node = testRootNode.addNode(nodeName2, testNodeType);
  node.setProperty(propertyName1, "The quick brown cat jumps over the lazy dog.");
  testRootNode.getSession().save();
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testPathProperty() throws Exception {
  Session session = getAdminSession();
  Node testRootNode = session.getRootNode().addNode("testRoot");
  try {
    testRootNode.setProperty("testPathProperty", "/foobar:test", PropertyType.PATH);
    session.save();
    fail("adding a  path property without registered namespace must fail.");
  } catch (RepositoryException e) {
    // ok.
  }
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testIsNotNodeTypeForNodeCheckFrozenTypeIfWereNotLookingForFrozenNodes() throws Exception {
  // GIVEN
  final Node node = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE).getRootNode().addNode("testPage", NodeTypes.Content.NAME);
  node.addMixin(JcrConstants.MIX_VERSIONABLE);
  node.getSession().save();
  final Node version = versionManager.addVersion(node, new Rule(NodeTypes.ContentNode.NAME, ",")).getFrozenNode();
  // WHEN-THEN
  assertFalse(NodeUtil.isNodeType(version, NodeTypes.ContentNode.NAME));
}

代码示例来源:origin: apache/jackrabbit

/**
 * Tests if the path of the created node is correct.
 */
public void testPath() throws RepositoryException {
  Node n1 = testRootNode.addNode(nodeName1, testNodeType);
  testRootNode.getSession().save();
  String expected = testRootNode.getPath() + "/" + nodeName1;
  assertEquals("Wrong path for created node.", expected, n1.getPath());
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testInvalidPathProperty() throws Exception {
  Session session = getAdminSession();
  Node testRootNode = session.getRootNode().addNode("testRoot");
  try {
    testRootNode.setProperty("testPathProperty", "/*/dfsdf", PropertyType.PATH);
    session.save();
    fail("adding a  path property without registered namespace must fail.");
  } catch (RepositoryException e) {
    // ok.
  }
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testIsNodeTypeForNodeCheckFrozenTypeIfWereNotLookingForFrozenNodes() throws Exception {
  // GIVEN
  final Node node = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE).getRootNode().addNode("testPage", NodeTypes.ContentNode.NAME);
  node.addMixin(JcrConstants.MIX_VERSIONABLE);
  node.getSession().save();
  final Node version = versionManager.addVersion(node, new Rule(NodeTypes.ContentNode.NAME, ",")).getFrozenNode();
  // WHEN-THEN
  assertTrue(NodeUtil.isNodeType(version, NodeTypes.ContentNode.NAME));
}

代码示例来源:origin: apache/jackrabbit

/**
 * Tests if text() node test is equivalent with jcr:xmltext.
 * @throws NotExecutableException 
 */
public void testTextNodeTest() throws RepositoryException, NotExecutableException {
  Node text1 = testRootNode.addNode(jcrXMLText);
  text1.setProperty(jcrXMLCharacters, "foo");
  testRootNode.getSession().save();
  String xpath = "/" + jcrRoot + testRoot + "/text()";
  executeXPathQuery(superuser, xpath, new Node[]{text1});
}

相关文章

微信公众号

最新文章

更多