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.jdbc.meta.strats;
020:
021: import java.sql.SQLException;
022:
023: import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
024: import org.apache.openjpa.jdbc.kernel.JDBCStore;
025: import org.apache.openjpa.jdbc.meta.ClassMapping;
026: import org.apache.openjpa.jdbc.meta.FieldMapping;
027: import org.apache.openjpa.jdbc.meta.FieldStrategy;
028: import org.apache.openjpa.jdbc.meta.ValueMapping;
029: import org.apache.openjpa.jdbc.schema.Column;
030: import org.apache.openjpa.jdbc.schema.ForeignKey;
031: import org.apache.openjpa.jdbc.sql.Joins;
032: import org.apache.openjpa.jdbc.sql.Result;
033: import org.apache.openjpa.jdbc.sql.Select;
034: import org.apache.openjpa.kernel.OpenJPAStateManager;
035:
036: /**
037: * Interface implemented by map strategies so that they can
038: * support large result set maps.
039: *
040: * @author Abe White
041: */
042: public interface LRSMapFieldStrategy extends FieldStrategy {
043:
044: /**
045: * The owning field mapping.
046: */
047: public FieldMapping getFieldMapping();
048:
049: /**
050: * Return all independent mappings to which this strategy must join in
051: * order to access map keys, or empty array if none.
052: *
053: * @see ValueMapping#getIndependentTypeMappings
054: * @see ClassMapping#EMPTY_MAPPINGS
055: */
056: public ClassMapping[] getIndependentKeyMappings(boolean traverse);
057:
058: /**
059: * Return all independent mappings to which this strategy must join in
060: * order to access map values, or empty array if none.
061: *
062: * @see ValueMapping#getIndependentTypeMappings
063: * @see ClassMapping#EMPTY_MAPPINGS
064: */
065: public ClassMapping[] getIndependentValueMappings(boolean traverse);
066:
067: /**
068: * Return the foreign key used to join to the owning field for the given
069: * mapping from either {@link #getIndependentKeyMappings} or
070: * {@link #getIndependentValueMappings} (or null).
071: */
072: public ForeignKey getJoinForeignKey(ClassMapping cls);
073:
074: /**
075: * Return the columns holding data for a map key for the given key mapping
076: * from {@link #getIndependentKeyMappings} or
077: * {@link #getIndependentValueMappings} (or null).
078: */
079: public Column[] getKeyColumns(ClassMapping cls);
080:
081: /**
082: * Return the columns holding data for a map value for the given value
083: * mapping from {@link #getIndependentKeyMappings} or
084: * {@link #getIndependentValueMappings} (or null).
085: */
086: public Column[] getValueColumns(ClassMapping cls);
087:
088: /**
089: * Implement this method to select the keys of this field.
090: * Elements of the result will be loaded with {@link #loadKey}.
091: * This method is only used if the key is not derived from the value.
092: */
093: public void selectKey(Select sel, ClassMapping key,
094: OpenJPAStateManager sm, JDBCStore store,
095: JDBCFetchConfiguration fetch, Joins joins);
096:
097: /**
098: * Load a key from the given result.
099: * This method is only used if the key is not derived from the value.
100: */
101: public Object loadKey(OpenJPAStateManager sm, JDBCStore store,
102: JDBCFetchConfiguration fetch, Result res, Joins joins)
103: throws SQLException;
104:
105: /**
106: * Some mapping derive keys from map values. Other mappings may return null.
107: */
108: public Object deriveKey(JDBCStore store, Object value);
109:
110: /**
111: * Some mapping derive values from map keys. Other mappings may return null.
112: */
113: public Object deriveValue(JDBCStore store, Object key);
114:
115: /**
116: * Implement this method to select the values of this field.
117: * Elements of the result will be loaded with {@link #loadValue}.
118: */
119: public void selectValue(Select sel, ClassMapping val,
120: OpenJPAStateManager sm, JDBCStore store,
121: JDBCFetchConfiguration fetch, Joins joins);
122:
123: /**
124: * Load a value from the given result.
125: */
126: public Object loadValue(OpenJPAStateManager sm, JDBCStore store,
127: JDBCFetchConfiguration fetch, Result res, Joins joins)
128: throws SQLException;
129:
130: /**
131: * Return results containing all keys and values for this map. If only
132: * one result is needed, set both array indexes to the same result
133: * instance. Also fill in the key and value joins in the given array.
134: * The results will be loaded with the {@link #loadKey} or
135: * {@link #deriveKey} and {@link #loadValue} methods.
136: */
137: public Result[] getResults(OpenJPAStateManager sm, JDBCStore store,
138: JDBCFetchConfiguration fetch, int eagerMode, Joins[] joins,
139: boolean lrs) throws SQLException;
140:
141: /**
142: * Join this value's table to the table for the given key mapping
143: * from {@link #getIndependentKeyMappings} (or null).
144: */
145: public Joins joinKeyRelation(Joins joins, ClassMapping key);
146:
147: /**
148: * Join this value's table to the table for the given value mapping
149: * from {@link #getIndependentValueMappings} (or null).
150: */
151: public Joins joinValueRelation(Joins joins, ClassMapping val);
152: }
|