01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.conf;
20:
21: import org.apache.openjpa.conf.CacheMarshaller.ValidationPolicy;
22: import org.apache.openjpa.lib.conf.Configurable;
23: import org.apache.openjpa.lib.conf.Configuration;
24:
25: /**
26: * Compute validity based on whether or not the cached data is from the same
27: * version of Kodo as the current install. This also checks OpenJPA version
28: * information in case the OpenJPA jars were independently updated.
29: *
30: * @since 1.1.0
31: */
32: public class OpenJPAVersionAndConfigurationTypeValidationPolicy
33: implements ValidationPolicy, Configurable {
34:
35: private String confClassName;
36:
37: public Object getCacheableData(Object o) {
38: return new Object[] { OpenJPAVersion.VERSION_ID, confClassName,
39: o, };
40: }
41:
42: public Object getValidData(Object o) {
43: Object[] array = (Object[]) o;
44: if (array.length != 3)
45: return null;
46:
47: if (OpenJPAVersion.VERSION_ID.equals(array[0])
48: && confClassName.equals(array[1]))
49: return array[2];
50: else
51: return null;
52: }
53:
54: public void setConfiguration(Configuration conf) {
55: confClassName = conf.getClass().getName();
56: }
57:
58: public void startConfiguration() {
59: }
60:
61: public void endConfiguration() {
62: }
63: }
|