本文整理汇总了Java中org.apache.sling.api.resource.ResourceResolver.commit方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceResolver.commit方法的具体用法?Java ResourceResolver.commit怎么用?Java ResourceResolver.commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.resource.ResourceResolver
的用法示例。
在下文中一共展示了ResourceResolver.commit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: operate
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
* Do some operation on repository (delete or update resource etc) with wrapped impersonated session
* (automatically opened and closed).
*/
public static void operate(ResourceResolverFactory factory, String userId, OperateCallback callback)
throws OperateException {
ResourceResolver resolver = null;
try {
resolver = getResourceResolverForUser(factory, userId);
callback.operate(resolver);
resolver.commit();
} catch (Exception e) {
throw new OperateException(OPERATE_ERROR_MESSAGE, e);
} finally {
if (resolver != null && resolver.isLive()) {
resolver.close();
}
}
}
示例2: call
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public Void call() throws Exception {
if ( rrf == null ) {
throw new IllegalStateException("ResourceResolverFactory not injected");
}
@SuppressWarnings("deprecation") // fine for testing
ResourceResolver rr = rrf.getAdministrativeResourceResolver(null);
try {
call0(rr);
rr.commit();
} finally {
if ( rr != null ) {
rr.close();
}
}
return null;
}
示例3: execute
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public String execute(ResourceResolver resourceResolver) {
JcrObservationThrottle jcrObservationThrottle = null;
try {
// Create the unique, temp node under which the event queue will be stored.
// Your resourceResolver must have permissions to create / modify / delete this node.
final String tmpPath = "/tmp/jcr-event-throttle/" + this.getClass().getName() + "/" + UUID.randomUUID().toString();
final Node tmpNode = JcrUtils.getOrCreateByPath(tmpPath, JcrConstants.NT_UNSTRUCTURED, resourceResolver.adaptTo(Session.class));
// Create a new JcrObservationThrottle for this operation and pass in the tmpNode that will record/queue the events
jcrObservationThrottle = new JcrObservationThrottle(tmpNode);
// Start listening against this JCR Session
jcrObservationThrottle.open();
for (int i = 0; i < 10000; i++) {
// Do a bunch of writes to the JCR
if (i % 10 == 0) {
// You can perform multiple saves and "trap" the events in this throttle
resourceResolver.commit();
}
}
if (resourceResolver.hasChanges()) {
// Commit and lagging commits from the work loop above
resourceResolver.commit();
}
log.debug("Waiting for throttled observation events to be delivered.");
// *** WARNING ***
// The amount of time to wait is determined by the event activity of the system at this point in time, so be conscious of this.
final long t = jcrObservationThrottle.waitForEvents();
log.info("Waited [ {} ] ms for throttled observation events to be delivered", t);
} catch (RepositoryException | PersistenceException e) {
log.error("Something bad happened!", e);
} finally {
if (jcrObservationThrottle != null) {
// Always close the JcrObervationThrottle in a finally black to ensure it gets closed.
jcrObservationThrottle.close();
}
}
return null;
}
示例4: getGlobalPropertiesPath
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
/**
* Takes resource and resource resolver return the global property path from the resource
*
* @param resource The resource to get the global property path from
* @return globalPropertiesPath
*/
public static String getGlobalPropertiesPath(Resource resource, ResourceResolver resourceResolver)
throws RepositoryException, PersistenceException {
String globalPropertiesPath = "";
Designer designer = resourceResolver.adaptTo(Designer.class);
Style style = designer.getStyle(resource);
Design design;
if (null != style) {
design = style.getDesign();
if (null != design) {
if (null != design.getContentResource()) {
if (null != design.getContentResource().getPath()) {
//add global node in design when it does not exist
Resource designResource = resourceResolver.getResource(design.getContentResource().getPath());
Node designNode = designResource.adaptTo(Node.class);
if (!designNode.hasNode(GLOBAL_PROPERTIES_KEY)) {
designNode.addNode(GLOBAL_PROPERTIES_KEY);
resourceResolver.commit();
}
// set global path
globalPropertiesPath = design.getContentResource().getPath() + GLOBAL_PATH;
}
}
}
}
return globalPropertiesPath;
}
示例5: replicate
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public void replicate(Script script, ResourceResolver resolver) throws ExecutionException,
ReplicationException, PersistenceException {
eventManager.trigger(Event.BEFORE_REPLICATE, script);
final List<Script> includes = new LinkedList<>();
includes.add(script);
includes.addAll(scriptManager.findIncludes(script, resolver));
final boolean autocommit = true;
final Resource includeDir = ResourceUtil
.getOrCreateResource(resolver, REPLICATION_PATH, JcrConstants.NT_UNSTRUCTURED,
JcrConstants.NT_UNSTRUCTURED, autocommit);
for (final Script include : includes) {
final String path = (script.equals(include) ? SCRIPT_PATH : REPLICATION_PATH) + "/" + FilenameUtils
.getName(include.getPath());
LOG.warn("Copying {} to {}", include.getPath(), includeDir.getPath());
copy(resolver, include.getPath(), includeDir);
resolver.commit();
final Session session = resolver.adaptTo(Session.class);
replicator.replicate(session, ReplicationActionType.ACTIVATE, path);
}
resolver.delete(includeDir);
resolver.commit();
eventManager.trigger(Event.AFTER_REPLICATE, script);
}
示例6: save
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
public void save(ResourceResolver resolver, String checksum) {
try {
Resource storage = getOrCreateChecksumStorage(resolver, CHECKSUM_STORAGE_PATH);
storage.adaptTo(ModifiableValueMap.class).put(filename, checksum);
resolver.commit();
} catch (PersistenceException e) {
LOG.error("Cannot update checksum for {} script", filename, e);
}
}
示例7: updateFormStructure
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public Resource updateFormStructure(Resource formResource) {
if (formResource != null) {
ResourceResolver resolver = formResource.getResourceResolver();
if (isFormContainer(formResource)) {
// add default action type, form id and action path
ModifiableValueMap formProperties = formResource.adaptTo(ModifiableValueMap.class);
if (formProperties != null) {
try {
if (formProperties.get(FormsConstants.START_PROPERTY_ACTION_TYPE,
String.class) == null) {
formProperties.put(FormsConstants.START_PROPERTY_ACTION_TYPE,
FormsConstants.DEFAULT_ACTION_TYPE);
String defaultContentPath = "/content/usergenerated" +
formResource.getPath().replaceAll("^.content", "").replaceAll("jcr.content.*", "") +
"cq-gen" + System.currentTimeMillis() + "/";
formProperties.put(FormsConstants.START_PROPERTY_ACTION_PATH,
defaultContentPath);
}
resolver.commit();
} catch (PersistenceException e) {
LOGGER.error("Unable to add default action type and form id " + formResource, e);
}
} else {
LOGGER.error("Resource is not adaptable to ValueMap - unable to add default action type and " +
"form id for " + formResource);
}
}
}
return null;
}
示例8: doWork
import org.apache.sling.api.resource.ResourceResolver; //导入方法依赖的package包/类
@Override
public final void doWork(final ResourceResolver resourceResolver) throws PersistenceException {
// Generally you always want to pass in the security context (JCR Session/Resource Resolver, Resource, etc.)
// into OSGi services rather than using administrative level repo access.
// Do some work...
Resource resource = resourceResolver.getResource("/content/some/resource");
ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);
properties.put("workDone", true);
resourceResolver.commit();
}