private Object tryParent(String parentTable){ MetaModel parentMM = inferTargetMetaModel(parentTable); if(parentMM == null){ return null; }else return metaModelLocal.hasAssociation(parentMM.getModelClass(), BelongsToAssociation.class) ? parent(parentMM.getModelClass()): null; }
private Object tryChildren(String childTable){ MetaModel childMM = inferTargetMetaModel(childTable); if(childMM == null){ return null; }else return metaModelLocal.hasAssociation(childMM.getModelClass(), OneToManyAssociation.class) ? getAll(childMM.getModelClass()): null; }
private Object tryPolymorphicChildren(String childTable){ MetaModel childMM = inferTargetMetaModel(childTable); if(childMM == null){ return null; }else return metaModelLocal.hasAssociation(childMM.getModelClass(), OneToManyPolymorphicAssociation.class) ? getAll(childMM.getModelClass()): null; }
private Object tryOther(String otherTable){ MetaModel otherMM = inferTargetMetaModel(otherTable); if(otherMM == null){ return null; }else return metaModelLocal.hasAssociation(otherMM.getModelClass(), Many2ManyAssociation.class) ? getAll(otherMM.getModelClass()): null; }
private Object tryPolymorphicParent(String parentTable){ MetaModel parentMM = inferTargetMetaModel(parentTable); if(parentMM == null){ return null; }else return metaModelLocal.hasAssociation(parentMM.getModelClass(), BelongsToPolymorphicAssociation.class) ? parent(parentMM.getModelClass()): null; }
if (metaModel.hasAssociation(child.getClass(), OneToManyAssociation.class) || metaModel.hasAssociation(child.getClass(), OneToManyPolymorphicAssociation.class)) { child.delete(); return 1; } else if (metaModel.hasAssociation(child.getClass(), Many2ManyAssociation.class)) { return new DB(metaModel.getDbName()).exec(metaModel.getDialect().deleteManyToManyAssociation( metaModel.getAssociationForTarget(child.getClass(), Many2ManyAssociation.class)),
private void processOverridesHasMany(Class<? extends Model> modelClass, HasMany hasManyAnnotation) { if(hasManyAnnotation != null){ Class<? extends Model> childClass = hasManyAnnotation.child(); String foreignKeyName = hasManyAnnotation.foreignKeyName(); if (metaModels.getMetaModel(childClass).hasAssociation(modelClass, OneToManyAssociation.class)) { LogFilter.log(LOGGER, LogLevel.WARNING, "Redundant annotations used: @BelongsTo and @HasMany on a " + "relationship between Model {} and Model {}.", modelClass.getName(), childClass.getName()); return; } Association hasMany = new OneToManyAssociation(modelClass, childClass, foreignKeyName); Association belongsTo = new BelongsToAssociation(childClass, modelClass, foreignKeyName); metaModels.getMetaModel(modelClass).addAssociation(hasMany); metaModels.getMetaModel(childClass).addAssociation(belongsTo); } }
private void processOverridesBelongsTo(Class<? extends Model> modelClass, BelongsTo belongsToAnnotation) { if(belongsToAnnotation != null){ Class<? extends Model> parentClass = belongsToAnnotation.parent(); String foreignKeyName = belongsToAnnotation.foreignKeyName(); if (metaModels.getMetaModel(parentClass).hasAssociation(modelClass, OneToManyAssociation.class)) { LogFilter.log(LOGGER, LogLevel.WARNING, "Redundant annotations used: @BelongsTo and @HasMany on a " + "relationship between Model {} and Model {}.", modelClass.getName(), parentClass.getName()); return; } Association hasMany = new OneToManyAssociation(parentClass, modelClass, foreignKeyName); Association belongsTo = new BelongsToAssociation(modelClass, parentClass, foreignKeyName); metaModels.getMetaModel(parentClass).addAssociation(hasMany); metaModels.getMetaModel(modelClass).addAssociation(belongsTo); } }
if (getId() != null) { if (metaModel.hasAssociation(child.getClass(), OneToManyAssociation.class)) { OneToManyAssociation ass = metaModel.getAssociationForTarget(child.getClass(), OneToManyAssociation.class); String fkName = ass.getFkName(); child.set(fkName, getId()); }else if(metaModel.hasAssociation(child.getClass(), Many2ManyAssociation.class)){ Many2ManyAssociation ass = metaModel.getAssociationForTarget(child.getClass(), Many2ManyAssociation.class); if (child.getId() == null) { } else if(metaModel.hasAssociation(child.getClass(), OneToManyPolymorphicAssociation.class)) { OneToManyPolymorphicAssociation ass = metaModel.getAssociationForTarget(child.getClass(), OneToManyPolymorphicAssociation.class); child.set("parent_id", getId());
private Object tryPolymorphicParent(String parentTable){ MetaModel parentMM = inferTargetMetaModel(parentTable); if(parentMM == null){ return null; }else return metaModelLocal.hasAssociation(parentMM.getModelClass(), BelongsToPolymorphicAssociation.class) ? parent(parentMM.getModelClass()): null; }
private Object tryParent(String parentTable){ MetaModel parentMM = inferTargetMetaModel(parentTable); if(parentMM == null){ return null; }else return metaModelLocal.hasAssociation(parentMM.getModelClass(), BelongsToAssociation.class) ? parent(parentMM.getModelClass()): null; }
private Object tryOther(String otherTable){ MetaModel otherMM = inferTargetMetaModel(otherTable); if(otherMM == null){ return null; }else return metaModelLocal.hasAssociation(otherMM.getModelClass(), Many2ManyAssociation.class) ? getAll(otherMM.getModelClass()): null; }
private Object tryPolymorphicChildren(String childTable){ MetaModel childMM = inferTargetMetaModel(childTable); if(childMM == null){ return null; }else return metaModelLocal.hasAssociation(childMM.getModelClass(), OneToManyPolymorphicAssociation.class) ? getAll(childMM.getModelClass()): null; }
private Object tryChildren(String childTable){ MetaModel childMM = inferTargetMetaModel(childTable); if(childMM == null){ return null; }else return metaModelLocal.hasAssociation(childMM.getModelClass(), OneToManyAssociation.class) ? getAll(childMM.getModelClass()): null; }
private Object tryPolymorphicChildren(String childTable){ MetaModel childMM = inferTargetMetaModel(childTable); if(childMM == null){ return null; }else return getMetaModelLocal().hasAssociation(childMM.getTableName(), OneToManyPolymorphicAssociation.class) ? getAll(childMM.getModelClass()): null; }
private Object tryChildren(String childTable){ MetaModel childMM = inferTargetMetaModel(childTable); if(childMM == null){ return null; }else return getMetaModelLocal().hasAssociation(childMM.getTableName(), OneToManyAssociation.class) ? getAll(childMM.getModelClass()): null; }
private Object tryPolymorphicParent(String parentTable){ MetaModel parentMM = inferTargetMetaModel(parentTable); if(parentMM == null){ return null; }else return getMetaModelLocal().hasAssociation(parentMM.getTableName(), BelongsToPolymorphicAssociation.class) ? parent(parentMM.getModelClass()): null; }
private Object tryOther(String otherTable){ MetaModel otherMM = inferTargetMetaModel(otherTable); if(otherMM == null){ return null; }else return getMetaModelLocal().hasAssociation(otherMM.getTableName(), Many2ManyAssociation.class) ? getAll(otherMM.getModelClass()): null; }
private Object tryParent(String parentTable){ MetaModel parentMM = inferTargetMetaModel(parentTable); if(parentMM == null){ return null; }else return getMetaModelLocal().hasAssociation(parentMM.getTableName(), BelongsToAssociation.class) ? parent(parentMM.getModelClass()): null; }
private void processOverridesHasMany(Class<? extends Model> modelClass, HasMany hasManyAnnotation) { if(hasManyAnnotation != null){ Class<? extends Model> childClass = hasManyAnnotation.child(); String foreignKeyName = hasManyAnnotation.foreignKeyName(); if (metaModels.getMetaModel(childClass).hasAssociation(modelClass, OneToManyAssociation.class)) { LogFilter.log(LOGGER, LogLevel.WARNING, "Redundant annotations used: @BelongsTo and @HasMany on a " + "relationship between Model {} and Model {}.", modelClass.getName(), childClass.getName()); return; } Association hasMany = new OneToManyAssociation(modelClass, childClass, foreignKeyName); Association belongsTo = new BelongsToAssociation(childClass, modelClass, foreignKeyName); metaModels.getMetaModel(modelClass).addAssociation(hasMany); metaModels.getMetaModel(childClass).addAssociation(belongsTo); } }