summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/amazon/carbonado/gen/DelegateStorableGenerator.java4
-rw-r--r--src/main/java/com/amazon/carbonado/gen/DetachedStorableFactory.java119
2 files changed, 123 insertions, 0 deletions
diff --git a/src/main/java/com/amazon/carbonado/gen/DelegateStorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/DelegateStorableGenerator.java
index 38b612c..f462c2e 100644
--- a/src/main/java/com/amazon/carbonado/gen/DelegateStorableGenerator.java
+++ b/src/main/java/com/amazon/carbonado/gen/DelegateStorableGenerator.java
@@ -62,6 +62,10 @@ public class DelegateStorableGenerator<S extends Storable> {
getDelegateClass(Class<S> type, EnumSet<MasterFeature> features)
throws SupportException
{
+ if (features == null) {
+ features = EnumSet.noneOf(MasterFeature.class);
+ }
+
Object key = KeyFactory.createKey(new Object[] {type, features});
synchronized (cCache) {
diff --git a/src/main/java/com/amazon/carbonado/gen/DetachedStorableFactory.java b/src/main/java/com/amazon/carbonado/gen/DetachedStorableFactory.java
new file mode 100644
index 0000000..96eab05
--- /dev/null
+++ b/src/main/java/com/amazon/carbonado/gen/DetachedStorableFactory.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2010 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.amazon.carbonado.gen;
+
+import com.amazon.carbonado.FetchException;
+import com.amazon.carbonado.PersistException;
+import com.amazon.carbonado.Repository;
+import com.amazon.carbonado.Storable;
+import com.amazon.carbonado.SupportException;
+import com.amazon.carbonado.Trigger;
+
+import com.amazon.carbonado.sequence.SequenceValueProducer;
+
+import org.cojen.util.QuickConstructorGenerator;
+import org.cojen.util.ThrowUnchecked;
+
+/**
+ * Creates {@link Storable} instances which are basic data containers. All load
+ * and store operations throw an exception, as do accesses to join properties.
+ *
+ * @author Brian S O'Neill
+ * @since 1.2.2
+ */
+public class DetachedStorableFactory {
+ private DetachedStorableFactory() {
+ }
+
+ public static <S extends Storable> S newInstance(Class<S> type)
+ throws SupportException
+ {
+ return (S) QuickConstructorGenerator
+ .getInstance(DelegateStorableGenerator.getDelegateClass(type, null),
+ NoSupport.Factory.class)
+ .newInstance(NoSupport.THE);
+ }
+
+ private static class NoSupport implements DelegateSupport<Storable> {
+ public static interface Factory {
+ Storable newInstance(DelegateSupport support);
+ }
+
+ private static final NoSupport THE = new NoSupport();
+
+ private static final String MESSAGE = "Storable is detached";
+
+ private NoSupport() {
+ }
+
+ public boolean doTryLoad(Storable storable) throws FetchException {
+ throw new FetchException(MESSAGE);
+ }
+
+ public boolean doTryInsert(Storable storable) throws PersistException {
+ throw new PersistException(MESSAGE);
+ }
+
+ public boolean doTryUpdate(Storable storable) throws PersistException {
+ throw new PersistException(MESSAGE);
+ }
+
+ public boolean doTryDelete(Storable storable) throws PersistException {
+ throw new PersistException(MESSAGE);
+ }
+
+ public SequenceValueProducer getSequenceValueProducer(String name)
+ throws PersistException
+ {
+ throw new PersistException(MESSAGE);
+ }
+
+ public Trigger<? super Storable> getInsertTrigger() {
+ return null;
+ }
+
+ public Trigger<? super Storable> getUpdateTrigger() {
+ return null;
+ }
+
+ public Trigger<? super Storable> getDeleteTrigger() {
+ return null;
+ }
+
+ public Trigger<? super Storable> getLoadTrigger() {
+ return null;
+ }
+
+ public void locallyDisableLoadTrigger() {
+ }
+
+ public void locallyEnableLoadTrigger() {
+ }
+
+ public Repository getRootRepository() {
+ // This method is only called when fetching join properties.
+ ThrowUnchecked.fire(new FetchException(MESSAGE));
+ return null;
+ }
+
+ public boolean isPropertySupported(String propertyName) {
+ return true;
+ }
+ }
+}