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.meta;
020:
021: import java.io.File;
022: import java.util.Collection;
023: import java.util.Map;
024: import java.util.Set;
025:
026: import org.apache.openjpa.lib.meta.ClassArgParser;
027:
028: /**
029: * The {@link MetaDataRepository} uses implementations of this interface
030: * to load and store metadata. Implementations need not be threadsafe.
031: *
032: * @author Patrick Linskey
033: * @author Abe White
034: */
035: public interface MetaDataFactory extends MetaDataModes {
036:
037: public static final int STORE_DEFAULT = 0;
038: public static final int STORE_PER_CLASS = 1;
039: public static final int STORE_VERBOSE = 2;
040:
041: /**
042: * Set the repository to load metadata into.
043: * This method will be called before use.
044: */
045: public void setRepository(MetaDataRepository repos);
046:
047: /**
048: * Base directory for storing metadata. May not be called.
049: */
050: public void setStoreDirectory(File dir);
051:
052: /**
053: * Storage mode. May not be called.
054: */
055: public void setStoreMode(int store);
056:
057: /**
058: * If true, I/O's must exactly obey the mode directives given, and may
059: * not load additional information.
060: */
061: public void setStrict(boolean strict);
062:
063: /**
064: * Load metadata for the given class in the given mode(s). If loading
065: * in {@link MetaDataModes#MODE_QUERY}, the class may be null. Loaded
066: * metadata should be added directly to the repository. It should have
067: * its source mode set appropriately via
068: * {@link ClassMetaData#setSourceMode}.
069: *
070: * @param mode the mode to load metadata in: if mapping information is
071: * stored together with metadata, then you can load mapping
072: * data even if this mode only includes
073: * {@link MetaDataModes#MODE_META MODE_META}, so long as
074: * the <code>strict</code> property hasn't been set
075: */
076: public void load(Class cls, int mode, ClassLoader envLoader);
077:
078: /**
079: * Store the given metadata.
080: *
081: * @param mode hint about what aspects of the metadata have changed
082: * @param output if non-null, rather than storing metadata directly,
083: * add entries mapping each output destination such
084: * as a <code>File</code> to the planned output for that
085: * destination in string form
086: * @return false if this factory is unable to store metadata
087: */
088: public boolean store(ClassMetaData[] metas,
089: QueryMetaData[] queries, SequenceMetaData[] seqs, int mode,
090: Map output);
091:
092: /**
093: * Drop the metadata for the given classes in the given mode(s).
094: *
095: * @return false if any metadata could not be dropped
096: */
097: public boolean drop(Class[] cls, int mode, ClassLoader envLoader);
098:
099: /**
100: * Return the metadata defaults for this factory.
101: */
102: public MetaDataDefaults getDefaults();
103:
104: /**
105: * Return all persistent class names, using the metadata locations supplied
106: * in configuration, optionally scanning the classpath.
107: * Return null if no types are supplied and this factory is unable to scan
108: * the classpath. This method should not be used directly by outside
109: * code; use {@link MetaDataRepository#getPersistentTypeNames} instead.
110: *
111: * @see MetaDataRepository#getPersistentTypeNames
112: * @see MetaDataRepository#loadPersistentTypes
113: */
114: public Set getPersistentTypeNames(boolean devpath,
115: ClassLoader envLoader);
116:
117: /**
118: * Return the type defining the given query name, if any.
119: */
120: public Class getQueryScope(String queryName, ClassLoader loader);
121:
122: /**
123: * Return the type defining the given result set mapping name, if any.
124: */
125: public Class getResultSetMappingScope(String resultSetMappingName,
126: ClassLoader loader);
127:
128: /**
129: * Return a properly-configured class arg parser for our expected
130: * metadata format.
131: */
132: public ClassArgParser newClassArgParser();
133:
134: /**
135: * Clear any internal caches.
136: */
137: public void clear();
138:
139: /**
140: * Add any extension keys used by this instance to the given set.
141: */
142: public void addClassExtensionKeys(Collection exts);
143:
144: /**
145: * Add any extension keys used by this instance to the given set.
146: */
147: public void addFieldExtensionKeys(Collection exts);
148:
149: /**
150: * Load XMLClassMetadata for the given class. Loaded
151: * metadata should be added directly to the repository.
152: */
153: public void loadXMLMetaData(FieldMetaData fmd);
154: }
|