| Method from org.apache.openjpa.jdbc.meta.ClassMapping Detail: |
public FieldMapping addDeclaredFieldMapping(String name,
Class type) {
return (FieldMapping) addDeclaredField(name, type);
}
|
public Joinable assertJoinable(Column col) {
Joinable join = getJoinable(col);
if (join == null)
throw new MetaDataException(_loc.get("no-joinable",
col.getFullName()));
return join;
}
Return the joinable for the given column, or throw an exception if
none is available. |
protected void clearDefinedFieldCache() {
// just make this method available to other classes in this package
super.clearDefinedFieldCache();
}
|
public void clearMapping() {
_strategy = null;
_cols = Schemas.EMPTY_COLUMNS;
_fk = null;
_table = null;
_info.clear();
setResolve(MODE_MAPPING | MODE_MAPPING_INIT, false);
}
Clear mapping information, including strategy. |
protected void clearSubclassCache() {
super.clearSubclassCache();
_joinSubMaps = null;
_assignMaps = null;
}
|
public void copy(ClassMetaData cls) {
super.copy(cls);
if (_subclassMode == Integer.MAX_VALUE)
_subclassMode = ((ClassMapping) cls).getSubclassFetchMode();
}
|
public void customDelete(OpenJPAStateManager sm,
JDBCStore store) throws SQLException {
assertStrategy().customDelete(sm, store);
}
|
public void customInsert(OpenJPAStateManager sm,
JDBCStore store) throws SQLException {
assertStrategy().customInsert(sm, store);
}
|
public boolean customLoad(OpenJPAStateManager sm,
JDBCStore store,
PCState state,
JDBCFetchConfiguration fetch) throws ClassNotFoundException, SQLException {
return assertStrategy().customLoad(sm, store, state, fetch);
}
|
public boolean customLoad(OpenJPAStateManager sm,
JDBCStore store,
JDBCFetchConfiguration fetch,
Result result) throws SQLException {
return assertStrategy().customLoad(sm, store, fetch, result);
}
|
public ResultObjectProvider customLoad(JDBCStore store,
boolean subclasses,
JDBCFetchConfiguration fetch,
long startIdx,
long endIdx) throws SQLException {
return assertStrategy().customLoad(store, subclasses, fetch,
startIdx, endIdx);
}
|
public void customUpdate(OpenJPAStateManager sm,
JDBCStore store) throws SQLException {
assertStrategy().customUpdate(sm, store);
}
|
public void delete(OpenJPAStateManager sm,
JDBCStore store,
RowManager rm) throws SQLException {
assertStrategy().delete(sm, store, rm);
}
|
public String getAlias() {
return assertStrategy().getAlias();
}
|
public ColumnIO getColumnIO() {
return (_io == null) ? ColumnIO.UNRESTRICTED : _io;
}
I/O information on the key columns / join key. |
public FieldMapping getDeclaredFieldMapping(int index) {
return (FieldMapping) getDeclaredField(index);
}
|
public FieldMapping getDeclaredFieldMapping(String name) {
return (FieldMapping) getDeclaredField(name);
}
|
public FieldMapping[] getDeclaredFieldMappings() {
return (FieldMapping[]) getDeclaredFields();
}
|
public FieldMapping[] getDeclaredUnmanagedFieldMappings() {
return (FieldMapping[]) getDeclaredUnmanagedFields();
}
|
public FieldMapping[] getDefaultFetchGroupFieldMappings() {
return (FieldMapping[]) getDefaultFetchGroupFields();
}
|
public FieldMapping[] getDefinedFieldMappings() {
return (FieldMapping[]) getDefinedFields();
}
|
public FieldMapping[] getDefinedFieldMappingsInListingOrder() {
return (FieldMapping[]) getDefinedFieldsInListingOrder();
}
|
public Discriminator getDiscriminator() {
return _discrim;
}
|
public ValueMapping getEmbeddingMapping() {
return (ValueMapping) getEmbeddingMetaData();
}
|
public FieldMapping getFieldMapping(int index) {
return (FieldMapping) getField(index);
}
|
public FieldMapping getFieldMapping(String name) {
return (FieldMapping) getField(name);
}
|
public FieldMapping[] getFieldMappings() {
return (FieldMapping[]) getFields();
}
|
public FieldMapping[] getFieldMappingsInListingOrder() {
return (FieldMapping[]) getFieldsInListingOrder();
}
|
public ClassMapping[] getIndependentAssignableMappings() {
ClassMapping[] subs = getMappedPCSubclassMappings(); // checks for new
if (_assignMaps == null) {
// remove unmapped subs
if (subs.length == 0) {
if (isMapped())
_assignMaps = new ClassMapping[]{ this };
else
_assignMaps = subs;
} else {
int size = (int) (subs.length * 1.33 + 2);
Set independent = new LinkedHashSet(size);
if (isMapped())
independent.add(this);
independent.addAll(Arrays.asList(subs));
// remove all mappings that have a superclass mapping in the set
ClassMapping map, sup;
List clear = null;
for (Iterator itr = independent.iterator(); itr.hasNext();) {
map = (ClassMapping) itr.next();
sup = map.getJoinablePCSuperclassMapping();
if (sup != null && independent.contains(sup)) {
if (clear == null)
clear = new ArrayList(independent.size() - 1);
clear.add(map);
}
}
if (clear != null)
independent.removeAll(clear);
_assignMaps = (ClassMapping[]) independent.toArray
(new ClassMapping[independent.size()]);
}
}
return _assignMaps;
}
Returns the closest-derived list of non-inter-joinable mapped types
assignable to this type. May return this mapping. |
public ForeignKey getJoinForeignKey() {
return _fk;
}
Foreign key linking the primary key columns to the superclass table,
or null if none. |
public Joinable getJoinable(Column col) {
Joinable join;
if (getEmbeddingMetaData() != null) {
join = getEmbeddingMapping().getFieldMapping().
getDefiningMapping().getJoinable(col);
if (join != null)
return join;
}
ClassMapping sup = getJoinablePCSuperclassMapping();
if (sup != null) {
join = sup.getJoinable(col);
if (join != null)
return join;
}
return (Joinable) _joinables.get(col);
}
Return the Joinable for the given column. Any column that
another mapping joins to must be controlled by a joinable. |
public ClassMapping[] getJoinablePCSubclassMappings() {
ClassMapping[] subs = getMappedPCSubclassMappings(); // checks for new
if (_joinSubMaps == null) {
if (subs.length == 0)
_joinSubMaps = subs;
else {
List joinable = new ArrayList(subs.length);
for (int i = 0; i < subs.length; i++)
if (isSubJoinable(subs[i]))
joinable.add(subs[i]);
_joinSubMaps = (ClassMapping[]) joinable.toArray
(new ClassMapping[joinable.size()]);
}
}
return _joinSubMaps;
}
Return mapped subclasses that are reachable via joins. |
public ClassMapping getJoinablePCSuperclassMapping() {
ClassMapping sup = getMappedPCSuperclassMapping();
if (sup == null)
return null;
if (_fk != null || _table == null || _table.equals(sup.getTable()))
return sup;
return null;
}
Return the nearest mapped superclass that can join to this class. |
public ClassMapping[] getMappedPCSubclassMappings() {
return (ClassMapping[]) getMappedPCSubclassMetaDatas();
}
|
public ClassMapping getMappedPCSuperclassMapping() {
return (ClassMapping) getMappedPCSuperclassMetaData();
}
|
public ClassMappingInfo getMappingInfo() {
return _info;
}
|
public MappingRepository getMappingRepository() {
return (MappingRepository) getRepository();
}
|
public Object getObjectId(JDBCStore store,
Result res,
ForeignKey fk,
boolean subs,
Joins joins) throws SQLException {
ValueMapping embed = getEmbeddingMapping();
if (embed != null)
return embed.getFieldMapping().getDefiningMapping().
getObjectId(store, res, fk, subs, joins);
return getObjectId(this, store, res, fk, subs, joins);
}
Return the oid value stored in the result. This implementation will
recurse until it finds an ancestor class who uses oid values for its
primary key. |
public ClassMapping[] getPCSubclassMappings() {
return (ClassMapping[]) getPCSubclassMetaDatas();
}
|
public ClassMapping getPCSuperclassMapping() {
return (ClassMapping) getPCSuperclassMetaData();
}
|
public Column[] getPrimaryKeyColumns() {
if (_cols.length == 0 && getIdentityType() == ID_APPLICATION
&& isMapped()) {
FieldMapping[] pks = getPrimaryKeyFieldMappings();
Collection cols = new ArrayList(pks.length);
Column[] fieldCols;
for (int i = 0; i < pks.length; i++) {
fieldCols = pks[i].getColumns();
for (int j = 0; j < fieldCols.length; j++)
cols.add(fieldCols[j]);
}
_cols = (Column[]) cols.toArray(new Column[cols.size()]);
}
return _cols;
}
The columns this mapping uses to uniquely identify an object.
These will typically be the primary key columns or the columns this
class uses to link to its superclass table. |
public FieldMapping[] getPrimaryKeyFieldMappings() {
return (FieldMapping[]) getPrimaryKeyFields();
}
|
public ClassStrategy getStrategy() {
return _strategy;
}
The strategy used to map this mapping. |
public int getSubclassFetchMode() {
if (_subclassMode == Integer.MAX_VALUE) {
if (getPCSuperclass() != null)
_subclassMode = getPCSuperclassMapping().
getSubclassFetchMode();
else
_subclassMode = FetchConfiguration.DEFAULT;
}
return _subclassMode;
}
|
public Table getTable() {
return _table;
}
The mapping's primary table. |
public Version getVersion() {
return _version;
}
|
public FieldMapping getVersionFieldMapping() {
return (FieldMapping) getVersionField();
}
|
public void initialize() {
assertStrategy().initialize();
}
|
protected void initializeMapping() {
super.initializeMapping();
FieldMapping[] fields = getDefinedFieldMappings();
for (int i = 0; i < fields.length; i++)
fields[i].resolve(MODE_MAPPING_INIT);
_discrim.resolve(MODE_MAPPING_INIT);
_version.resolve(MODE_MAPPING_INIT);
_strategy.initialize();
}
|
public void insert(OpenJPAStateManager sm,
JDBCStore store,
RowManager rm) throws SQLException {
assertStrategy().insert(sm, store, rm);
}
|
public Boolean isCustomDelete(OpenJPAStateManager sm,
JDBCStore store) {
return assertStrategy().isCustomDelete(sm, store);
}
|
public Boolean isCustomInsert(OpenJPAStateManager sm,
JDBCStore store) {
return assertStrategy().isCustomInsert(sm, store);
}
|
public Boolean isCustomUpdate(OpenJPAStateManager sm,
JDBCStore store) {
return assertStrategy().isCustomUpdate(sm, store);
}
|
public Boolean isForeignKeyObjectId(ForeignKey fk) {
// if this mapping's primary key can't construct an oid, then no way
// foreign key can
if (getIdentityType() == ID_UNKNOWN || !isPrimaryKeyObjectId(false))
return Boolean.FALSE;
// with datastore identity, it's all or nothing
Column[] cols = fk.getPrimaryKeyColumns();
if (getIdentityType() == ID_DATASTORE) {
if (cols.length != 1 || cols[0] != getPrimaryKeyColumns()[0])
return Boolean.FALSE;
return Boolean.TRUE;
}
// check the join mapping for each pk column to see if it links up to
// a primary key field
Joinable join;
for (int i = 0; i < cols.length; i++) {
join = assertJoinable(cols[i]);
if (join.getFieldIndex() != -1
&& getField(join.getFieldIndex()).getPrimaryKeyIndex() == -1)
return Boolean.FALSE;
}
// if all primary key links, see whether we join to all pks
if (isPrimaryKeyObjectId(true)
&& cols.length == getPrimaryKeyColumns().length)
return Boolean.TRUE;
return null;
}
Return whether the columns of the given foreign key to this mapping
can be used to construct an object id for this type. This is a
relatively expensive operation; its results should be cached. |
public boolean isMapped() {
if (!super.isMapped())
return false;
if (_strategy != null)
return _strategy != NoneClassStrategy.getInstance();
return !NoneClassStrategy.ALIAS.equals(_info.getStrategy());
}
Returns true if this class does not use the "none" strategy (including
if it has a null strategy, and therefore is probably in the process of
being mapped). |
public boolean isPrimaryKeyObjectId(boolean hasAll) {
return assertStrategy().isPrimaryKeyObjectId(hasAll);
}
|
public Joins joinSuperclass(Joins joins,
boolean toThis) {
return assertStrategy().joinSuperclass(joins, toThis);
}
|
public void map(boolean adapt) {
assertStrategy().map(adapt);
}
|
public void refSchemaComponents() {
if (getEmbeddingMetaData() == null) {
if (_table != null && _table.getPrimaryKey() != null)
_table.getPrimaryKey().ref();
if (_fk != null)
_fk.ref();
Column[] pks = getPrimaryKeyColumns();
for (int i = 0; i < pks.length; i++)
pks[i].ref();
} else {
FieldMapping[] fields = getFieldMappings();
for (int i = 0; i < fields.length; i++)
fields[i].refSchemaComponents();
}
}
|
protected void resolveMapping(boolean runtime) {
super.resolveMapping(runtime);
// map class strategy; it may already be mapped by the repository before
// the resolve process begins
MappingRepository repos = getMappingRepository();
if (_strategy == null)
repos.getStrategyInstaller().installStrategy(this);
Log log = getRepository().getLog();
if (log.isTraceEnabled())
log.trace(_loc.get("strategy", this, _strategy.getAlias()));
// make sure unmapped superclass fields are defined if we're mapped;
// also may have been done by repository already
defineSuperclassFields(getJoinablePCSuperclassMapping() == null);
// resolve everything that doesn't rely on any relations to avoid
// recursion, then resolve all fields
resolveNonRelationMappings();
FieldMapping[] fms = getFieldMappings();
for (int i = 0; i < fms.length; i++)
if (fms[i].getDefiningMetaData() == this)
fms[i].resolve(MODE_MAPPING);
fms = getDeclaredUnmanagedFieldMappings();
for (int i = 0; i < fms.length; i++)
fms[i].resolve(MODE_MAPPING);
// mark mapped columns
if (_cols != null) {
ColumnIO io = getColumnIO();
for (int i = 0; i < _cols.length; i++) {
if (io.isInsertable(i, false))
_cols[i].setFlag(Column.FLAG_DIRECT_INSERT, true);
if (io.isUpdatable(i, false))
_cols[i].setFlag(Column.FLAG_DIRECT_UPDATE, true);
}
}
// once columns are resolved, resolve unique constraints as they need
// the columns be resolved
_info.getUniques(this, true);
}
|
void resolveNonRelationMappings() {
// make sure primary key fields are resolved first because other
// fields might rely on them
FieldMapping[] fms = getPrimaryKeyFieldMappings();
for (int i = 0; i < fms.length; i++)
fms[i].resolve(MODE_MAPPING);
// resolve defined fields that are safe; that don't rely on other types
// also being resolved. don't use getDefinedFields b/c it relies on
// whether fields are mapped, which isn't known yet
fms = getFieldMappings();
for (int i = 0; i < fms.length; i++)
if (fms[i].getDefiningMetaData() == this
&& !fms[i].isTypePC() && !fms[i].getKey().isTypePC()
&& !fms[i].getElement().isTypePC())
fms[i].resolve(MODE_MAPPING);
_discrim.resolve(MODE_MAPPING);
_version.resolve(MODE_MAPPING);
}
Resolve non-relation field mappings so that when we do relation
mappings they can rely on them for joins. |
public void setClassMapping(ClassMapping owner) {
assertStrategy().setClassMapping(owner);
}
|
public void setColumnIO(ColumnIO io) {
_io = io;
}
I/O information on the key columns / join key. |
protected void setDescribedType(Class type) {
super.setDescribedType(type);
// this method called from superclass constructor, so _info not yet
// initialized
if (_info != null)
_info.setClassName(type.getName());
}
|
public void setJoinForeignKey(ForeignKey fk) {
_fk = fk;
}
Foreign key linking the primary key columns to the superclass table,
or null if none. |
public void setJoinable(Column col,
Joinable joinable) {
// don't let non-pk override pk
Joinable join = (Joinable) _joinables.get(col);
if (join == null || (join.getFieldIndex() != -1
&& getField(join.getFieldIndex()).getPrimaryKeyIndex() == -1))
_joinables.put(col, joinable);
}
Add the given column-to-joinable mapping. |
public void setPrimaryKeyColumns(Column[] cols) {
if (cols == null)
cols = Schemas.EMPTY_COLUMNS;
_cols = cols;
}
The columns this mapping uses to uniquely identify an object.
These will typically be the primary key columns or the columns this
class uses to link to its superclass table. |
public void setStrategy(ClassStrategy strategy,
Boolean adapt) {
// set strategy first so we can access it during mapping
ClassStrategy orig = _strategy;
_strategy = strategy;
if (strategy != null) {
try {
strategy.setClassMapping(this);
if (adapt != null)
strategy.map(adapt.booleanValue());
} catch (RuntimeException re) {
// reset strategy
_strategy = orig;
throw re;
}
}
}
The strategy used to map this mapping. The adapt
parameter determines whether to adapt when mapping the strategy;
use null if the strategy should not be mapped. |
public void setSubclassFetchMode(int mode) {
_subclassMode = mode;
}
|
public void setTable(Table table) {
_table = table;
}
The mapping's primary table. |
public boolean supportsEagerSelect(Select sel,
OpenJPAStateManager sm,
JDBCStore store,
ClassMapping base,
JDBCFetchConfiguration fetch) {
return assertStrategy().supportsEagerSelect(sel, sm, store, base,
fetch);
}
|
public void syncMappingInfo() {
if (getEmbeddingMetaData() == null)
_info.syncWith(this);
else {
_info.clear();
FieldMapping[] fields = getFieldMappings();
for (int i = 0; i < fields.length; i++)
fields[i].syncMappingInfo();
}
}
Update MappingInfo with our current mapping information. |
public Object toDataStoreValue(Object obj,
Column[] cols,
JDBCStore store) {
Object ret = (cols.length == 1) ? null : new Object[cols.length];
// in the past we've been lenient about being able to translate objects
// from other persistence contexts, so try to get sm directly from
// instance before asking our context
OpenJPAStateManager sm;
if (ImplHelper.isManageable(obj))
sm = (OpenJPAStateManager) (ImplHelper.toPersistenceCapable(obj,
getRepository().getConfiguration()))
.pcGetStateManager();
else
sm = store.getContext().getStateManager(obj);
if (sm == null)
return ret;
Object val;
for (int i = 0; i < cols.length; i++) {
val = assertJoinable(cols[i]).getJoinValue(sm, cols[i], store);
if (cols.length == 1)
ret = val;
else
((Object[]) ret)[i] = val;
}
return ret;
}
Return the given column value(s) for the given object. The given
columns will be primary key columns of this mapping, but may be in
any order. If there is only one column, return its value. If there
are multiple columns, return an object array of their values, in the
same order the columns are given. |
public void update(OpenJPAStateManager sm,
JDBCStore store,
RowManager rm) throws SQLException {
assertStrategy().update(sm, store, rm);
}
|
protected boolean validateDataStoreExtensionPrefix(String prefix) {
return "jdbc-".equals(prefix);
}
|