public static String tableNameOf(Class<? extends Model> clazz) { return Registry.instance().getTableName(clazz); }
public static String tableNameOf(Class<? extends Model> clazz) { return Registry.instance().getTableName(clazz); }
public static String tableNameOf(Class<? extends Model> clazz) { return Registry.instance().getTableName(clazz); }
private void processOverridesBelongsTo(Class<? extends Model> modelClass, BelongsTo belongsToAnnotation) { if(belongsToAnnotation != null){ Class<? extends Model> parentClass = belongsToAnnotation.parent(); String foreignKeyName = belongsToAnnotation.foreignKeyName(); Association hasMany = new OneToManyAssociation(getTableName(parentClass), getTableName(modelClass), foreignKeyName); Association belongsTo = new BelongsToAssociation(getTableName(modelClass), getTableName(parentClass), foreignKeyName); metaModels.getMetaModel(parentClass).addAssociation(hasMany); metaModels.getMetaModel(modelClass).addAssociation(belongsTo); } }
/** * This methods supports one to many, many to many relationships as well as polymorphic associations. * <p/> * In case of one to many, the <code>clazz</code> must be a class of a child model, and it will return a * collection of all children. * <p/> * In case of many to many, the <code>clazz</code> must be a class of a another related model, and it will return a * collection of all related models. * <p/> * In case of polymorphic, the <code>clazz</code> must be a class of a polymorphically related model, and it will return a * collection of all related models. * * * @param clazz class of a child model for one to many, or class of another model, in case of many to many or class of child in case of * polymorphic * * @return list of children in case of one to many, or list of other models, in case many to many. */ public <C extends Model> LazyList<C> getAll(Class<C> clazz) { List<Model> children = cachedChildren.get(clazz); if(children != null){ return (LazyList<C>) children; } String tableName = Registry.instance().getTableName(clazz); if(tableName == null) throw new IllegalArgumentException("table: " + tableName + " does not exist for model: " + clazz); return get(tableName, null); }
includes.addAll(metaModel.getAssociationsForTarget(Registry.instance().getTableName(includeClass)));
/** * Provides a list of child models in one to many, many to many and polymorphic associations, but in addition also allows to filter this list * by criteria. * * <p/> * <strong>1.</strong> For one to many, the criteria is against the child table. * * <p/> * <strong>2.</strong> For polymorphic association, the criteria is against the child table. * * <p/> * <strong>3.</strong> For many to many, the criteria is against the join table. * For example, if you have table PROJECTS, ASSIGNMENTS and PROGRAMMERS, where a project has many programmers and a programmer * has many projects, and ASSIGNMENTS is a join table, you can write code like this, assuming that the ASSIGNMENTS table * has a column <code>duration_weeks</code>: * * <pre> * List<Project> threeWeekProjects = programmer.get(Project.class, "duration_weeks = ?", 3); * </pre> * where this list will contain all projects to which this programmer is assigned for 3 weeks. * * @param clazz related type * @param query sub-query for join table. * @param params parameters for a sub-query * @return list of relations in many to many */ public <C extends Model> LazyList<C> get(Class<C> clazz, String query, Object ... params){ return get(Registry.instance().getTableName(clazz), query, params); }
this.query = query; this.params = params; String tableName = Registry.instance().getTableName(modelClass); this.metaModel = metaModelFor(tableName);
this.query = query; this.params = params; String tableName = Registry.instance().getTableName(modelClass); this.metaModel = Registry.instance().getMetaModel(tableName);
private void processManyToManyOverrides(Many2Many many2manyAnnotation, Class<? extends Model> modelClass){ Class<? extends Model> otherClass = many2manyAnnotation.other(); String source = getTableName(modelClass); String target = 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); }
String source = getTableName(modelClass); String target = getTableName(otherClass); String join = many2manyAnnotation.join(); String sourceFKName = many2manyAnnotation.sourceFKName(); new BelongsToPolymorphicAssociation(getTableName(modelClass), getTableName(parentClass), typeLabel, parentClass.getName()); metaModels.getMetaModel(modelClass).addAssociation(belongsToPolymorphicAssociation); new OneToManyPolymorphicAssociation(getTableName(parentClass), getTableName(modelClass), typeLabel); metaModels.getMetaModel(parentClass).addAssociation(oneToManyPolymorphicAssociation);
String childTable = Registry.instance().getTableName(child.getClass()); MetaModel metaModel = getMetaModelLocal(); if (metaModel.hasAssociation(childTable, OneToManyAssociation.class)
String childTable = Registry.instance().getTableName(child.getClass()); MetaModel metaModel = getMetaModelLocal(); if (getId() != null) {