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
020
021public abstract class BasePersister<T extends Model> implements Persister<T> {
022    private Class<T> modelClass;
023    private ModelController<T> controller;
024    private String bucket;
025    private Stash<T> stash;
026
027    @Override
028    public void init(DataAccessRegistration registration, ModelController<T> controller, Stash<T> stash) {
029        this.bucket = registration.getBucket();
030        this.controller = controller;
031        this.stash = stash;
032        this.modelClass = (Class<T>)registration.getModelClass();
033    }
034
035    @Override
036    public Class<T> getModelClass() {
037        return this.modelClass;
038    }
039    public Persister<T> setModelClass(Class<T> modelClass) {
040        this.modelClass = modelClass;
041        return this;
042    }
043
044    @Override
045    public boolean isDbBacked() {
046        return false;
047    }
048
049
050    @Override
051    public String getBucket() {
052        return this.bucket;
053    }
054
055    @Override
056    public Persister setBucket(String bucket) {
057        this.bucket = bucket; return this;
058    }
059
060
061    @Override
062    public ModelController<T> getItemController() {
063        return this.controller;
064    }
065
066    @Override
067    public Persister<T> setItemController(ModelController<T> controller) {
068        this.controller = controller;
069        return this;
070    }
071
072    public Stash<T> getStash() {
073        return stash;
074    }
075
076    public BasePersister setStash(Stash<T> stash) {
077        this.stash = stash;
078        return this;
079    }
080
081    public void onPreRead() {
082
083    }
084
085    public void handleFetchOne(T obj) {
086        obj.setBucket(getBucket());
087        onFetchOne();
088    }
089
090    public boolean reloadIfNewer(T obj) {
091        return false;
092    }
093
094    public void onFetchOne() {
095
096    }
097
098
099}