summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo/logging
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2007-08-26 02:44:46 +0000
committerBrian S. O'Neill <bronee@gmail.com>2007-08-26 02:44:46 +0000
commitabb61b817c4c87dde9fa8f6899f0901b9d945142 (patch)
tree40bfb8490a3d5525ba8444f1ba4900aab84e1ebd /src/main/java/com/amazon/carbonado/repo/logging
parent6d231091ddf24f5c05e51b8c48e455b09dab47c8 (diff)
Removed vestigial support for wrapping Storables.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/logging')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java196
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingRepository.java3
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingRepositoryBuilder.java3
-rw-r--r--src/main/java/com/amazon/carbonado/repo/logging/LoggingStorage.java153
4 files changed, 255 insertions, 100 deletions
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<S extends Storable> extends WrappedQuery<S> {
+class LoggingQuery<S extends Storable> implements Query<S> {
private final LoggingStorage<S> mStorage;
+ private final Query<S> mQuery;
LoggingQuery(LoggingStorage<S> storage, Query<S> query) {
- super(query);
mStorage = storage;
+ mQuery = query;
+ }
+
+ public Class<S> getStorableType() {
+ return mQuery.getStorableType();
+ }
+
+ public Filter<S> getFilter() {
+ return mQuery.getFilter();
+ }
+
+ public FilterValues<S> getFilterValues() {
+ return mQuery.getFilterValues();
+ }
+
+ public int getBlankParameterCount() {
+ return mQuery.getBlankParameterCount();
+ }
+
+ public Query<S> with(int value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(long value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(float value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(double value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(boolean value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(char value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(byte value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(short value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> with(Object value) {
+ return newInstance(mQuery.with(value));
+ }
+
+ public Query<S> withValues(Object... objects) {
+ return newInstance(mQuery.withValues(objects));
+ }
+
+ public Query<S> and(String filter) throws FetchException {
+ return newInstance(mQuery.and(filter));
+ }
+
+ public Query<S> and(Filter<S> filter) throws FetchException {
+ return newInstance(mQuery.and(filter));
+ }
+
+ public Query<S> or(String filter) throws FetchException {
+ return newInstance(mQuery.or(filter));
+ }
+
+ public Query<S> or(Filter<S> filter) throws FetchException {
+ return newInstance(mQuery.or(filter));
+ }
+
+ public Query<S> not() throws FetchException {
+ return newInstance(mQuery.not());
+ }
+
+ public Query<S> orderBy(String property) throws FetchException, UnsupportedOperationException {
+ return newInstance(mQuery.orderBy(property));
+ }
+
+ public Query<S> orderBy(String... strings)
+ throws FetchException, UnsupportedOperationException
+ {
+ return newInstance(mQuery.orderBy(strings));
}
public Cursor<S> 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<S> 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<S> newInstance(Query<S> query) {
+ private LoggingQuery<S> newInstance(Query<S> query) {
return new LoggingQuery<S>(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<Repository> mRootRef;
- final Iterable<TriggerFactory> mTriggerFactories;
private final Repository mRepo;
private final Log mLog;
private final StoragePool mStoragePool;
LoggingRepository(AtomicReference<Repository> rootRef,
- Iterable<TriggerFactory> 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<S extends Storable> extends WrappedStorage<S> {
- final LoggingRepository mRepo;
+class LoggingStorage<S extends Storable> implements Storage<S> {
+ private final Storage<S> mStorage;
+ final Log mLog;
+
+ LoggingStorage(LoggingRepository repo, Storage<S> storage) {
+ mStorage = storage;
+ mLog = repo.getLog();
+ storage.addTrigger(new LoggingTrigger<S>(mLog));
+ }
+
+ public Class<S> getStorableType() {
+ return mStorage.getStorableType();
+ }
- LoggingStorage(LoggingRepository repo, Storage<S> storage) throws RepositoryException {
- super(storage, repo.mTriggerFactories);
- mRepo = repo;
+ public S prepare() {
+ return mStorage.prepare();
+ }
+
+ public Query<S> query() throws FetchException {
+ return new LoggingQuery<S>(this, mStorage.query());
+ }
+
+ public Query<S> query(String filter) throws FetchException {
+ return new LoggingQuery<S>(this, mStorage.query(filter));
+ }
+
+ public Query<S> query(Filter<S> filter) throws FetchException {
+ return new LoggingQuery<S>(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<? super S> trigger) {
+ return mStorage.addTrigger(trigger);
}
- protected Query<S> wrap(Query<S> query) {
- return new LoggingQuery<S>(this, query);
+ public boolean removeTrigger(Trigger<? super S> trigger) {
+ return mStorage.removeTrigger(trigger);
}
- protected Support createSupport(S storable) {
- return new Handler(storable);
+ protected Query<S> wrap(Query<S> query) {
+ return new LoggingQuery<S>(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<S extends Storable> extends Trigger<S> {
+ 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);
}
}
}