From abb61b817c4c87dde9fa8f6899f0901b9d945142 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 26 Aug 2007 02:44:46 +0000 Subject: Removed vestigial support for wrapping Storables. --- .../carbonado/repo/logging/LoggingQuery.java | 196 +++++++++++++++++++-- .../carbonado/repo/logging/LoggingRepository.java | 3 - .../repo/logging/LoggingRepositoryBuilder.java | 3 +- .../carbonado/repo/logging/LoggingStorage.java | 153 ++++++++-------- 4 files changed, 255 insertions(+), 100 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo/logging') diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java index ecf54a0..d1f21ce 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java @@ -18,79 +18,239 @@ package com.amazon.carbonado.repo.logging; +import java.io.IOException; + import com.amazon.carbonado.Cursor; import com.amazon.carbonado.FetchException; import com.amazon.carbonado.PersistException; import com.amazon.carbonado.Query; import com.amazon.carbonado.Storable; -import com.amazon.carbonado.spi.WrappedQuery; + +import com.amazon.carbonado.filter.Filter; +import com.amazon.carbonado.filter.FilterValues; /** * * * @author Brian S O'Neill */ -class LoggingQuery extends WrappedQuery { +class LoggingQuery implements Query { private final LoggingStorage mStorage; + private final Query mQuery; LoggingQuery(LoggingStorage storage, Query query) { - super(query); mStorage = storage; + mQuery = query; + } + + public Class getStorableType() { + return mQuery.getStorableType(); + } + + public Filter getFilter() { + return mQuery.getFilter(); + } + + public FilterValues getFilterValues() { + return mQuery.getFilterValues(); + } + + public int getBlankParameterCount() { + return mQuery.getBlankParameterCount(); + } + + public Query with(int value) { + return newInstance(mQuery.with(value)); + } + + public Query with(long value) { + return newInstance(mQuery.with(value)); + } + + public Query with(float value) { + return newInstance(mQuery.with(value)); + } + + public Query with(double value) { + return newInstance(mQuery.with(value)); + } + + public Query with(boolean value) { + return newInstance(mQuery.with(value)); + } + + public Query with(char value) { + return newInstance(mQuery.with(value)); + } + + public Query with(byte value) { + return newInstance(mQuery.with(value)); + } + + public Query with(short value) { + return newInstance(mQuery.with(value)); + } + + public Query with(Object value) { + return newInstance(mQuery.with(value)); + } + + public Query withValues(Object... objects) { + return newInstance(mQuery.withValues(objects)); + } + + public Query and(String filter) throws FetchException { + return newInstance(mQuery.and(filter)); + } + + public Query and(Filter filter) throws FetchException { + return newInstance(mQuery.and(filter)); + } + + public Query or(String filter) throws FetchException { + return newInstance(mQuery.or(filter)); + } + + public Query or(Filter filter) throws FetchException { + return newInstance(mQuery.or(filter)); + } + + public Query not() throws FetchException { + return newInstance(mQuery.not()); + } + + public Query orderBy(String property) throws FetchException, UnsupportedOperationException { + return newInstance(mQuery.orderBy(property)); + } + + public Query orderBy(String... strings) + throws FetchException, UnsupportedOperationException + { + return newInstance(mQuery.orderBy(strings)); } public Cursor fetch() throws FetchException { - Log log = mStorage.mRepo.getLog(); + Log log = mStorage.mLog; if (log.isEnabled()) { log.write("Query.fetch() on " + this); } - return super.fetch(); + return mQuery.fetch(); + } + + public Cursor fetchAfter(S start) throws FetchException { + Log log = mStorage.mLog; + if (log.isEnabled()) { + log.write("Query.fetchAfter(start) on " + this + ", start: " + start); + } + return mQuery.fetchAfter(start); } public S loadOne() throws FetchException { - Log log = mStorage.mRepo.getLog(); + Log log = mStorage.mLog; if (log.isEnabled()) { log.write("Query.loadOne() on " + this); } - return super.loadOne(); + return mQuery.loadOne(); } public S tryLoadOne() throws FetchException { - Log log = mStorage.mRepo.getLog(); + Log log = mStorage.mLog; if (log.isEnabled()) { log.write("Query.tryLoadOne() on " + this); } - return super.tryLoadOne(); + return mQuery.tryLoadOne(); } public void deleteOne() throws PersistException { - Log log = mStorage.mRepo.getLog(); + Log log = mStorage.mLog; if (log.isEnabled()) { log.write("Query.deleteOne() on " + this); } - super.deleteOne(); + mQuery.deleteOne(); } public boolean tryDeleteOne() throws PersistException { - Log log = mStorage.mRepo.getLog(); + Log log = mStorage.mLog; if (log.isEnabled()) { log.write("Query.tryDeleteOne() on " + this); } - return super.tryDeleteOne(); + return mQuery.tryDeleteOne(); } public void deleteAll() throws PersistException { - Log log = mStorage.mRepo.getLog(); + Log log = mStorage.mLog; if (log.isEnabled()) { log.write("Query.deleteAll() on " + this); } - super.deleteAll(); + mQuery.deleteAll(); + } + + public long count() throws FetchException { + Log log = mStorage.mLog; + if (log.isEnabled()) { + log.write("Query.count() on " + this); + } + return mQuery.count(); + } + + public boolean exists() throws FetchException { + Log log = mStorage.mLog; + if (log.isEnabled()) { + log.write("Query.exists() on " + this); + } + return mQuery.exists(); + } + + public boolean printNative() { + return mQuery.printNative(); + } + + public boolean printNative(Appendable app) throws IOException { + return mQuery.printNative(app); + } + + public boolean printNative(Appendable app, int indentLevel) throws IOException { + return mQuery.printNative(app, indentLevel); } - protected S wrap(S storable) { - return mStorage.wrap(storable); + public boolean printPlan() { + return mQuery.printPlan(); + } + + public boolean printPlan(Appendable app) throws IOException { + return mQuery.printPlan(app); + } + + public boolean printPlan(Appendable app, int indentLevel) throws IOException { + return mQuery.printPlan(app, indentLevel); + } + + public void appendTo(Appendable appendable) throws IOException { + appendable.append(mQuery.toString()); + } + + public String toString() { + return mQuery.toString(); + } + + @Override + public int hashCode() { + return mQuery.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof LoggingQuery) { + LoggingQuery other = (LoggingQuery) obj; + return mQuery.equals(other.mQuery); + } + return false; } - protected WrappedQuery newInstance(Query query) { + private LoggingQuery newInstance(Query query) { return new LoggingQuery(mStorage, query); } } diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java index 89e6e21..e196993 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java @@ -40,18 +40,15 @@ import com.amazon.carbonado.spi.StoragePool; */ class LoggingRepository implements Repository, LogAccessCapability { private final AtomicReference mRootRef; - final Iterable mTriggerFactories; private final Repository mRepo; private final Log mLog; private final StoragePool mStoragePool; LoggingRepository(AtomicReference rootRef, - Iterable triggerFactories, Repository actual, Log log) { mRootRef = rootRef; - mTriggerFactories = triggerFactories; mRepo = actual; mLog = log; diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java index 3909eb1..b8c2892 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java @@ -97,8 +97,7 @@ public class LoggingRepositoryBuilder extends AbstractRepositoryBuilder { return actual; } - Repository repo = new LoggingRepository - (rootRef, mRepoBuilder.getTriggerFactories(), actual, mLog); + Repository repo = new LoggingRepository(rootRef, actual, mLog); rootRef.set(repo); return repo; } diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java index a6a56a1..5aed8a7 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java @@ -21,130 +21,129 @@ package com.amazon.carbonado.repo.logging; import com.amazon.carbonado.FetchException; import com.amazon.carbonado.PersistException; import com.amazon.carbonado.Query; -import com.amazon.carbonado.Repository; -import com.amazon.carbonado.RepositoryException; import com.amazon.carbonado.Storable; import com.amazon.carbonado.Storage; +import com.amazon.carbonado.Trigger; -import com.amazon.carbonado.spi.WrappedStorage; +import com.amazon.carbonado.filter.Filter; /** * * * @author Brian S O'Neill */ -class LoggingStorage extends WrappedStorage { - final LoggingRepository mRepo; +class LoggingStorage implements Storage { + private final Storage mStorage; + final Log mLog; + + LoggingStorage(LoggingRepository repo, Storage storage) { + mStorage = storage; + mLog = repo.getLog(); + storage.addTrigger(new LoggingTrigger(mLog)); + } + + public Class getStorableType() { + return mStorage.getStorableType(); + } - LoggingStorage(LoggingRepository repo, Storage storage) throws RepositoryException { - super(storage, repo.mTriggerFactories); - mRepo = repo; + public S prepare() { + return mStorage.prepare(); + } + + public Query query() throws FetchException { + return new LoggingQuery(this, mStorage.query()); + } + + public Query query(String filter) throws FetchException { + return new LoggingQuery(this, mStorage.query(filter)); + } + + public Query query(Filter filter) throws FetchException { + return new LoggingQuery(this, mStorage.query(filter)); } /** * @since 1.2 */ public void truncate() throws PersistException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storage.truncate() on " + getStorableType().getClass()); + if (mLog.isEnabled()) { + mLog.write("Storage.truncate() on " + getStorableType().getClass()); } - super.truncate(); + mStorage.truncate(); } - protected S wrap(S storable) { - return super.wrap(storable); + public boolean addTrigger(Trigger trigger) { + return mStorage.addTrigger(trigger); } - protected Query wrap(Query query) { - return new LoggingQuery(this, query); + public boolean removeTrigger(Trigger trigger) { + return mStorage.removeTrigger(trigger); } - protected Support createSupport(S storable) { - return new Handler(storable); + protected Query wrap(Query query) { + return new LoggingQuery(this, query); } - private class Handler extends Support { - private final S mStorable; - - Handler(S storable) { - mStorable = storable; - } - - public Repository getRootRepository() { - return mRepo.getRootRepository(); - } + private static class LoggingTrigger extends Trigger { + private final Log mLog; - public boolean isPropertySupported(String propertyName) { - return mStorable.isPropertySupported(propertyName); + LoggingTrigger(Log log) { + mLog = log; } - public void load() throws FetchException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storable.load() on " + mStorable.toStringKeyOnly()); + @Override + public Object beforeInsert(S storable) { + if (mLog.isEnabled()) { + mLog.write("Storable.insert() on " + storable.toString()); } - mStorable.load(); + return null; } - public boolean tryLoad() throws FetchException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storable.tryLoad() on " + mStorable.toStringKeyOnly()); + @Override + public Object beforeTryInsert(S storable) { + if (mLog.isEnabled()) { + mLog.write("Storable.tryInsert() on " + storable.toString()); } - return mStorable.tryLoad(); + return null; } - public void insert() throws PersistException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storable.insert() on " + mStorable.toString()); + @Override + public Object beforeUpdate(S storable) { + if (mLog.isEnabled()) { + mLog.write("Storable.update() on " + storable.toString()); } - mStorable.insert(); + return null; } - public boolean tryInsert() throws PersistException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storable.tryInsert() on " + mStorable.toString()); + @Override + public Object beforeTryUpdate(S storable) { + if (mLog.isEnabled()) { + mLog.write("Storable.tryUpdate() on " + storable.toString()); } - return mStorable.tryInsert(); + return null; } - public void update() throws PersistException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storable.update() on " + mStorable.toString()); + @Override + public Object beforeDelete(S storable) { + if (mLog.isEnabled()) { + mLog.write("Storable.delete() on " + storable.toString()); } - mStorable.update(); + return null; } - public boolean tryUpdate() throws PersistException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storable.tryUpdate() on " + mStorable.toString()); + @Override + public Object beforeTryDelete(S storable) { + if (mLog.isEnabled()) { + mLog.write("Storable.tryDelete() on " + storable.toString()); } - return mStorable.tryUpdate(); + return null; } - public void delete() throws PersistException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storable.delete() on " + mStorable.toStringKeyOnly()); + @Override + public void afterLoad(S storable) { + if (mLog.isEnabled()) { + mLog.write("Loaded " + storable.toString()); } - mStorable.delete(); - } - - public boolean tryDelete() throws PersistException { - Log log = mRepo.getLog(); - if (log.isEnabled()) { - log.write("Storable.tryDelete() on " + mStorable.toStringKeyOnly()); - } - return mStorable.tryDelete(); - } - - public Support createSupport(S storable) { - return new Handler(storable); } } } -- cgit v1.2.3