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: /**
022: * Struct encompassing backwards-compatibility options.
023: */
024: public class Compatibility {
025:
026: /**
027: * If a JPQL statement is not compliant with the JPA specification,
028: * fail to parse it.
029: *
030: * @since 1.1.0
031: */
032: public static final int JPQL_STRICT = 0;
033:
034: /**
035: * If a JPQL statement is not compliant with the JPA specification,
036: * warn the first time that statement is parsed.
037: *
038: * @since 1.1.0
039: */
040: public static final int JPQL_WARN = 1;
041:
042: /**
043: * Allow non-compliant extensions of JPQL.
044: *
045: * @since 1.1.0
046: */
047: public static final int JPQL_EXTENDED = 2;
048:
049: private boolean _strictIdValues = false;
050: private boolean _hollowLookups = true;
051: private boolean _checkStore = false;
052: private boolean _copyIds = false;
053: private boolean _closeOnCommit = true;
054: private boolean _quotedNumbers = false;
055: private boolean _nonOptimisticVersionCheck = false;
056: private int _jpql = JPQL_STRICT;
057:
058: /**
059: * Whether to require exact identity value types when creating object
060: * ids from a class and value. Defaults to false.
061: */
062: public boolean getStrictIdentityValues() {
063: return _strictIdValues;
064: }
065:
066: /**
067: * Whether to require exact identity value types when creating object
068: * ids from a class and value. Defaults to false.
069: */
070: public void setStrictIdentityValues(boolean strictVals) {
071: _strictIdValues = strictVals;
072: }
073:
074: /**
075: * Whether to interpret quoted numbers in query strings as numbers.
076: * OpenJPA versions 0.3.1 and prior treated them as numbers; more recent
077: * versions treat them as strings.
078: */
079: public boolean getQuotedNumbersInQueries() {
080: return _quotedNumbers;
081: }
082:
083: /**
084: * Whether to interpret quoted numbers in query strings as numbers.
085: * OpenJPA versions 0.3.1 and prior treated them as numbers; more recent
086: * versions treat them as strings.
087: */
088: public void setQuotedNumbersInQueries(boolean quotedNumbers) {
089: _quotedNumbers = quotedNumbers;
090: }
091:
092: /**
093: * Whether to return hollow instances to broker lookups with a
094: * <code>validate</code> parameter of false. OpenJPA versions prior to
095: * 0.4.0 did not return hollow instances without special configuration
096: * (the <code>ObjectLookupMode</code>). Beginning with 0.4.0, hollow
097: * objects are the default.
098: */
099: public boolean getValidateFalseReturnsHollow() {
100: return _hollowLookups;
101: }
102:
103: /**
104: * Whether to return hollow instances to broker lookups with a
105: * <code>validate</code> parameter of false. OpenJPA versions prior to
106: * 0.4.0 did not return hollow instances without special configuration
107: * (the <code>ObjectLookupMode</code>). Beginning with 0.4.0, hollow
108: * objects are the default.
109: */
110: public void setValidateFalseReturnsHollow(boolean hollow) {
111: _hollowLookups = hollow;
112: }
113:
114: /**
115: * Whether to check the datastore for the existence of a nontransactional
116: * cached object in broker lookups with a <code>validate</code> parameter
117: * of true. OpenJPA versions prior to 0.4.0 checked the datastore.
118: */
119: public boolean getValidateTrueChecksStore() {
120: return _checkStore;
121: }
122:
123: /**
124: * Whether to check the datastore for the existence of a nontransactional
125: * cached object in broker lookups with a <code>validate</code> parameter
126: * of true. OpenJPA versions prior to 0.4.0 checked the datastore.
127: */
128: public void setValidateTrueChecksStore(boolean check) {
129: _checkStore = check;
130: }
131:
132: /**
133: * Whether to copy identity objects before returning them to client code.
134: * Versions of OpenJPA prior to 0.3.0 always copied identity objects. Also,
135: * you should configure OpenJPA to copy identity objects if you mutate them
136: * after use.
137: */
138: public boolean getCopyObjectIds() {
139: return _copyIds;
140: }
141:
142: /**
143: * Whether to copy identity objects before returning them to client code.
144: * Versions of OpenJPA prior to 0.3.0 always copied identity objects. Also,
145: * you should configure OpenJPA to copy identity objects if you mutate them
146: * after use.
147: */
148: public void setCopyObjectIds(boolean copy) {
149: _copyIds = copy;
150: }
151:
152: /**
153: * Whether to close the broker when the managed transaction commits.
154: * Versions of OpenJPA prior to 0.3.0 did not close the broker.
155: */
156: public boolean getCloseOnManagedCommit() {
157: return _closeOnCommit;
158: }
159:
160: /**
161: * Whether to close the broker when the managed transaction commits.
162: * Versions of OpenJPA prior to 0.3.0 did not close the broker.
163: */
164: public void setCloseOnManagedCommit(boolean close) {
165: _closeOnCommit = close;
166: }
167:
168: /**
169: * Whether or not to perform a version check on instances being updated
170: * in a datastore transaction. Version of OpenJPA prior to 0.4.1 always
171: * forced a version check.
172: */
173: public void setNonOptimisticVersionCheck(
174: boolean nonOptimisticVersionCheck) {
175: _nonOptimisticVersionCheck = nonOptimisticVersionCheck;
176: }
177:
178: /**
179: * Whether or not to perform a version check on instances being updated
180: * in a datastore transaction. Version of OpenJPA prior to 0.4.1 always
181: * forced a version check.
182: */
183: public boolean getNonOptimisticVersionCheck() {
184: return _nonOptimisticVersionCheck;
185: }
186:
187: /**
188: * Whether or not JPQL extensions are allowed. Defaults to
189: * {@link #JPQL_STRICT}.
190: *
191: * @since 1.1.0
192: * @see #JPQL_WARN
193: * @see #JPQL_STRICT
194: * @see #JPQL_EXTENDED
195: */
196: public int getJPQL() {
197: return _jpql;
198: }
199:
200: /**
201: * Whether or not JPQL extensions are allowed. Possible values: "warn",
202: * "strict", "extended".
203: *
204: * @since 1.1.0
205: * @see #JPQL_WARN
206: * @see #JPQL_STRICT
207: * @see #JPQL_EXTENDED
208: */
209: public void setJPQL(String jpql) {
210: if ("warn".equals(jpql))
211: _jpql = JPQL_WARN;
212: else if ("strict".equals(jpql))
213: _jpql = JPQL_STRICT;
214: else if ("extended".equals(jpql))
215: _jpql = JPQL_EXTENDED;
216: else
217: throw new IllegalArgumentException(jpql);
218: }
219: }
|