Package com.rosivanyshyn.db.dao
Interface GenericDAO<T>
- Type Parameters:
T- – the type of entities
- All Known Subinterfaces:
AccountDAO,ApartmentDAO,BookingDAO,OrderDAO,ResponseToOrderDAO
- All Known Implementing Classes:
AccountDAOImpl,ApartmentDAOImpl,BookingDAOImpl,GenericDAOImpl,OrderDAOImpl,ResponseToOrderDAOImpl
public interface GenericDAO<T>
Generic DAO interface.
Implement methods which are generic for all others DAO
-
Method Summary
Modifier and TypeMethodDescriptionintCount the number of rows in the last query
Last query should have SQL_CALC_FOUND_ROWS part!!!delete(Connection con, Long id) Delete object from respective table by id.get(Connection con, Long id) Get object from respective table by id.getAll(Connection con) Get all objects from respective table.getByField(Connection con, String field, Object value) Find entity from respective table by field and value.getFew(Connection con, int start, int total) Get few objects from respective table.getWithDynamicQuery(Connection con, String secondQueryPart, Object... fields) Get objects from respective table by using query builder string partinsert(Connection con, T object) Add specific object to respective table.update(Connection con, T object) Update object in respective table.
-
Method Details
-
insert
Add specific object to respective table.- Parameters:
con- connection to databaseobject- object- Returns:
- Boolean operation result
-
get
Get object from respective table by id.- Parameters:
con- connection to databaseid- object id- Returns:
- T object result field
-
getAll
Get all objects from respective table.- Parameters:
con- connection to database- Returns:
- ArrayList
result array
-
getFew
Get few objects from respective table.
Example - start 15, total 50, return records from 15 to 65 (Not from 15 to 50!!!)- Parameters:
con- connection to databasestart- which record to start sampling fromtotal- records count to get- Returns:
- ArrayList
result array
-
getByField
Find entity from respective table by field and value.- Parameters:
con- connection to databasefield- user field. Doesn`t support foreign keys!!!value- user value- Returns:
- T field
-
getWithDynamicQuery
Get objects from respective table by using query builder string part- Parameters:
con- connection to databasesecondQueryPart- query builder string partfields- fields for insertion in query builder string part statement- Returns:
- ArrayList
result array
-
update
Update object in respective table.- Parameters:
con- connection to databaseobject- object to update- Returns:
- Boolean operation result
-
delete
Delete object from respective table by id.- Parameters:
con- connection to databaseid- object id- Returns:
- Boolean operation result
-
countRowsInLastQuery
Count the number of rows in the last query
Last query should have SQL_CALC_FOUND_ROWS part!!!- Parameters:
con- connection to database- Returns:
- number of rows
-