public void map(boolean adapt) {
if (cls.getEmbeddingMetaData() != null)
throw new MetaDataException(_loc.get("not-full", cls));
ClassMapping sup = cls.getMappedPCSuperclassMapping();
ClassMappingInfo info = cls.getMappingInfo();
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);
// find class table
Table table = info.getTable(cls, adapt);
// find primary key column
Column[] pkCols = null;
if (cls.getIdentityType() == cls.ID_DATASTORE) {
Column id = new Column();
id.setName("id");
id.setJavaType(JavaTypes.LONG);
id.setComment("datastore id");
if (cls.getIdentityStrategy() == ValueStrategies.AUTOASSIGN)
id.setAutoAssigned(true);
id.setNotNull(true);
pkCols = info.getDataStoreIdColumns(cls, new Column[]{ id },
table, adapt);
cls.setPrimaryKeyColumns(pkCols);
cls.setColumnIO(info.getColumnIO());
}
cls.setTable(table);
// add a primary key if we don't have one already
PrimaryKey pk = table.getPrimaryKey();
if (pk == null) {
String pkname = null;
if (adapt)
pkname = cls.getMappingRepository().getMappingDefaults().
getPrimaryKeyName(cls, table);
pk = table.addPrimaryKey(pkname);
pk.setLogical(!adapt);
if (pkCols != null)
pk.setColumns(pkCols);
}
// set joinable
if (cls.getIdentityType() == ClassMapping.ID_DATASTORE)
cls.setJoinable(cls.getPrimaryKeyColumns()[0],
new IdentityJoinable(cls));
}
|