本文整理汇总了Java中javax.jcr.Session.save方法的典型用法代码示例。如果您正苦于以下问题:Java Session.save方法的具体用法?Java Session.save怎么用?Java Session.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jcr.Session
的用法示例。
在下文中一共展示了Session.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import javax.jcr.Session; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp();
Session session = openSession();
Node node = session.getRootNode().addNode("home").addNode("test");
node.setProperty("content.approved", APPROVED);
node.setProperty("my.contents.property", CONTENT);
ValueFactory valFact = session.getValueFactory();
Value[] vals = new Value[] {valFact.createValue("value-1"), valFact.createValue("value-2")};
node.setProperty("my.multi.valued", vals);
identifier = node.getIdentifier();
session.save();
session.logout();
}
示例2: testExpandMultivalue
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* jsonfn.from(content).expand("baz", "category").print()
*
* ==> { "foo" : "hahaha", "baz" : {"identifier" : "1234-123456-1234", "name" : "cat1"}, b: 1234, "bar" : "meh", ... }
*/
@Test
public void testExpandMultivalue() throws Exception {
// GIVEN
Node node = session.getNode("/home/section2/article/mgnl:apex");
Session catSession = catNode.getSession();
catSession.getWorkspace().copy(catNode.getPath(), "/othercat");
catSession.save();
Node catNode2 = catSession.getNode("/othercat");
node.setProperty("baz", new String[] { catNode.getIdentifier(), catNode2.getIdentifier() });
node.save();
// WHEN
String json = JsonTemplatingFunctions.from(node).expand("baz", "category").add("@id").print();
// THEN
assertThat(json, startsWith("{"));
// [{ == array of props ;)
assertThat(json, containsString("\"baz\" : [ {"));
assertThat(json, containsString("" + catNode.getIdentifier()));
assertThat(json, containsString("" + catNode2.getIdentifier()));
assertThat(json, endsWith("}"));
}
示例3: testSubNodePropertyListingWithExclusionOfParent
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* Lists specified properties only for sub nodes but not for the parent nodes. Issue #21.
*
*/
@Test
public void testSubNodePropertyListingWithExclusionOfParent() throws Exception {
Session session = MgnlContext.getInstance().getJCRSession("website");
// GIVEN
Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
node.addNode("tab0","mgnl:content");
node.addNode("tab1","mgnl:content");
node.addNode("tab2","mgnl:content");
session.save();
// WHEN
String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
.down(1).add( "tab(.+)['@id']").inline().print();
// THEN
assertThat(json, startsWith("{"));
assertThat(json, containsString("\"tab1\":{\"@id\""));
assertThat(json, not(containsString("},\"@id\":")));
assertThat(json, containsString("},\"tab2\":{\"@id\":"));
assertThat(json, endsWith("}"));
}
示例4: testSubNodeWithSamePropertyAsOneOfAncestors
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* Lists specified properties only for parent nodes but not for the subnodes. Issue #16.
*
*/
@Test
public void testSubNodeWithSamePropertyAsOneOfAncestors() throws Exception {
Session session = MgnlContext.getInstance().getJCRSession("website");
// GIVEN
Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
node.setProperty("abstract", "foo");
Node child = node.addNode("linkInternal","mgnl:content");
child.setProperty("abstract", "foo");
session.save();
// WHEN
String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
.down(3).add("alias['abstract']").exclude("linkInternal['abstract']").inline().print();
// THEN
assertThat(json, startsWith("{"));
assertThat(json, containsString("{\"abstract\":\"foo\"}"));
assertThat(json, endsWith("}"));
}
示例5: testSubNodeWithSystemPropertyNameAsOneOfAncestors
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* Lists specified properties only for parent nodes but not for the subnodes. Issue #16.
*
*/
@Test
public void testSubNodeWithSystemPropertyNameAsOneOfAncestors() throws Exception {
Session session = MgnlContext.getInstance().getJCRSession("website");
// GIVEN
Node node = session.getNode("/home/section2/article/mgnl:apex/alias");
node.setProperty("abstract", "foo");
Node child = node.addNode("linkInternal","mgnl:content");
child.setProperty("abstract", "foo");
session.save();
// WHEN
String json = JsonTemplatingFunctions.from(session.getNode("/home/section2/article/mgnl:apex/alias"))
.down(3).add("alias['@id']").exclude("linkInternal['@id']").inline().print();
// THEN
assertThat(json, startsWith("{"));
assertThat(json, containsString("{\"@id\":\""));
assertEquals(json.split("id").length, 2);
assertThat(json, endsWith("}"));
}
示例6: testPerformance
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* Test performance.
*/
@Test
public void testPerformance() throws Exception {
Session session = MgnlContext.getInstance().getJCRSession("website");
for (int i = 0; i < 100; i++) {
session.getWorkspace().copy("/home/section", "/home/section0" + i);
}
session.save();
int count = 10;
long stamp = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
// WHEN
singleRun();
}
long res = System.currentTimeMillis() - stamp;
res = res / count;
assertTrue(res < 4000);
}
示例7: deleteComment
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* Delete comment by setting it's display property to false.
*
* @param request The current request to get session and Resource Resolver
* @param id The comment UUID
* @return true if the operation was successful
*/
public boolean deleteComment(final SlingHttpServletRequest request, final String id) {
boolean result = false;
try {
Session session = request.getResourceResolver().adaptTo(Session.class);
Node node = session.getNodeByIdentifier(id);
if (node != null) {
JcrResourceUtil.setProperty(node, PublickConstants.COMMENT_PROPERTY_DISPLAY, false);
session.save();
result = true;
}
} catch (RepositoryException e) {
LOGGER.error("Could not delete comment from JCR", e);
}
return result;
}
示例8: editComment
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* Edit comment and mark it as author edited.
*
* @param request The current request to get session and Resource Resolver
* @param id The comment UUID
* @param text The comment text
* @return true if the operation was successful
*/
public boolean editComment(final SlingHttpServletRequest request, final String id, String text) {
boolean result = false;
try {
Session session = request.getResourceResolver().adaptTo(Session.class);
Node node = session.getNodeByIdentifier(id);
if (node != null) {
JcrResourceUtil.setProperty(node, PublickConstants.COMMENT_PROPERTY_COMMENT, text);
JcrResourceUtil.setProperty(node, PublickConstants.COMMENT_PROPERTY_EDITED, true);
session.save();
result = true;
}
} catch (RepositoryException e) {
LOGGER.error("Could not update comment from JCR", e);
}
return result;
}
示例9: curePhase
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* The purpose of this method is to check for some conditions which may break Phases.
*
* @param boardId
* @param phaseId
* @return
* @throws Exception
*/
@PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
@RequestMapping(value = "/{phaseId}/cure", method=RequestMethod.GET)
public @ResponseBody Boolean curePhase(@PathVariable String boardId,
@PathVariable String phaseId) throws Exception {
Session session = ocmFactory.getOcm().getSession();
try{
Node node = session.getNode(String.format(URI.PHASES_URI, boardId, phaseId));
Property property = node.getProperty("cards");
// If there is a property we need to kill it.
property.remove();
session.save();
} catch (PathNotFoundException e){
// This is expected - there should be no property.
} finally {
session.logout();
}
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
return true;
}
示例10: getIdFromRepository
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* This method
* @param session
* @param path
* @return
* @throws Exception
*/
public synchronized static Long getIdFromRepository( Session session, String path, String id) throws Exception {
Long returnId = null;
//LockManager lockManager = session.getWorkspace().getLockManager();
try{
//Lock lock = lockManager.lock(path, false, false, 30000l, "");
//Node node = lock.getNode();
Node node = session.getNode(path);
try {
Property property = node.getProperty(id);
returnId = property.getLong();
} catch (PathNotFoundException e) {
returnId = 10001l;
}
node.setProperty(id, returnId+1);
session.save();
} finally {
//lockManager.unlock(path);
}
return returnId;
}
示例11: ensurePresence
import javax.jcr.Session; //导入方法依赖的package包/类
public void ensurePresence(Session session, String initialPath, String... nodeNames) throws PathNotFoundException, RepositoryException {
if (null != nodeNames) {
final String childNodeName = nodeNames[0];
final Node parentNode = session.getNode(initialPath);
final Node childNode;
if (parentNode.hasNode(childNodeName)) {
childNode = parentNode.getNode(childNodeName);
} else {
childNode = parentNode.addNode(childNodeName);
session.save();
}
if (nodeNames.length > 1) {
ensurePresence(session, childNode.getPath(), Arrays.copyOfRange(nodeNames, 1, nodeNames.length));
}
}
}
示例12: getJcrFromFixture
import javax.jcr.Session; //导入方法依赖的package包/类
public Session getJcrFromFixture(InputStream fixture) {
Repository repository = null;
Session session = null;
try {
repository = MockJcr.newRepository();
session = repository.login();
Node rootNode = session.getRootNode();
Yaml parser = new Yaml();
List<Map<String, Object>> nodes = (ArrayList<Map<String, Object>>) parser.load(fixture);
for (Map object: nodes) {
NodeYaml node = new NodeYaml(
(String) object.get("path"),
(String) object.get("primaryType"),
(Map<String, Object>) object.getOrDefault("properties", emptyMap())
);
Node n = rootNode.addNode(node.path, node.primaryType);
for (Map.Entry<String, Object> entry : node.properties.entrySet()) {
if (entry.getValue() instanceof Boolean) {
n.setProperty(entry.getKey(), (Boolean) entry.getValue());
} else {
n.setProperty(entry.getKey(), entry.getValue().toString());
}
}
}
session.save();
} catch (RepositoryException e) {
throw new RuntimeException("Failed to set property on JCR node", e);
}
return session;
}
示例13: deleteNode
import javax.jcr.Session; //导入方法依赖的package包/类
/**
* Deletes node under specified path.
*
* @param nodePath Absolute path to node.
* @param session jcr session
* @throws RepositoryException if problem with jcr repository occurred
*/
public void deleteNode(String nodePath, Session session) throws RepositoryException {
LOG.debug("Deleting node '{}'", nodePath);
if (session.nodeExists(nodePath)) {
session.removeItem(nodePath);
session.save();
}
}
示例14: trackScriptEnd
import javax.jcr.Session; //导入方法依赖的package包/类
protected void trackScriptEnd(Session session, Node statusNode, String statusNodePath, String status) {
try {
statusNode.setProperty("status", status);
statusNode.setProperty("endDate", Calendar.getInstance());
session.save();
} catch (RepositoryException e) {
logger.warn("On-deploy script status node could not be updated: {} - status: {}", statusNodePath, status);
}
}
示例15: trackScriptStart
import javax.jcr.Session; //导入方法依赖的package包/类
protected void trackScriptStart(Session session, Node statusNode, String statusNodePath) {
logger.info("Starting on-deploy script: {}", statusNodePath);
try {
statusNode.setProperty("status", "running");
statusNode.setProperty("startDate", Calendar.getInstance());
statusNode.setProperty("endDate", (Calendar) null);
session.save();
} catch (RepositoryException e) {
logger.error("On-deploy script cannot be run because the system could not write to the script status node: {}", statusNodePath);
throw new OnDeployEarlyTerminationException(e);
}
}