1 package org.apache.archiva.metadata.repository.jcr;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.metadata.repository.MetadataResolver;
23 import org.apache.archiva.metadata.repository.MetadataSessionException;
24 import org.apache.archiva.metadata.repository.RepositorySession;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import javax.jcr.RepositoryException;
29 import javax.jcr.Session;
33 * Session implementation for a JCR repository.
35 * @author Martin Stockhammer <martin_s@apache.org>
37 public class JcrSession extends RepositorySession implements AutoCloseable
40 private static final Logger log = LoggerFactory.getLogger( JcrSession.class );
42 private Session jcrSession;
43 private JcrMetadataRepository repository;
45 public JcrSession( JcrMetadataRepository metadataRepository, MetadataResolver resolver) throws RepositoryException
47 super( metadataRepository, resolver );
48 this.repository = metadataRepository;
49 this.jcrSession = metadataRepository.login();
52 public Session getJcrSession() {
56 public JcrMetadataRepository getJcrRepository() {
68 protected boolean isDirty( )
70 if (super.isDirty()) {
75 return jcrSession.hasPendingChanges( );
77 catch ( RepositoryException e )
79 log.error( "Could not check pending changes {}", e.getMessage( ) );
85 public void save( ) throws MetadataSessionException
92 catch ( RepositoryException e )
94 throw new MetadataSessionException( e.getMessage( ), e );
99 public void revert( ) throws MetadataSessionException
104 jcrSession.refresh( false );
106 catch ( RepositoryException e )
108 throw new MetadataSessionException( e.getMessage( ), e );
113 public void refresh() throws MetadataSessionException {
115 jcrSession.refresh(true);
116 } catch (RepositoryException e) {
117 throw new MetadataSessionException(e.getMessage(), e);
122 public void refreshAndDiscard() throws MetadataSessionException {
124 jcrSession.refresh(false);
125 } catch (RepositoryException e) {
126 throw new MetadataSessionException(e.getMessage(), e);