1 23 package org.apache.slide.store.mem; 24 25 import org.apache.slide.common.ServiceAccessException; 26 import org.apache.slide.common.Uri; 27 import org.apache.slide.content.NodeRevisionContent; 28 import org.apache.slide.content.NodeRevisionDescriptor; 29 import org.apache.slide.content.RevisionAlreadyExistException; 30 import org.apache.slide.content.RevisionNotFoundException; 31 import org.apache.slide.store.ContentStore; 32 33 34 36 public class TransientContentStore extends AbstractTransientStore implements 37 ContentStore 38 { 39 41 public NodeRevisionContent retrieveRevisionContent(Uri uri, 42 NodeRevisionDescriptor revisionDescriptor) 43 throws ServiceAccessException, RevisionNotFoundException 44 { 45 VersionedUriKey key = new VersionedUriKey(uri, 46 revisionDescriptor.getRevisionNumber()); 47 debug("retrieveRevisionContent {0}", key); 48 49 byte[] content = (byte[])get(key); 50 if (content != null) { 51 NodeRevisionContent revisionContent = new NodeRevisionContent(); 52 revisionContent.setContent(content); 53 return revisionContent; 54 } else { 55 throw new RevisionNotFoundException(uri.toString(), 56 revisionDescriptor.getRevisionNumber()); 57 } 58 } 59 60 public void createRevisionContent(Uri uri, 61 NodeRevisionDescriptor revisionDescriptor, 62 NodeRevisionContent revisionContent) throws ServiceAccessException, 63 RevisionAlreadyExistException 64 { 65 VersionedUriKey key = new VersionedUriKey(uri, 66 revisionDescriptor.getRevisionNumber()); 67 debug("createRevisionContent {0}", key); 68 69 byte[] content = (byte[])get(key); 70 if (content == null) { 71 put(key, revisionContent.getContentBytes()); 72 } else { 73 throw new RevisionAlreadyExistException(uri.toString(), 74 revisionDescriptor.getRevisionNumber()); 75 } 76 } 77 78 public void storeRevisionContent(Uri uri, 79 NodeRevisionDescriptor revisionDescriptor, 80 NodeRevisionContent revisionContent) throws ServiceAccessException, 81 RevisionNotFoundException 82 { 83 VersionedUriKey key = new VersionedUriKey(uri, 84 revisionDescriptor.getRevisionNumber()); 85 debug("storeRevisionContent {0}", key); 86 87 byte[] content = (byte[])get(key); 88 if (content != null) { 89 put(key, revisionContent.getContentBytes()); 90 } else { 91 throw new RevisionNotFoundException(uri.toString(), 92 revisionDescriptor.getRevisionNumber()); 93 } 94 } 95 96 public void removeRevisionContent(Uri uri, 97 NodeRevisionDescriptor revisionDescriptor) 98 throws ServiceAccessException 99 { 100 VersionedUriKey key = new VersionedUriKey(uri, 101 revisionDescriptor.getRevisionNumber()); 102 debug("storeRevisionContent {0}", key); 103 104 remove(key); 105 } 106 } 107 | Popular Tags |