Search in sources :

Example 1 with CarModel

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"));
}
Also used : CarModel(org.jumpmind.pos.persist.cars.CarModel) RaceCarModel(org.jumpmind.pos.persist.cars.RaceCarModel) Query(org.jumpmind.pos.persist.Query) StringReader(java.io.StringReader) DBSession(org.jumpmind.pos.persist.DBSession) Test(org.junit.Test)

Example 2 with CarModel

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"));
}
Also used : CarModel(org.jumpmind.pos.persist.cars.CarModel) RaceCarModel(org.jumpmind.pos.persist.cars.RaceCarModel) Query(org.jumpmind.pos.persist.Query) StringReader(java.io.StringReader) DBSession(org.jumpmind.pos.persist.DBSession) Test(org.junit.Test)

Example 3 with CarModel

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());
}
Also used : CarModel(org.jumpmind.pos.persist.cars.CarModel) RaceCarModel(org.jumpmind.pos.persist.cars.RaceCarModel) DBSession(org.jumpmind.pos.persist.DBSession) SearchCriteria(org.jumpmind.pos.persist.model.SearchCriteria) Test(org.junit.Test)

Example 4 with CarModel

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());
    }
}
Also used : CarModel(org.jumpmind.pos.persist.cars.CarModel) RaceCarModel(org.jumpmind.pos.persist.cars.RaceCarModel) Query(org.jumpmind.pos.persist.Query) DBSession(org.jumpmind.pos.persist.DBSession) Test(org.junit.Test)

Example 5 with CarModel

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);
}
Also used : CarModel(org.jumpmind.pos.persist.cars.CarModel) RaceCarModel(org.jumpmind.pos.persist.cars.RaceCarModel) Query(org.jumpmind.pos.persist.Query) DBSession(org.jumpmind.pos.persist.DBSession) Test(org.junit.Test)

Aggregations

CarModel (org.jumpmind.pos.persist.cars.CarModel)28 Test (org.junit.Test)28 RaceCarModel (org.jumpmind.pos.persist.cars.RaceCarModel)23 DBSession (org.jumpmind.pos.persist.DBSession)17 Query (org.jumpmind.pos.persist.Query)12 SearchCriteria (org.jumpmind.pos.persist.model.SearchCriteria)6 StringReader (java.io.StringReader)4 HashMap (java.util.HashMap)4 List (java.util.List)2 SqlStatement (org.jumpmind.pos.persist.SqlStatement)2 AugmentedCarModel (org.jumpmind.pos.persist.cars.AugmentedCarModel)2 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1 CarModelExtension (org.jumpmind.pos.persist.cars.CarModelExtension)1 CarTrimTypeCode (org.jumpmind.pos.persist.cars.CarTrimTypeCode)1