当前位置: 首页>>代码示例>>Java>>正文


Java ResourceResolver.commit方法代码示例

本文整理汇总了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();
		}
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:20,代码来源:SlingHelper.java

示例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;
}
 
开发者ID:auniverseaway,项目名称:aem-touch-admin-console,代码行数:20,代码来源:HelloWorldModelServerSideTest.java

示例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;
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:47,代码来源:SampleJcrObservationThrottle.java

示例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;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:33,代码来源:ResourceUtils.java

示例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);
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:30,代码来源:ScriptReplicatorImpl.java

示例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);
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:10,代码来源:Checksum.java

示例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;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:32,代码来源:FormStructureHelperImpl.java

示例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();
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:12,代码来源:SampleServiceImpl.java


注:本文中的org.apache.sling.api.resource.ResourceResolver.commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。