Abstract Queries

Daobab open doors to true abstract programming. Entity, Dao and Select could be completly abstractly writen.
Since interfaces are entity features, you can base on features instead of entities.
Make one query regarded to some features and apply to all capable entities you have.

To play with abstracts efficially, you need to have a propper, relational data model. Also you need to be familiar with Daobab functionalities.

Abstract programming rules

  • definie Dao and Entity type features
    In abstract programming, we aer not working on object but types. That's why into Daobab, we need to to define types based on relations.
    Since we are both working on Daos and Entities, and Daos are conencted to Entities, we need to define their connected features:
    public default <D extends ICachedDataBaseDao<E>& IDaoRelatedToInsertDate<E>,E extends RelatedToInsertDate> E getYoungestRecord(D dao){
    }
    In the example above, we accept whanever CachedDataBaseDao, related to Entity having InsertDate.
    So that we execute for example followed query:
    public default <D extends ICachedDataBaseDao<E>& IDaoRelatedToInsertDate<E>,E extends RelatedToInsertDate> Date getYoungestRecord(D dao){
    	return Select.field(dao.colInsertDate()).orderDescBy(dao.colInsertDate()).result();
    }
    This query return the younest record of any CachedDataBaseDao having insertDate
  • combine features
    If you want to create abstract query regarding few features, combine them:
    public default <D extends ICachedDataBaseDao<E>& IDaoRelatedToInsertDate<E>&IDaoRelatedToName<E>,E extends RelatedToInsertDate&RelatedToName> String getYoungestRecord(D dao){
    	return Select.field(dao.colName()).orderDescBy(dao.colInsertDate()).result();
    								}
  • Example: method to find youngest record regarded to some pizza:

    This method accepts a dao related to Pizza and having relation to InsertDate column, and an entity related to this dao. No matter what instances those objects are. Only a features are important:

    private <D extends IDaoRelatedToInsertDate<E>&IDaoRelatedToPizza<E>,
    	E extends RelatedToInsertDate&RelatedToPizza>
    	E  getYoungestRecordNameRelatedToPizza(D dao,RelatedToPizza entityRelated) {
    		return Select.entity(dao.colInsertDate())
    			.where(dao.relPizza(),entityRelated)
    			.orderDescBy(dao.colInsertDate())
    			.result();
    	}

    Usage:

    OrderPizza youngestOrder=getYoungestRecordNameRelatedToPizza(daoOrderPizza,pizza);
    OrderPizza youngestOrder=getYoungestRecordNameRelatedToPizza(daoOrderPizza,pizzaPrice);
    OrderPizza youngestOrder=getYoungestRecordNameRelatedToPizza(daoOrderPizza,pizzaIngredient);
    								

    Example: find related to record:

    private <D extends IDao<Z>,Z extends R,R>
    	List<Z>  findRealted(D dao,ColumnDefinition<? extends R,?,R> commoncolumn,R val) { {
    	return Select.entityList(dao)
    		.where(commoncolumn.pointTo(dao),val)
    		.result();
    	}

    Usage:

    List<PizzaIngredient> pizzaIngredient=
    	findRealted(daoPizzaIngredient,daoPizza.relPizza(),op);
    List<IngredientPrice> ingredientPrice=
    	findRealted(daoIngredientPrice,daoIngredient.relIngredient(),pizzaIngredient.get(0));