Data Access

Data Access

Qcadoo framework provides a generic crud layer for database entities. All its methods are contained in DataDefinition interface. To get the problem instance of the data definition object You should use DataDefinitionService#get(String,String) method.

CRUD operations example

DataDefinition dd = dataDefinitionService.get("plugin", "model");

Entity newEntity = dd.create();
newEntity.setField("name", "xxx");
Entity savedEntity = dd.save(newEntity);

if(savedEntity.isValid()) {
    Entity existingEntity = dd.get(savedEntity.getId());
    existingEntity.setField("name", "yyy");
    dd.save(existingEntity);

    dd.delete(existingEntity.getId());
}

Find by HQL example

Please see SearcQueryBuilder documentation for more information.

DataDefinition dd = dataDefinitionService.get("plugin", "model");

SearchResult result = dd.find("where name = :name").setString("name", "xxx").list();

for(Entity e : result.getEntities()) {
    // ...
}

Find by Criteria example

Please see SearchCriteriaBuilder documentation for more information.

DataDefinition dd = dataDefinitionService.get("plugin", "model");

SearchResult result = dd.find().add(SearchRestrictions.eq("name", "xxx").list();

for(Entity e : result.getEntities()) {
    // ...
}