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 java.util.Map;
22:
23: import org.apache.openjpa.lib.conf.Configuration;
24: import org.apache.openjpa.lib.conf.PluginValue;
25: import org.apache.openjpa.conf.CacheMarshallersValue;
26: import org.apache.openjpa.meta.MetaDataRepository;
27:
28: /**
29: * A {@link PluginValue} that interacts with the {@link CacheMarshaller}
30: * to cache the metadata repository between executions.
31: *
32: * @since 1.1.0
33: */
34: public class MetaDataRepositoryValue extends PluginValue {
35:
36: private static final String KEY = "MetaDataRepository";
37:
38: public MetaDataRepositoryValue() {
39: super (KEY, false);
40: String[] aliases = new String[] { "default",
41: MetaDataRepository.class.getName() };
42: setAliases(aliases);
43: setDefault(aliases[0]);
44: setString(aliases[0]);
45: }
46:
47: public Object instantiate(Class type, Configuration c, boolean fatal) {
48: MetaDataRepository repos = null;
49: OpenJPAConfiguration conf = (OpenJPAConfiguration) c;
50:
51: Object[] os = (Object[]) CacheMarshallersValue
52: .getMarshallerById(conf,
53: MetaDataCacheMaintenance.class.getName())
54: .load();
55: if (os != null) {
56: repos = (MetaDataRepository) os[0];
57: if (os[1] != null)
58: // It's a bit odd that we do this in MetaDataRepositoryValue.
59: // We need to serialize all the various bits of configuration
60: // together; maybe we can move the caching logic somewhere
61: // else?
62: conf.getQueryCompilationCacheInstance().putAll(
63: (Map) os[1]);
64: }
65:
66: if (repos == null)
67: return super.instantiate(type, c, fatal);
68: else
69: return repos;
70: }
71:
72: }
|