use of org.jumpmind.pos.persist.Query in project openpos-framework by JumpMind.
the class DBSessionQueryTest method testWhereInStatement.
@Test
public void testWhereInStatement() {
DBSession db = sessionFactory.createDbSession();
Query<CarStats> modelCounts = new Query<CarStats>().named("carCountByModelWithIn").result(CarStats.class);
List<String> makes = new ArrayList<>();
makes.add("Hyundai");
makes.add("Honda");
List<CarStats> carStats = db.query(modelCounts, makes, 100);
assertEquals(3, carStats.size());
assertEquals("Accent", carStats.get(0).getModel());
assertEquals("Elantra", carStats.get(1).getModel());
assertEquals("Santa Fe", carStats.get(2).getModel());
}
use of org.jumpmind.pos.persist.Query in project openpos-framework by JumpMind.
the class DBSessionQueryTest method testAdHocQueryOnePartStatement.
@Test
public void testAdHocQueryOnePartStatement() {
DBSession db = sessionFactory.createDbSession();
Query<CarStats> modelCounts = new Query<CarStats>().named("carCountByModel").result(CarStats.class);
List<CarStats> carStats = db.query(modelCounts, "Hyundai", 100);
assertEquals(3, carStats.size());
assertEquals("Accent", carStats.get(0).getModel());
assertEquals("Elantra", carStats.get(1).getModel());
assertEquals("Santa Fe", carStats.get(2).getModel());
}
use of org.jumpmind.pos.persist.Query in project openpos-framework by JumpMind.
the class DBSessionQueryTest method testLiteralQueryReplacementInWhereClause.
@Test
public void testLiteralQueryReplacementInWhereClause() {
sessionFactory.createAndUpgrade();
DBSession db = sessionFactory.createDbSession();
db.executeScript(new StringReader("update car_car set color = 'grey' where model = 'Accent';" + "update car_car set color = 'blue' where model = 'Elantra';"));
Query<CarModel> carsByLiteralFieldMatch = new Query<CarModel>().named("carsByLiteralReplacementInWhereClause").result(CarModel.class);
Map<String, Object> params = new HashMap<>();
params.put("columnName", "color");
params.put("columnValue", "blue");
List<CarModel> cars = db.query(carsByLiteralFieldMatch, params, 100);
assertEquals(1, cars.size());
assertEquals("Hyundai", cars.get(0).getMake());
assertEquals("Elantra", cars.get(0).getModel());
assertEquals("blue", cars.get(0).getAdditionalField("color"));
}
use of org.jumpmind.pos.persist.Query in project openpos-framework by JumpMind.
the class DBSessionQueryTest method testLiteralQueryReplacementInSelectClause.
@Test
public void testLiteralQueryReplacementInSelectClause() {
sessionFactory.createAndUpgrade();
DBSession db = sessionFactory.createDbSession();
db.executeScript(new StringReader("update car_car set color = 'grey' where model = 'Accent';" + "update car_car set color = 'blue' where model = 'Elantra';"));
Query<CarModel> carsByLiteralReplacementInSelectClause = new Query<CarModel>().named("carsByLiteralReplacementInSelectClause").result(CarModel.class);
Map<String, Object> params = new HashMap<>();
params.put("columnName", "color");
params.put("columnValue", "blue");
List<CarModel> cars = db.query(carsByLiteralReplacementInSelectClause, params, 100);
assertEquals(1, cars.size());
assertEquals("Hyundai", cars.get(0).getMake());
assertEquals("Elantra", cars.get(0).getModel());
assertEquals("blue", cars.get(0).getAdditionalField("color"));
}
use of org.jumpmind.pos.persist.Query in project openpos-framework by JumpMind.
the class DBSessionQueryTest method testOptionalParamQuery.
@Test
public void testOptionalParamQuery() {
DBSession db = sessionFactory.createDbSession();
Query<CarModel> byMakeAndModel = new Query<CarModel>().named("byMakeAndModel").result(CarModel.class);
{
Map<String, Object> params = new HashMap<>();
params.put("make", "Hyundai");
params.put("model", "Accent");
List<CarModel> hyundais = db.query(byMakeAndModel, params, 100);
assertEquals(1, hyundais.size());
CarModel hyundaiLookupedUp = hyundais.get(0);
assertNotNull(hyundaiLookupedUp);
assertEquals("Hyundai", hyundaiLookupedUp.getMake());
assertEquals("Accent", hyundaiLookupedUp.getModel());
assertEquals("2005", hyundaiLookupedUp.getModelYear());
}
{
Map<String, Object> params = new HashMap<>();
params.put("make", "Hyundai");
List<CarModel> hyundais = db.query(byMakeAndModel, params, 100);
assertEquals(3, hyundais.size());
CarModel hyundaiLookupedUp = hyundais.get(0);
assertNotNull(hyundaiLookupedUp);
assertEquals("Hyundai", hyundaiLookupedUp.getMake());
assertEquals("Accent", hyundaiLookupedUp.getModel());
assertEquals("2005", hyundaiLookupedUp.getModelYear());
}
}
Aggregations