001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.conf;
020:
021: import org.apache.openjpa.kernel.DetachState;
022:
023: /**
024: * Detach options.
025: *
026: * @author Abe White
027: * @nojavadoc
028: */
029: public abstract class DetachOptions implements DetachState {
030:
031: private boolean _field = true;
032: private boolean _transient = true;
033: private boolean _manager = true;
034: private boolean _access = true;
035:
036: /**
037: * The {@link DetachState} constant.
038: */
039: public abstract int getDetachState();
040:
041: /**
042: * Whether to add a detached state field to enhanced classes.
043: */
044: public boolean getDetachedStateField() {
045: return _field;
046: }
047:
048: /**
049: * Whether to add a detached state field to enhanced classes.
050: */
051: public void setDetachedStateField(boolean val) {
052: _field = val;
053: if (!val)
054: _manager = false;
055: }
056:
057: /**
058: * For auto-configuration of the detached state field. Accepts values
059: * "true", "false", or "transient".
060: */
061: public void setDetachedStateField(String val) {
062: if (val == null)
063: return;
064: if ("transient".equals(val)) {
065: setDetachedStateField(true);
066: _transient = true;
067: } else if ("true".equals(val)) {
068: setDetachedStateField(true);
069: _transient = false;
070: } else if ("false".equals(val)) {
071: setDetachedStateField(false);
072: _transient = false;
073: } else
074: throw new IllegalArgumentException("DetachedStateField="
075: + val);
076: }
077:
078: /**
079: * Whether to use transient detached state.
080: */
081: public boolean isDetachedStateTransient() {
082: return _transient;
083: }
084:
085: /**
086: * Whether to use transient detached state.
087: */
088: public void setDetachedStateTransient(boolean val) {
089: _transient = val;
090: }
091:
092: /**
093: * Whether to use a detached state manager on types that allow it.
094: * Types that do not use detached state or that declare a custom detached
095: * state field to maintain serialization compatibility will never use
096: * a detached state manager. Defaults to true.
097: */
098: public boolean getDetachedStateManager() {
099: return _manager;
100: }
101:
102: /**
103: * Whether to use a detached state manager on types that allow it.
104: * Types that do not use detached state or that declare a custom detached
105: * state field to maintain serialization compatibility will never use
106: * a detached state manager. Defaults to true.
107: */
108: public void setDetachedStateManager(boolean val) {
109: _manager = val;
110: }
111:
112: /**
113: * Whether to allow access to unloaded detached fields. This setting only
114: * applies to instances with detached state managers.
115: */
116: public boolean getAccessUnloaded() {
117: return _access;
118: }
119:
120: /**
121: * Whether to allow access to unloaded detached fields. This setting only
122: * applies to instances with detached state managers.
123: */
124: public void setAccessUnloaded(boolean val) {
125: _access = val;
126: }
127:
128: /**
129: * Detach loaded state.
130: */
131: public static class Loaded extends DetachOptions {
132:
133: public int getDetachState() {
134: return DETACH_LOADED;
135: }
136: }
137:
138: /**
139: * Public to allow reflection.
140: */
141: public static class FetchGroups extends DetachOptions {
142:
143: public int getDetachState() {
144: return DETACH_FGS;
145: }
146: }
147:
148: /**
149: * Public to allow reflection.
150: */
151: public static class All extends DetachOptions {
152:
153: public int getDetachState() {
154: return DETACH_ALL;
155: }
156: }
157: }
|