001/* 002 * Stallion Core: A Modern Web Framework 003 * 004 * Copyright (C) 2015 - 2016 Stallion Software LLC. 005 * 006 * This program is free software: you can redistribute it and/or modify it under the terms of the 007 * GNU General Public License as published by the Free Software Foundation, either version 2 of 008 * the License, or (at your option) any later version. This program is distributed in the hope that 009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 011 * License for more details. You should have received a copy of the GNU General Public License 012 * along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>. 013 * 014 * 015 * 016 */ 017 018package io.stallion.dataAccess; 019 020import io.stallion.dataAccess.filtering.FilterChain; 021import io.stallion.exceptions.UsageException; 022 023import java.lang.annotation.Annotation; 024import java.util.List; 025 026/** 027 * {@inheritDoc} 028 * 029 * The NoStash class contains no local copy of the objects, 030 * and instead looks up objects directly from the persister. 031 * 032 * Any filtering is passed through to the persister. 033 * 034 * @param <T> 035 */ 036public class NoStash<T extends Model> extends StashBase<T> { 037 038 039 @Override 040 public void sync(T obj) { 041 // Doesn't do anything, since no local copy 042 } 043 044 045 @Override 046 public T detach(T obj) { 047 // Always detached, so can just return object 048 return obj; 049 } 050 051 @Override 052 public void save(T obj) { 053 getPersister().persist(obj); 054 } 055 056 057 @Override 058 public void hardDelete(T obj) { 059 getPersister().hardDelete(obj); 060 } 061 062 @Override 063 public void loadAll() { 064 // Don't load all for non synced 065 } 066 067 @Override 068 public boolean loadItem(T obj) { 069 return false; 070 } 071 072 @Override 073 public void loadForId(Long id) { 074 // No syncing, no loading 075 } 076 077 @Override 078 public List<T> getItems() { 079 throw new UsageException("This StashDummy does not have all items in memory."); 080 } 081 082 @Override 083 public void reset() { 084 085 } 086 087 @Override 088 public void onPreRead() { 089 090 } 091 092 @Override 093 public T forId(Long id) { 094 return filterChain().filter("id", id).first(); 095 } 096 097 @Override 098 public T originalForId(Long id) { 099 return getPersister().fetchOne(id); 100 } 101 102 @Override 103 public T forUniqueKey(String keyName, Object value) { 104 return filterChain().filter(keyName, value).first(); 105 } 106 107 108 @Override 109 public List<T> listForKey(String keyName, Object value) { 110 return filterChain().filter(keyName, value).all(); 111 } 112 113 @Override 114 public int countForKey(String keyName, Object value) { 115 return filterChain().filter(keyName, value).count(); 116 } 117 118 @Override 119 public FilterChain<T> filterChain() { 120 return getPersister().filterChain(); 121 } 122 123 @Override 124 public FilterChain<T> filterByKey(String key, Object lookupValue) { 125 return filterChain().filter(key, lookupValue); 126 } 127 128 @Override 129 public FilterChain<T> filterChain(List<T> subset) { 130 return new FilterChain<T>(getBucket(), subset, null); 131 } 132 133 134}