protected String getTableName(Class<? extends Model> modelClass) { init(MetaModel.getDbName(modelClass)); String tableName = metaModels.getTableName(modelClass); if (tableName == null) { throw new DBException("failed to find metamodel for " + modelClass + ". Are you sure that a corresponding table exists in DB?"); } return tableName; }
private void processManyToManyOverrides(Many2Many many2manyAnnotation, Class<? extends Model> modelClass){ Class<? extends Model> otherClass = many2manyAnnotation.other(); String source = metaModels.getTableName(modelClass); String target = metaModels.getTableName(otherClass); String join = many2manyAnnotation.join(); String sourceFKName = many2manyAnnotation.sourceFKName(); String targetFKName = many2manyAnnotation.targetFKName(); String otherPk; String thisPk; try { Method m = modelClass.getMethod("getMetaModel"); MetaModel mm = (MetaModel) m.invoke(modelClass); thisPk = mm.getIdName(); m = otherClass.getMethod("getMetaModel"); mm = (MetaModel) m.invoke(otherClass); otherPk = mm.getIdName(); } catch (Exception e) { throw new InitException("failed to determine PK name in many to many relationship", e); } Association many2many1 = new Many2ManyAssociation(modelClass, otherClass, join, sourceFKName, targetFKName, otherPk); metaModels.getMetaModel(source).addAssociation(many2many1); Association many2many2 = new Many2ManyAssociation(otherClass, modelClass, join, targetFKName, sourceFKName, thisPk); metaModels.getMetaModel(target).addAssociation(many2many2); }
protected String getTableName(Class<? extends Model> modelClass) { init(MetaModel.getDbName(modelClass), modelClass); String tableName = metaModels.getTableName(modelClass); if (tableName == null) { throw new DBException("failed to find metamodel for " + modelClass + ". Are you sure that a corresponding table exists in DB?"); } return tableName; }
protected String getTableName(Class<? extends Model> modelClass) { init(MetaModel.getDbName(modelClass)); String tableName = metaModels.getTableName(modelClass); if (tableName == null) { throw new DBException("failed to find metamodel for " + modelClass + ". Are you sure that a corresponding table exists in DB?"); } return tableName; }