/** * Add a unique constraint for the given table. * @param table must be primary table or secondary table name added a * priori to this receiver. * @param unique the unique constraint. null means no-op. * @deprecated */ public void addUnique(String table, Unique unique) { addUnique(DBIdentifier.newTable(table), unique); }
/** * If an inheritance strategy has not been set on this mapping, set it * to the default (flat). This method should be called before strategies * are created for the specified mapping. */ protected void setDefaultInheritanceStrategy(ClassMapping mapping) { ClassMappingInfo info = mapping.getMappingInfo(); if (info != null && info.getHierarchyStrategy() == null) info.setHierarchyStrategy(FlatClassStrategy.ALIAS); }
/** * Return any columns defined for the given class level join, or empty * list if none. * @deprecated */ public List<Column> getSecondaryTableJoinColumns(String tableName) { return getSecondaryTableJoinColumns(DBIdentifier.newTable(tableName)); }
/** * Create raw mapping info for the given instance. */ protected ClassMappingInfo newMappingInfo(ClassMapping cls) { ClassMappingInfo info = new ClassMappingInfo(); info.setClassName(cls.getDescribedType().getName()); return info; }
@Override protected void serializeClassMappingContent(ClassMetaData mapping) throws SAXException { ClassMapping cls = (ClassMapping) mapping; ClassMappingInfo info = cls.getMappingInfo(); serializeTable(info.getTableName(), "table", ClassUtil.getClassName(mapping.getDescribedType()), null, info.getUniques(info.getTableName())); for (String second : info.getSecondaryTableNames()) serializeTable(second, "secondary-table", null, info, info.getUniques(second)); serializeColumns(info, ColType.PK_JOIN, null); }
if (sup != null && info.isJoinedSubclass()) throw new MetaDataException(_loc.get("not-full", cls)); info.assertNoJoin(cls, true); info.assertNoForeignKey(cls, !adapt); info.assertNoIndex(cls, false); info.assertNoUnique(cls, false); Table table = info.getTable(cls, adapt); id.setAutoAssigned(true); id.setNotNull(true); pkCols = info.getDataStoreIdColumns(cls, new Column[]{ id }, table, adapt); cls.setPrimaryKeyColumns(pkCols); cls.setColumnIO(info.getColumnIO());
/** * Synchronize internal information with the mapping data for the given * class. */ public void syncWith(ClassMapping cls) { clear(false); ClassMapping sup = cls.getMappedPCSuperclassMapping(); if (cls.getTable() != null && (sup == null || sup.getTable() != cls.getTable())) _tableName = cls.getMappingRepository().getDBDictionary(). getFullIdentifier(cls.getTable(), true); // set io before syncing cols setColumnIO(cls.getColumnIO()); if (cls.getJoinForeignKey() != null && sup != null && sup.getTable() != null) syncForeignKey(cls, cls.getJoinForeignKey(), cls.getTable(), sup.getTable()); else if (cls.getIdentityType() == ClassMapping.ID_DATASTORE) syncColumns(cls, cls.getPrimaryKeyColumns(), false); // record inheritance strategy if class does not use default strategy // for base classes, and for all subclasses so we can be sure subsequent // mapping runs don't think subclass is unmapped String strat = (cls.getStrategy() == null) ? null : cls.getStrategy().getAlias(); if (strat != null && (cls.getPCSuperclass() != null || !FullClassStrategy.ALIAS.equals(strat))) setStrategy(strat); }
info.assertNoIndex(cls, false); info.assertNoUnique(cls, false); Table table = info.getTable(cls, adapt); ForeignKey fk = info.getSuperclassJoin(cls, table, adapt); Column[] pkCols = fk.getColumns(); cls.setJoinForeignKey(fk); cls.setPrimaryKeyColumns(pkCols); cls.setColumnIO(info.getColumnIO());
public void addSecondaryTable(DBIdentifier second) { setSecondaryTableJoinColumns(second, null); }
ClassMappingInfo info = ((ClassMapping) ctx).getMappingInfo(); tableName = (_secondaryTable == null) ? info.getTableIdentifier() : DBIdentifier.newTable(_secondaryTable, delimit()); info.addUnique(tableName, unique); } else if (ctx instanceof FieldMapping) {// JoinTable FieldMappingInfo info = ((FieldMapping)ctx).getMappingInfo();
public boolean isVerticalStrategy() { String strat = getMappingInfo().getHierarchyStrategy(); if (strat != null && strat.equals(VerticalClassStrategy.ALIAS)) return true; return false; } }
@Override protected void startClassMapping(ClassMetaData meta, boolean mappedSuper, Attributes attrs) throws SAXException { if (mappedSuper) ((ClassMapping) meta).getMappingInfo().setStrategy (NoneClassStrategy.ALIAS); }
/** * Parse inheritance. */ private boolean startInheritance(Attributes attrs) { String val = attrs.getValue("strategy"); if (val == null) return true; ClassMapping cm = (ClassMapping) currentElement(); ClassMappingInfo info = cm.getMappingInfo(); switch (Enum.valueOf(InheritanceType.class, val)) { case SINGLE_TABLE: info.setHierarchyStrategy(FlatClassStrategy.ALIAS); break; case JOINED: info.setHierarchyStrategy(VerticalClassStrategy.ALIAS); break; case TABLE_PER_CLASS: info.setHierarchyStrategy(FullClassStrategy.ALIAS); break; } return true; }
/** * Get the unique constraints of the given primary or secondary table. * @deprecated */ public Unique[] getUniques(String table) { return getUniques(DBIdentifier.newTable(table)); }
/** * Set class table. */ private void parseTable(ClassMapping cm, Table table) { String tableName = toTableName(table.schema(), table.name()); if (tableName != null) cm.getMappingInfo().setTableName(tableName); for (UniqueConstraint uniqueConstraint:table.uniqueConstraints()) { Unique unique = newUnique(cm, null, uniqueConstraint.columnNames()); cm.getMappingInfo().addUnique(unique); } }
if (sup != null && info.isJoinedSubclass()) throw new MetaDataException(_loc.get("not-full", cls)); info.assertNoJoin(cls, true); info.assertNoForeignKey(cls, !adapt); info.assertNoIndex(cls, false); info.assertNoUnique(cls, false); Table table = info.getTable(cls, adapt); id.setAutoAssigned(true); id.setNotNull(true); pkCols = info.getDataStoreIdColumns(cls, new Column[]{ id }, table, adapt); cls.setPrimaryKeyColumns(pkCols); cls.setColumnIO(info.getColumnIO());
/** * Synchronize internal information with the mapping data for the given * class. */ public void syncWith(ClassMapping cls) { clear(false); ClassMapping sup = cls.getMappedPCSuperclassMapping(); if (cls.getTable() != null && (sup == null || sup.getTable() != cls.getTable())) _tableName = cls.getMappingRepository().getDBDictionary(). getFullIdentifier(cls.getTable(), true); // set io before syncing cols setColumnIO(cls.getColumnIO()); if (cls.getJoinForeignKey() != null && sup != null && sup.getTable() != null) syncForeignKey(cls, cls.getJoinForeignKey(), cls.getTable(), sup.getTable()); else if (cls.getIdentityType() == ClassMapping.ID_DATASTORE) syncColumns(cls, cls.getPrimaryKeyColumns(), false); // record inheritance strategy if class does not use default strategy // for base classes, and for all subclasses so we can be sure subsequent // mapping runs don't think subclass is unmapped String strat = (cls.getStrategy() == null) ? null : cls.getStrategy().getAlias(); if (strat != null && (cls.getPCSuperclass() != null || !FullClassStrategy.ALIAS.equals(strat))) setStrategy(strat); }
info.assertNoIndex(cls, false); info.assertNoUnique(cls, false); Table table = info.getTable(cls, adapt); ForeignKey fk = info.getSuperclassJoin(cls, table, adapt); Column[] pkCols = fk.getColumns(); cls.setJoinForeignKey(fk); cls.setPrimaryKeyColumns(pkCols); cls.setColumnIO(info.getColumnIO());
@Override protected void serializeClassMappingContent(ClassMetaData mapping) throws SAXException { ClassMapping cls = (ClassMapping) mapping; ClassMappingInfo info = cls.getMappingInfo(); serializeTable(info.getTableName(), "table", ClassUtil.getClassName(mapping.getDescribedType()), null, info.getUniques(info.getTableName())); for (String second : info.getSecondaryTableNames()) serializeTable(second, "secondary-table", null, info, info.getUniques(second)); serializeColumns(info, ColType.PK_JOIN, null); }
/** * Create raw mapping info for the given instance. */ protected ClassMappingInfo newMappingInfo(ClassMapping cls) { ClassMappingInfo info = new ClassMappingInfo(); info.setClassName(cls.getDescribedType().getName()); return info; }