001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.http.commons.session; 019 020import org.fcrepo.kernel.api.FedoraSession; 021 022/** 023 * Provide a batch-aware HTTP session 024 * @author acoburn 025 */ 026public class HttpSession { 027 028 private boolean batch = false; 029 030 private final FedoraSession session; 031 032 /** 033 * Create an HTTP session from a Fedora session 034 * @param session the Fedora session 035 * Note: by default, the HTTP Session is not marked as a batch operation. 036 * Client code must call makeBatch in order to promote the session into 037 * a batch operation. 038 */ 039 public HttpSession(final FedoraSession session) { 040 this.session = session; 041 } 042 043 /** 044 * Make this HTTP Session into a batch operation. 045 */ 046 public void makeBatchSession() { 047 this.batch = true; 048 } 049 050 /** 051 * Commit a non-batch session 052 */ 053 public void commit() { 054 if (!isBatchSession()) { 055 session.commit(); 056 } 057 } 058 059 /** 060 * Expire a non-batch session 061 */ 062 public void expire() { 063 if (!isBatchSession()) { 064 session.expire(); 065 } 066 } 067 068 /** 069 * Return whether this session is part of a batch operation 070 * @return whether this session is part of a batch operation 071 */ 072 public boolean isBatchSession() { 073 return batch; 074 } 075 076 /** 077 * Return the id of the underlying session 078 * @return the session identifier 079 */ 080 public String getId() { 081 return session.getId(); 082 } 083 084 /** 085 * Return the underlying FedoraSession 086 * @return the FedoraSession 087 */ 088 public FedoraSession getFedoraSession() { 089 return session; 090 } 091}