From 0edcea544249116c2b212427caac0f9d54949e92 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 10 Mar 2010 16:47:43 +0000 Subject: Add DetachedStorableFactory. --- .../carbonado/gen/DelegateStorableGenerator.java | 4 + .../carbonado/gen/DetachedStorableFactory.java | 119 +++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/main/java/com/amazon/carbonado/gen/DetachedStorableFactory.java (limited to 'src/main/java') 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 { getDelegateClass(Class type, EnumSet 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 newInstance(Class type) + throws SupportException + { + return (S) QuickConstructorGenerator + .getInstance(DelegateStorableGenerator.getDelegateClass(type, null), + NoSupport.Factory.class) + .newInstance(NoSupport.THE); + } + + private static class NoSupport implements DelegateSupport { + 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 getInsertTrigger() { + return null; + } + + public Trigger getUpdateTrigger() { + return null; + } + + public Trigger getDeleteTrigger() { + return null; + } + + public Trigger 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; + } + } +} -- cgit v1.2.3