Skip to content

Commit 08685eb

Browse files
committed
Basic Inventory Handling classes
1 parent 3a92a1d commit 08685eb

7 files changed

Lines changed: 165 additions & 2 deletions

File tree

JavaSource/com/acminds/acuteauto/persistence/BaseDAO.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import javax.persistence.EntityManager;
1010
import javax.persistence.Query;
11+
import javax.persistence.TypedQuery;
1112

1213
/**
1314
* @author MANSUR
@@ -16,7 +17,7 @@
1617
public class BaseDAO {
1718
private EntityManager em = PersistenceManager.getEntityManager();
1819

19-
public BaseDTO get(Class<BaseDTO> clazz, Integer id) {
20+
public <T>T get(Class<T> clazz, Integer id) {
2021
return em.find(clazz, id);
2122
}
2223

@@ -94,12 +95,20 @@ public final void clearEntityManager()
9495
* ************************************************************************
9596
* ************************************************************************
9697
*
97-
* Named Queries
98+
* Queries
9899
*
99100
* ************************************************************************
100101
* ************************************************************************
101102
*/
102103

104+
public Query createQuery(String query) {
105+
return em.createQuery(query);
106+
}
107+
108+
public <T>TypedQuery<T> createQuery(String query, Class<T> clazz) {
109+
return em.createQuery(query, clazz);
110+
}
111+
103112
public Query createNamedQuery(String name) {
104113
return em.createNamedQuery(name);
105114
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
*
3+
*/
4+
package com.acminds.acuteauto.persistence.dao;
5+
6+
import java.util.List;
7+
8+
import javax.persistence.TypedQuery;
9+
10+
import com.acminds.acuteauto.persistence.BaseDAO;
11+
import com.acminds.acuteauto.persistence.dto.Category;
12+
import com.acminds.acuteauto.persistence.dto.Vehicle;
13+
import com.acminds.acuteauto.utils.Utils;
14+
15+
/**
16+
* @author Mansur
17+
*
18+
*/
19+
public class InventoryDAO extends BaseDAO {
20+
21+
public List<Vehicle> getCars(int makeId, int modelId, int styleId, int year, int mileage, int bodyType) {
22+
String q = "from Vehicle v where 1=1 ";
23+
if(!Utils.isEmpty(makeId)) q= q+" and v.make.id = "+makeId;
24+
if(!Utils.isEmpty(modelId)) q= q+" and v.model.id = "+modelId;
25+
if(!Utils.isEmpty(styleId)) q= q+" and v.style.id = "+styleId;
26+
if(!Utils.isEmpty(year)) q= q+" and v.year = "+year;
27+
if(!Utils.isEmpty(bodyType)) q= q+" and v.style.vehicleType= "+bodyType;
28+
if(!Utils.isEmpty(mileage)) q= q+" and v.mileage <= "+mileage;
29+
TypedQuery<Vehicle> tq = createQuery(q, Vehicle.class);
30+
return tq.getResultList();
31+
}
32+
33+
public List<Vehicle> getCarsByCategory(int categoryId, String categoryName) {
34+
Category c = null;
35+
if(categoryId>0) {
36+
c = get(Category.class, categoryId);
37+
} else if (!Utils.isEmpty(categoryName)) {
38+
String q = "from Category c where c.name="+categoryName;
39+
TypedQuery<Category> tq = createQuery(q, Category.class);
40+
c = tq.getSingleResult();
41+
}
42+
if(!Utils.isEmpty(c))
43+
return c.getVehicles();
44+
return null;
45+
}
46+
47+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
*
3+
*/
4+
package com.acminds.acuteauto.service;
5+
6+
import java.util.List;
7+
8+
import com.acminds.acuteauto.persistence.dto.Vehicle;
9+
10+
11+
/**
12+
* @author Mansur
13+
*
14+
*/
15+
public class InventoryService {
16+
17+
public List<Vehicle> getCars(String makeId, String modelId, String mileage, String bodyType, boolean smartSearch) {
18+
return null;
19+
}
20+
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
*
3+
*/
4+
package com.acminds.acuteauto.ui;
5+
6+
/**
7+
* @author Mansur
8+
*
9+
*/
10+
public class BaseController {
11+
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
*
3+
*/
4+
package com.acminds.acuteauto.ui.controller;
5+
6+
import javax.faces.bean.ManagedBean;
7+
import javax.faces.bean.RequestScoped;
8+
9+
import com.acminds.acuteauto.ui.BaseController;
10+
import com.acminds.acuteauto.ui.form.CarSearchForm;
11+
12+
/**
13+
* @author Mansur
14+
*
15+
*/
16+
@ManagedBean(name="hmpCtrl")
17+
@RequestScoped
18+
public class HomePageController extends BaseController{
19+
20+
private CarSearchForm csForm = new CarSearchForm();
21+
public CarSearchForm getCsForm() {
22+
return csForm;
23+
}
24+
public void setCsForm(CarSearchForm csForm) {
25+
this.csForm = csForm;
26+
}
27+
28+
public String searchCars() {
29+
return null;
30+
}
31+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*
3+
*/
4+
package com.acminds.acuteauto.ui.form;
5+
6+
/**
7+
* @author Mansur
8+
*
9+
*/
10+
public class CarSearchForm {
11+
12+
private String makeId;
13+
private String modelId;
14+
private String year;
15+
private String mileage;
16+
public String getMakeId() {
17+
return makeId;
18+
}
19+
public void setMakeId(String makeId) {
20+
this.makeId = makeId;
21+
}
22+
public String getModelId() {
23+
return modelId;
24+
}
25+
public void setModelId(String modelId) {
26+
this.modelId = modelId;
27+
}
28+
public String getYear() {
29+
return year;
30+
}
31+
public void setYear(String year) {
32+
this.year = year;
33+
}
34+
public String getMileage() {
35+
return mileage;
36+
}
37+
public void setMileage(String mileage) {
38+
this.mileage = mileage;
39+
}
40+
41+
}

JavaSource/sql/db-schema.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ NAME VARCHAR(60) NOT NULL,
6262
DESCRIPTION VARCHAR(100),
6363
CATEGORY_TYPE INT(3), -- FUTURE USE.
6464
PARENT_ID INT,
65+
EFFECTIVE_DATE DATE NOT NULL,
66+
EXPIRY_DATE DATE,
6567
CREATE_DATE TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
6668
CREATED_BY INT NOT NULL
6769
);

0 commit comments

Comments
 (0)