/** * Synchronize internal information with the mapping data for the given * field. */ public void syncWith(FieldMapping field) { clear(false); if (field.getJoinForeignKey() != null) _tableName = field.getMappingRepository().getDBDictionary(). getFullIdentifier(field.getTable(), true); ClassMapping def = field.getDefiningMapping(); setColumnIO(field.getJoinColumnIO()); if (field.getJoinForeignKey() != null && def.getTable() != null) syncForeignKey(field, field.getJoinForeignKey(), field.getTable(), def.getTable()); _outer = field.isJoinOuter(); syncIndex(field, field.getJoinIndex()); syncUnique(field, field.getJoinUnique()); syncJoinTableUniques(field, field.getJoinTableUniques()); syncOrderColumn(field); syncStrategy(field); }
public void setBi1MJoinTableInfo() { if (getAssociationType() == FieldMetaData.ONE_TO_MANY) { FieldMapping mapped = getBi_MTo1_JTField(); if (mapped != null) { FieldMappingInfo info = getMappingInfo(); FieldMappingInfo mappedInfo = mapped.getMappingInfo(); info.setTableIdentifier(mappedInfo.getTableIdentifier()); info.setColumns(mapped.getElementMapping().getValueInfo().getColumns()); getElementMapping().getValueInfo().setColumns( mappedInfo.getColumns()); } } }
@Override protected void parseStrategy(FieldMetaData fmd, Attributes attrs) { String strategy = attrs.getValue("strategy"); if (!StringUtils.isEmpty(strategy)) { ((FieldMapping) fmd).getMappingInfo().setStrategy(strategy); } }
/** * Return the join from the field table to the owning class table. */ public ForeignKey getJoin(final FieldMapping field, Table table, boolean adapt) { // if we have no join columns defined, check class-level join // if the given field is embedded then consider primary table of owner return getJoin(field, table, adapt, getColumns()); }
/** * Map this field to its table, optionally requiring that it be * in another table. Utility method for use by mapping strategies. */ public void mapJoin(boolean adapt, boolean joinRequired) { Table table = _info.getTable(this, joinRequired, adapt); if(table != null && table.equals(getDefiningMapping().getTable())) { // Don't create a join if the field's table is the same as the // class's table. table = null; } ForeignKey join = null; if (table != null) join = _info.getJoin(this, table, adapt); if (join == null && joinRequired) throw new MetaDataException(_loc.get("join-required", this)); if (join == null) { _info.assertNoJoin(this, true); _info.assertNoForeignKey(this, !adapt); _info.assertNoUnique(this, !adapt); _info.assertNoIndex(this, !adapt); } else { _fk = join; _io = _info.getColumnIO(); _outer = _info.isJoinOuter(); _unq = _info.getJoinUnique(this, false, adapt); _idx = _info.getJoinIndex(this, adapt); } }
case MANY_ONE: serializeColumns(field.getValueInfo(), ColType.JOIN, field.getMappingInfo().getTableName(), null, fmd); return; case ONE_MANY: if (field.getMappingInfo().getJoinDirection() == MappingInfo.JOIN_NONE) { serializeColumns(field.getElementMapping().getValueInfo(), if (field.getMappingInfo().hasSchemaComponents() || field.getElementMapping().getValueInfo() .hasSchemaComponents()) { AnnotationBuilder abJoinTbl = addAnnotation(JoinTable.class, fmd); String table = field.getMappingInfo().getTableName(); if (table != null) { int index = table.indexOf('.'); field.getMappingInfo().getTableName(), null, fmd); if (strategy == PersistenceStrategy.BASIC && isLob(field)) { addAnnotation(Lob.class, fmd);
throw new MetaDataException(_loc.get("not-inv-relation-coll", field, mapped)); field.getMappingInfo().assertNoSchemaComponents(field, !adapt); vinfo.assertNoSchemaComponents(elem, !adapt); mapped.resolve(mapped.MODE_META | mapped.MODE_MAPPING); Column orderCol = finfo.getOrderColumn(field, field.getTable(), adapt); field.setOrderColumn(orderCol); field.setOrderColumnIO(finfo.getColumnIO()); field.mapPrimaryKey(adapt);
/** * Update {@link MappingInfo} with our current mapping information. */ public void syncMappingInfo() { if (isVersion()) { // we rely on the fact that the version will setup our mapping // info correctly when it is synced } else if (getMappedByMapping() != null) { _info.clear(); _val.getValueInfo().clear(); _key.getValueInfo().clear(); _elem.getValueInfo().clear(); FieldMapping mapped = getMappedByMapping(); _info.syncStrategy(this); if (_orderCol.getColumn() != null && mapped.getOrderColumn() == null) _info.syncOrderColumn(this); _val.getValueInfo().setUseClassCriteria (_val.getUseClassCriteria()); _key.getValueInfo().setUseClassCriteria (_key.getUseClassCriteria()); _elem.getValueInfo().setUseClassCriteria (_elem.getUseClassCriteria()); } else { _info.syncWith(this); _val.syncMappingInfo(); _key.syncMappingInfo(); _elem.syncMappingInfo(); } }
/** * Return the table for the given field, or null if no table given. */ public Table getTable(final FieldMapping field, boolean create, boolean adapt) { if (_tableName == null && !create) return null; Table table = field.getDefiningMapping().getTable(); String schemaName = (table == null) ? null : table.getSchema().getName(); // if we have no join columns defined, there may be class-level join // information with a more fully-qualified name for our table String tableName = _tableName; if (tableName != null && getColumns().isEmpty()) tableName = field.getDefiningMapping().getMappingInfo(). getSecondaryTableName(tableName); return createTable(field, new TableDefaults() { public String get(Schema schema) { // delay this so that we don't do schema reflection for unique // table name unless necessary return field.getMappingRepository().getMappingDefaults(). getTableName(field, schema); } }, schemaName, tableName, adapt); }
field.getMappingInfo().assertNoSchemaComponents(field, !adapt); field.getValueInfo().assertNoSchemaComponents(field, !adapt); mapped.resolve(mapped.MODE_META | mapped.MODE_MAPPING); String tableName = field.getMappingInfo().getTableName(); Table table = field.getTypeMapping().getTable(); ValueMappingInfo vinfo = field.getValueInfo(); || tableName.equalsIgnoreCase(table.getFullName()))) { vinfo.setJoinDirection(MappingInfo.JOIN_INVERSE); vinfo.setColumns(field.getMappingInfo().getColumns()); field.getMappingInfo().setTableName(null); field.getMappingInfo().setColumns(null);
/** * Clear mapping information, including strategy. */ public void clearMapping() { _strategy = null; _fk = null; _unq = null; _idx = null; _outer = false; _orderCol.setColumn(null); _val.clearMapping(); _key.clearMapping(); _elem.clearMapping(); _info.clear(); setResolve(MODE_MAPPING, false); }
if (field.getMappingInfo().hasSchemaComponents() || field2.getMappingInfo().hasSchemaComponents()) return true;
/** * Parse join-column. */ private boolean startJoinColumn(Attributes attrs) throws SAXException { // only join cols in a join table join field table to class table; // others act as data fk cols Object currentParent = currentParent(); if (currentParent == COLLECTION_TABLE) { FieldMapping fm = (FieldMapping) peekElement(); Column col = parseColumn(attrs); List<Column> colList = fm.getMappingInfo().getColumns(); if (colList.isEmpty()) { colList = new ArrayList<Column>(); fm.getMappingInfo().setColumns(colList); } colList.add(col); fm.getMappingInfo().setColumns(colList); return true; } if (currentParent != JOIN_TABLE) return startColumn(attrs); if (_joinCols == null) _joinCols = new ArrayList<Column>(3); _joinCols.add(parseColumn(attrs)); return true; }
boolean useInverseKeyMapping = DBIdentifier.isNull(info.getTableIdentifier()) && info.getColumns().isEmpty() && !elem.getValueInfo().getColumns().isEmpty();
fm.getValueInfo().setColumns(defMap._defCols); if (!DBIdentifier.isNull(defMap._defTable)) fm.getMappingInfo().setTableIdentifier(defMap._defTable); setUnique(fm, defMap._unique); fm.getMappingInfo().setColumns(defMap._defJoinCols); if (defMap._defElemJoinCols != null) fm.getElementMapping().getValueInfo().setColumns(
/** * Return the join from the field table to the owning class table. */ public ForeignKey getJoin(final FieldMapping field, Table table, boolean adapt) { // if we have no join columns defined, check class-level join List cols = getColumns(); if (cols.isEmpty()) cols = field.getDefiningMapping().getMappingInfo(). getSecondaryTableJoinColumns(_tableName); ForeignKeyDefaults def = new ForeignKeyDefaults() { public ForeignKey get(Table local, Table foreign, boolean inverse) { return field.getMappingRepository().getMappingDefaults(). getJoinForeignKey(field, local, foreign); } public void populate(Table local, Table foreign, Column col, Object target, boolean inverse, int pos, int cols) { field.getMappingRepository().getMappingDefaults(). populateJoinColumn(field, local, foreign, col, target, pos, cols); } }; ClassMapping cls = field.getDefiningMapping(); return createForeignKey(field, "join", cols, def, table, cls, cls, false, adapt); }
/** * Use hints in mapping data to figure out whether the given relation * field should use an inverse foreign key or an association table mapping. */ private boolean useInverseKeyMapping(FieldMapping field) { FieldMapping mapped = field.getMappedByMapping(); if (mapped != null) { if (mapped.getTypeCode() == JavaTypes.PC) return true; if (mapped.getElement().getTypeCode() == JavaTypes.PC) return false; throw new MetaDataException(_loc.get("bad-mapped-by", field, mapped)); } // without a mapped-by, we have to look for clues as to the mapping. // we assume that anything with element foreign key columns but no join // columns or table uses an inverse foreign key, and anything else uses // an association table FieldMappingInfo info = field.getMappingInfo(); ValueMapping elem = field.getElementMapping(); return info.getTableName() == null && info.getColumns().isEmpty() && !elem.getValueInfo().getColumns().isEmpty(); }
/** * Set the join table information back. */ private void endJoinTable() { FieldMapping fm = (FieldMapping) currentElement(); if (_joinCols != null) fm.getMappingInfo().setColumns(_joinCols); if (_cols != null) fm.getElementMapping().getValueInfo().setColumns(_cols); clearColumnInfo(); }
/** * Create raw mapping info for the given instance. */ protected FieldMappingInfo newMappingInfo(FieldMapping fm) { return new FieldMappingInfo(); }
Table table = _info.getTable(this, joinRequired, adapt); join = _info.getJoin(this, table, adapt); if (join == null && joinRequired) throw new MetaDataException(_loc.get("join-required", this)); _info.assertNoJoin(this, true); _info.assertNoForeignKey(this, !adapt); _info.assertNoUnique(this, !adapt); _info.assertNoIndex(this, !adapt); } else { _fk = join; _io = _info.getColumnIO(); _outer = _info.isJoinOuter(); _unq = _info.getJoinUnique(this, false, adapt); _joinTableUniques = _info.getJoinTableUniques(this, false, adapt); _idx = _info.getJoinIndex(this, adapt); table.setAssociation();