FileDocCategorySizeDatePackage
StorageImplementation.javaAPI DocApache Lucene 2.1.022742Wed Feb 14 10:46:04 GMT 2007org.apache.lucene.gdata.storage.lucenestorage

StorageImplementation

public class StorageImplementation extends Object implements org.apache.lucene.gdata.storage.Storage
This is an implementation of the {@link org.apache.lucene.gdata.storage.Storage} interface. The StorageImplementation provides access to the {@link org.apache.lucene.gdata.storage.lucenestorage.StorageQuery} and the {@link org.apache.lucene.gdata.storage.lucenestorage.StorageModifier}. This class will be instantiated per client request.
author
Simon Willnauer

Fields Summary
private final StorageCoreController
controller
private static final Log
LOG
Constructors Summary
public StorageImplementation()
Creates a new StorageImplementation

throws
StorageException - if the storage controller can not be obtained


                                        
        
        this.controller = (StorageCoreController) GDataServerRegistry
                .getRegistry().lookup(StorageController.class,
                        ComponentType.STORAGECONTROLLER);
        if (this.controller == null)
            throw new StorageException("Can't get registered StorageController");
    
Methods Summary
public voidclose()

see
org.apache.lucene.gdata.storage.Storage#close()

        //
    
public voiddeleteAccount(java.lang.String Accountname)

see
org.apache.lucene.gdata.storage.Storage#deleteAccount(java.lang.String)

        if (Accountname == null)
            throw new StorageException("can not delete null Account");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            if (query.get().getUser(Accountname) == null)
                throw new StorageException("Account does not exist");
            StorageModifier modifier = this.controller.getStorageModifier();
            modifier.deleteAccount(Accountname);
        } catch (Exception e) {
            LOG.error("Can't update Account -- " + e.getMessage(), e);
            StorageException ex = new StorageException(
                    "Can't update Account -- " + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        } finally {
            if (query != null)
                query.decrementRef();
        }
    
public voiddeleteEntry(org.apache.lucene.gdata.data.ServerBaseEntry entry)

see
org.apache.lucene.gdata.storage.Storage#deleteEntry(org.apache.lucene.gdata.data.ServerBaseEntry)


        if (entry == null)
            throw new StorageException("Entry is null");
        if(entry.getId() == null)
            throw new StorageException("Entry id is null");
        if(entry.getFeedId() == null)
            throw new StorageException("feed id is null");
        if (LOG.isInfoEnabled())
            LOG.info("delete entry " + entry.getId() + " -- feed: "
                    + entry.getFeedId());
        StorageModifier modifier = this.controller.getStorageModifier();
        ReferenceCounter<StorageQuery> query = this.controller.getStorageQuery();
        // try to set concurrency Lock
        String key = entry.getId();
        setLock(key);
        try{
        if(query.get().isEntryStored(entry.getId(),entry.getFeedId())){
            if(query.get().checkEntryVersion(entry.getId(),entry.getFeedId(),entry.getVersion())){
                modifier.deleteEntry(new StorageEntryWrapper(entry,StorageOperation.DELETE));
            }else
                throw new ModificationConflictException("The entry version does not match -- entry "+entry.getId()+" feed:"+entry.getFeedId()+" version: "+entry.getVersion());
        }
        else
            throw new ResourceNotFoundException("Entry for entry id: "+entry.getId()+" is not stored");
        }catch (IOException e) {
            throw new StorageException("Can not access storage");
        }finally{
            if(query != null)
                query.decrementRef();
            // release lock for concurrency
            releaseLock(key);
        }
    
public voiddeleteFeed(java.lang.String feedId)

see
org.apache.lucene.gdata.storage.Storage#deleteFeed(java.lang.String)

        if (feedId == null)
            throw new StorageException("can not delete feed id is null ");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            if (!query.get().isFeedStored(feedId))
                throw new StorageException("Account does not exist");
            StorageModifier modifier = this.controller.getStorageModifier();

            modifier.deleteFeed(feedId);

        } catch (Exception e) {
            LOG.error("Can't delete feed -- " + e.getMessage(), e);
            StorageException ex = new StorageException("Can't create feed -- "
                    + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        } finally {
            if (query != null)
                query.decrementRef();
        }
    
public org.apache.lucene.gdata.data.GDataAccountgetAccount(java.lang.String accountName)

see
org.apache.lucene.gdata.storage.Storage#getAccount(java.lang.String)

        if (accountName == null)
            throw new StorageException("account name must not be null");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            return query.get().getUser(accountName);
        } catch (Exception e) {
            throw new StorageException("Can not access storage", e);
        } finally {
            if (query != null)
                query.decrementRef();
        }
    
public java.lang.StringgetAccountNameForFeedId(java.lang.String feedId)

see
org.apache.lucene.gdata.storage.Storage#getAccountNameForFeedId(java.lang.String)

        if (feedId == null)
            throw new StorageException("feed-id must not be null");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            String accountName = query.get().getAccountNameForFeedId(feedId);
            if (accountName == null)
                throw new StorageException("no feed for feedId " + feedId
                        + " found");
            return accountName;
        } catch (IOException e) {
            throw new StorageException("Can not access storage - "
                    + e.getMessage(), e);
        } finally {
            if (query != null)
                query.decrementRef();
        }

    
public com.google.gdata.data.BaseEntrygetEntry(org.apache.lucene.gdata.data.ServerBaseEntry entry)

see
org.apache.lucene.gdata.storage.Storage#getEntry(org.apache.lucene.gdata.data.ServerBaseEntry)


        if (entry == null)
            throw new StorageException("No entry  specified -- is null");
        if (LOG.isInfoEnabled())
            LOG.info("get entry " + entry.getId() + " -- feed: "
                    + entry.getFeedId());
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            BaseEntry retVal = query.get().singleEntryQuery(entry.getId(),
                    entry.getFeedId(), entry.getServiceConfig());
            if(retVal == null)
                throw new ResourceNotFoundException("can not get entry for entry ID "+entry.getId());
            return retVal;
        } catch (Exception e) {
            LOG.error("Can't get entry for feedID: " + entry.getFeedId()
                    + "; entryId: " + entry.getId() + " -- " + e.getMessage(),
                    e);
            StorageException ex = new StorageException("Can't create Entry -- "
                    + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        } finally {
            if (query != null)
                query.decrementRef();
        }

    
public java.lang.LonggetEntryLastModified(java.lang.String entryId, java.lang.String feedId)

see
org.apache.lucene.gdata.storage.Storage#getEntryLastModified(java.lang.String, java.lang.String)

        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            return new Long(query.get().getEntryLastModified(entryId,feedId));
        } catch (IOException e) {
            throw new StorageException("Can not access storage - "
                    + e.getMessage(), e);
        } finally {
            if (query != null)
                query.decrementRef();
        }

        
    
public com.google.gdata.data.BaseFeedgetFeed(org.apache.lucene.gdata.data.ServerBaseFeed feed)

see
org.apache.lucene.gdata.storage.Storage#getFeed(org.apache.lucene.gdata.data.ServerBaseFeed)


        if (feed == null)
            throw new StorageException("feed is null");
        if (LOG.isInfoEnabled())
            LOG.info("get feed: " + feed.getId() + " start-index: "
                    + feed.getStartIndex() + " resultCount: "
                    + feed.getItemsPerPage());
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            BaseFeed retVal = query.get().getLatestFeedQuery(feed.getId(),
                    feed.getItemsPerPage(), feed.getStartIndex(),
                    feed.getServiceConfig());
            return retVal;
        } catch (Exception e) {
            LOG.error("Can't get latest feed for feedID: " + feed.getId()
                    + " -- " + e.getMessage(), e);
            StorageException ex = new StorageException("Can't create Entry -- "
                    + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        } finally {
            if (query != null)
                query.decrementRef();
        }

    
public java.lang.LonggetFeedLastModified(java.lang.String feedId)

see
org.apache.lucene.gdata.storage.Storage#getFeedLastModified(java.lang.String)

        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            return new Long(query.get().getFeedLastModified(feedId));
        } catch (IOException e) {
            throw new StorageException("Can not access storage - "
                    + e.getMessage(), e);
        } finally {
            if (query != null)
                query.decrementRef();
        }

            
public java.lang.StringgetServiceForFeed(java.lang.String feedId)

see
org.apache.lucene.gdata.storage.Storage#getServiceForFeed(java.lang.String)

        if (feedId == null)
            throw new StorageException("no feed for the feedID == null");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            String type = query.get().getService(feedId);
            if (type == null)
                throw new StorageException("no feed for the feedID == "
                        + feedId + " found");
            return type;
        } catch (Exception e) {
            throw new StorageException("Can not access storage", e);
        } finally {
            if (query != null)
                query.decrementRef();
        }
    
private voidreleaseLock(java.lang.String key)

        if(!this.controller.getLock().releaseLock(key))
            throw new StorageException("Can not release lock for key: "+key);
    
private voidsetLock(java.lang.String key)

        if(!this.controller.getLock().setLock(key))
            throw new ModificationConflictException("Can not set lock for entry -- "+key);
            
    
public voidstoreAccount(org.apache.lucene.gdata.data.GDataAccount Account)

see
org.apache.lucene.gdata.storage.Storage#storeAccount(org.apache.lucene.gdata.data.GDataAccount)

        if (Account == null)
            throw new StorageException("Can not save null Account");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            if (query.get().getUser(Account.getName()) != null)
                throw new StorageException("Account already exists");
            StorageModifier modifier = this.controller.getStorageModifier();
            StorageAccountWrapper wrapper = new StorageAccountWrapper(Account);
            modifier.createAccount(wrapper);
        } catch (Exception e) {
            LOG.error("Can't save Account -- " + e.getMessage(), e);
            StorageException ex = new StorageException("Can't save Account -- "
                    + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        } finally {
            if (query != null)
                query.decrementRef();
        }
    
public com.google.gdata.data.BaseEntrystoreEntry(org.apache.lucene.gdata.data.ServerBaseEntry entry)

see
org.apache.lucene.gdata.storage.Storage#storeEntry(org.apache.lucene.gdata.data.ServerBaseEntry)

        if (entry == null)
            throw new StorageException("entry is null");
        if(entry.getFeedId() == null)
            throw new StorageException("feed-id is null");
        if(entry.getVersion() != 1)
            throw new StorageException("entry version must be 1");
        if(entry.getServiceConfig() == null)
            throw new StorageException("ProvidedService must not be null");
        StorageModifier modifier = this.controller.getStorageModifier();
        String id = this.controller.releaseId();
        entry.setId(entry.getFeedId() + id);
        if (LOG.isInfoEnabled())
            LOG.info("Store entry " + id + " -- feed: " + entry.getFeedId());

        try {
            StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,
                    StorageOperation.INSERT);
            modifier.insertEntry(wrapper);
        } catch (IOException e) {
            StorageException ex = new StorageException("Can't create Entry -- "
                    + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        }

        return entry.getEntry();
    
public voidstoreFeed(org.apache.lucene.gdata.data.ServerBaseFeed feed, java.lang.String accountName)

see
org.apache.lucene.gdata.storage.Storage#storeFeed(org.apache.lucene.gdata.data.ServerBaseFeed, java.lang.String)

        if (feed == null)
            throw new StorageException("can not insert null feed");
        if (accountName == null)
            throw new StorageException("accountName must not be null");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            if (query.get().isFeedStored(feed.getId()))
                throw new StorageException("feed with feedID " + feed.getId()
                        + " is already stored");
            StorageModifier modifier = this.controller.getStorageModifier();
            StorageFeedWrapper wrapper = new StorageFeedWrapper(feed,
                    accountName);
            modifier.createFeed(wrapper);

        } catch (Exception e) {
            LOG.error("Can't create feed -- " + e.getMessage(), e);
            StorageException ex = new StorageException("Can't create feed -- "
                    + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        } finally {
            if (query != null)
                query.decrementRef();
        }

    
public voidupdateAccount(org.apache.lucene.gdata.data.GDataAccount Account)

see
org.apache.lucene.gdata.storage.Storage#updateAccount(org.apache.lucene.gdata.data.GDataAccount)

        if (Account == null)
            throw new StorageException("Can not update null Account");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            if (query.get().getUser(Account.getName()) == null)
                throw new StorageException("Account does not exist");
            StorageModifier modifier = this.controller.getStorageModifier();
            StorageAccountWrapper wrapper = new StorageAccountWrapper(Account);
            modifier.updateAccount(wrapper);
        } catch (Exception e) {
            LOG.error("Can't update Account -- " + e.getMessage(), e);
            StorageException ex = new StorageException(
                    "Can't update Account -- " + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        } finally {
            if (query != null)
                query.decrementRef();
        }

    
public com.google.gdata.data.BaseEntryupdateEntry(org.apache.lucene.gdata.data.ServerBaseEntry entry)

see
org.apache.lucene.gdata.storage.Storage#updateEntry(org.apache.lucene.gdata.data.ServerBaseEntry)


        if (entry == null)
            throw new StorageException("entry is null");
        if(entry.getId() == null)
            throw new StorageException("entry id is null");
        if(entry.getServiceConfig() == null)
            throw new StorageException("service config is not set -- null");
        if(entry.getFeedId() == null)
            throw new StorageException("feed id is null");
        if (LOG.isInfoEnabled())
            LOG.info("update entry " + entry.getId() + " -- feed: "
                    + entry.getFeedId());
        StorageModifier modifier = this.controller.getStorageModifier();
        ReferenceCounter<StorageQuery> query = this.controller.getStorageQuery();
        // try to set concurrency Lock
        String key = entry.getId();
        setLock(key);
        try {
            
            
            if(query.get().isEntryStored(entry.getId(),entry.getFeedId())){
                
                if(query.get().checkEntryVersion(entry.getId(),entry.getFeedId(),entry.getVersion())){
                    entry.setVersion(entry.getVersion()+1);
                    StorageEntryWrapper wrapper = new StorageEntryWrapper(entry,
                            StorageOperation.UPDATE);  
                    modifier.updateEntry(wrapper);
                }else
                    throw new ModificationConflictException("The entry version does not match -- entry "+entry.getId()+" feed:"+entry.getFeedId()+" version: "+entry.getVersion());
              
            }else
                throw new ResourceNotFoundException("Entry for entry id: "+entry.getId()+" is not stored");
            
        } catch (IOException e) {
            LOG.error("Can't update entry for feedID: " + entry.getFeedId()
                    + "; entryId: " + entry.getId() + " -- " + e.getMessage(),
                    e);
            StorageException ex = new StorageException("Can't update Entry -- "
                    + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        }

        finally{
            if(query != null)
                query.decrementRef();
            // release lock for concurrency
            releaseLock(key);
        }

        return entry.getEntry();

    
public voidupdateFeed(org.apache.lucene.gdata.data.ServerBaseFeed feed, java.lang.String accountName)

see
org.apache.lucene.gdata.storage.Storage#updateFeed(org.apache.lucene.gdata.data.ServerBaseFeed, java.lang.String)

        if (feed == null)
            throw new StorageException("can not update null feed");
        if (accountName == null)
            throw new StorageException("accountName must not be null");
        ReferenceCounter<StorageQuery> query = null;
        try {
            query = this.controller.getStorageQuery();
            if (!query.get().isFeedStored(feed.getId()))
                throw new StorageException("Account does not exist");
            StorageModifier modifier = this.controller.getStorageModifier();
            StorageFeedWrapper wrapper = new StorageFeedWrapper(feed,
                    accountName);
            modifier.updateFeed(wrapper);

        } catch (Exception e) {
            LOG.error("Can't create feed -- " + e.getMessage(), e);
            StorageException ex = new StorageException("Can't create feed -- "
                    + e.getMessage(), e);
            ex.setStackTrace(e.getStackTrace());
            throw ex;

        } finally {
            if (query != null)
                query.decrementRef();
        }