    001package com.hammurapi.store.local;
    002
    003import java.util.concurrent.locks.ReadWriteLock;
    004
    005import com.hammurapi.extract.Predicate;
    006import com.hammurapi.store.AbstractStore;
    007import com.hammurapi.store.DeputyStore;
    008import com.hammurapi.store.LiveView;
    009import com.hammurapi.store.UnmodifiableStore;
    010
    011/**
    012 * In-memory object store.
    013 * @author Pavel Vlasov
    014 *
    015 * @param <T>
    016 */
    017public class LocalStoreImpl<T, PK> extends LocalStoreBase<T, PK, LocalStore<T,PK>> implements LocalStore<T, PK> {
    018
    019
    020        public LocalStoreImpl(Config<T, PK, LocalStore<T, PK>> config) {
    021                super(config);
    022        }
    023
    024        protected static class LocalDeputyStore<T, PK> extends DeputyStore<T, PK, LocalStore<T,PK>> implements LocalStore<T,PK> {
    025
    026                public LocalDeputyStore(AbstractStore<T, PK, LocalStore<T, PK>> master,     ReadWriteLock masterLock) {
    027                        super(master, masterLock);
    028                }
    029
    030                @Override
    031                protected LocalStore<T, PK> createDeputy() {
    032                        return new LocalDeputyStore<T, PK>(this, createMasterLock());
    033                }
    034
    035                @Override
    036                public LocalStore<T, PK> createUnmodifiableFacade() {
    037                        return new LocalUnmodifiableStore<T, PK>(this);
    038                }
    039
    040                @Override
    041                protected LocalStore<T, PK> createLiveView(Predicate<T, LocalStore<T, PK>> selector) {
    042                        return new LocalLiveView<T, PK>(this, selector);
    043                }
    044
    045        }
    046
    047        protected static class LocalUnmodifiableStore<T, PK> extends UnmodifiableStore<T, PK, LocalStore<T, PK>> implements LocalStore<T, PK> {
    048
    049                public LocalUnmodifiableStore(LocalStore<T, PK> master) {
    050                        super(master);
    051                }
    052
    053        }
    054
    055        protected static class LocalLiveView<T, PK> extends LiveView<T, PK, LocalStore<T, PK>> implements LocalStore<T, PK> {
    056
    057                public LocalLiveView(LocalStore<T, PK> master, Predicate<T, LocalStore<T, PK>> selector) {
    058                        super(master, selector);
    059                }
    060
    061                @Override
    062                public LocalStore<T, PK> createUnmodifiableFacade() {
    063                        return new LocalUnmodifiableStore<T, PK>(this);
    064                }
    065
    066        }
    067
    068        @Override
    069        protected LocalStore<T, PK> createDeputy() {
    070                return new LocalDeputyStore<T,PK>(this, createMasterLock());
    071        }
    072
    073        @Override
    074        public LocalStore<T, PK> createUnmodifiableFacade() {
    075                return new LocalUnmodifiableStore<T, PK>(this);
    076        }
    077
    078        @Override
    079        protected LocalStore<T, PK> createLiveView(Predicate<T, LocalStore<T, PK>> selector) {
    080                return new LocalLiveView<T,PK>(this, selector);
    081        }
    082
    083}