use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class BelongsToIntegrationTest method shouldSaveBelongsToField.
@Test
public void shouldSaveBelongsToField() throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
DataDefinition componentDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_COMPONENT);
Entity machine = machineDao.save(createMachine("asd"));
Entity product = productDao.save(createProduct("asd", "asd"));
Entity component = createComponent("name", product, machine);
// when
component = componentDao.save(component);
// then
assertNotNull(component);
assertEquals(product.getId(), ((Entity) component.getField("product")).getId());
Map<String, Object> result = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_COMPONENT);
assertNotNull(result);
assertEquals(product.getId(), result.get("product_id"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class BelongsToIntegrationTest method shouldSaveBelongsToFieldWithId.
@Test
public void shouldSaveBelongsToFieldWithId() throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
DataDefinition componentDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_COMPONENT);
Entity machine = machineDao.save(createMachine("asd"));
Entity product = productDao.save(createProduct("asd", "asd"));
Entity component = createComponent("name", product.getId(), machine.getId());
// when
component = componentDao.save(component);
// then
assertNotNull(component);
assertEquals(product.getId(), ((Entity) component.getField("product")).getId());
Map<String, Object> result = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_COMPONENT);
assertNotNull(result);
assertEquals(product.getId(), result.get("product_id"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method findByQueryWithBelongsToSubqueries.
private void findByQueryWithBelongsToSubqueries(final JoinType joinType) throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition partDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PART);
productDao.save(createProduct("qwe", "qwe"));
Entity product = productDao.save(createProduct("asd", "asd"));
Entity expectedPart = partDao.save(createPart("name", product));
// when
SearchCriteriaBuilder criteria = partDao.find();
criteria.createCriteria("product", "product", joinType).add(SearchRestrictions.eq("name", "asd"));
Entity part = criteria.uniqueResult();
// then
assertEquals(expectedPart.getId(), part.getId());
assertEquals(expectedPart.getDataDefinition(), part.getDataDefinition());
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method shouldFindAllByQuery.
@Test
public void shouldFindAllByQuery() throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
productDao.save(createProduct("asd", "asd"));
productDao.save(createProduct("asd2", "asd2"));
// when
SearchResult result = productDao.find().list();
// then
assertEquals(2, result.getTotalNumberOfEntities());
assertEquals(2, result.getEntities().size());
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class CriteriaIntegrationTest method shouldFindByQueryWithAliasedSubqueries.
@Test
public void shouldFindByQueryWithAliasedSubqueries() throws Exception {
// given
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition partDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PART);
productDao.save(createProduct("qwe", "qwe"));
Entity expectedProduct = productDao.save(createProduct("asd", "asd"));
partDao.save(createPart("name", expectedProduct));
// when
SearchCriteriaBuilder subcriteria = partDao.findWithAlias("part").add(SearchRestrictions.eqField("part.product.id", "p.id")).setProjection(SearchProjections.id());
Entity product = productDao.findWithAlias("p").add(SearchSubqueries.exists(subcriteria)).uniqueResult();
// then
assertEquals(expectedProduct.getId(), product.getId());
assertEquals(expectedProduct.getDataDefinition(), product.getDataDefinition());
}
Aggregations