use of org.jumpmind.pos.persist.cars.CarModel 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.cars.CarModel 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.cars.CarModel in project openpos-framework by JumpMind.
the class DBSessionQueryTest method testBatchDeleteOnTaggedModel.
@Test
public void testBatchDeleteOnTaggedModel() {
DBSession db = sessionFactory.createDbSession();
CarModel carModel1 = new CarModel();
carModel1.setVin(VIN + "1222");
carModel1.setMake("BMW");
carModel1.setModel("328i");
carModel1.setModelYear("2013");
carModel1.setTagValue("DEALERSHIP_NUMBER", "123");
CarModel carModel2 = new CarModel();
carModel2.setVin(VIN + "1222");
carModel2.setMake("BMW");
carModel2.setModel("328i");
carModel2.setModelYear("2013");
carModel2.setTagValue("DEALERSHIP_NUMBER", "456");
List<CarModel> carModels = Arrays.asList(carModel1, carModel2);
db.batchInsert(carModels);
SearchCriteria searchCriteria = new SearchCriteria(CarModel.class).addCriteria("vin", VIN + "1222");
List<CarModel> cars = db.findByCriteria(searchCriteria);
assertEquals(2, cars.size());
db.batchDelete(Collections.singletonList(carModel2));
cars = db.findByCriteria(searchCriteria);
assertEquals(1, cars.size());
}
use of org.jumpmind.pos.persist.cars.CarModel 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());
}
}
use of org.jumpmind.pos.persist.cars.CarModel in project openpos-framework by JumpMind.
the class DBSessionQueryTest method testMissingParameter.
@Test(expected = PersistException.class)
public void testMissingParameter() {
DBSession db = sessionFactory.createDbSession();
Query<CarModel> byMakeAndModel = new Query<CarModel>().named("byMakeAndModel").result(CarModel.class);
Map<String, Object> params = new HashMap<>();
db.query(byMakeAndModel, params, 100);
}
Aggregations