Package ru.bgcrm.dao
Class CommonDAO
java.lang.Object
ru.bgcrm.dao.CommonDAO
- Direct Known Subclasses:
AddressDAO
,BGBillingDAO
,Cleaner
,CommonLinkDAO
,ConfigDAO
,ContractCustomerDAO
,CustomerDAO
,CustomerGroupDAO
,DatabaseDAO
,DemoDAO
,DispatchDAO
,DocumentDAO
,EMailDAO
,EntityLogDAO
,ExecuteSQL
,FileDataDAO
,GrplDAO
,IfaceStateDAO
,InvoiceNumberDAO
,InvoiceSearchDAO
,MessageDAO
,MessagePossibleProcessSearch
,MobileDAO
,NewsDAO
,OldParamSearchDAO
,ParamDAO
,ParamGroupDAO
,ParamLogDAO
,ParamValueDAO
,ParamValueSelect
,PartyDAO
,PatternDAO
,PeriodicDAO
,ProcessCloneDAO
,ProcessDAO
,ProcessLinkSearchDAO
,ProcessParamSearchDAO
,ProcessSearchDAO
,ProcessTypeDAO
,PropertiesDAO
,QueryDAO
,QueryHistoryDAO
,QueueDAO
,ReportActionBase.Selector
,SavedFilterDAO
,SearchDAO
,SecretDAO
,ShiftDAO
,StatusChangeDAO
,StatusDAO
,SubscriptionDAO
,TabelDAO
,TaskDAO
,UserDAO
,UserGroupDAO
,WorkTaskDAO
,WorkTypeDAO
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static interface
protected class
CommonDAO.RecordUpdater<T extends Id>
-
Field Summary
Modifier and TypeFieldDescriptionprotected Connection
protected final Log
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
deleteById
(String tableName, int id) protected int
SelectsFOUND_ROWS()
for given statement.protected <T> T
getById
(String tableName, int id, CommonDAO.ObjectExtractor<T> extractor) getGroupedIds
(String tableName, String linkColumn, String selectColumn) getGroupedIds
(String tableName, String linkColumn, String selectColumn, String posColumn) Queries int list SELECTselectColumn
FROMtableName
WHERElinkColumn
=id
ORDER BYposColumn
protected String
getPageLimit
(Page page) Generates pageLIMIT offset, rows
query.protected String
getPeriodSql
(Period period, String fieldName) protected int
Takes last generated key fromps
.protected int
setPeriodParamValue
(Period period, PreparedStatement ps, int index) protected void
setRecordCount
(Page page, PreparedStatement ps) protected <T extends Id>
voidupdate
(T record, CommonDAO.RecordUpdater<T> updater) protected void
updateColumn
(String tableName, int id, String columnName, String value) protected void
protected void
updateIds
(String tableName, String linkColumn, String valueColumn, String posColumn, int id, List<Integer> values) protected int
updateOrInsert
(String updatePsQuery, String insertPsQuery, Object... params) Updates and if no records updated then inserting a new one.
-
Field Details
-
log
-
SQL_SELECT
- See Also:
-
SQL_SELECT_ALL_FROM
- See Also:
-
SQL_SELECT_COUNT_ROWS
- See Also:
-
SQL_DISTINCT
- See Also:
-
SQL_INSERT_IGNORE
- See Also:
-
SQL_INSERT_INTO
- See Also:
-
SQL_VALUES
- See Also:
-
SQL_SET
- See Also:
-
SQL_UPDATE
- See Also:
-
SQL_DELETE
- See Also:
-
SQL_DELETE_FROM
- See Also:
-
SQL_FROM
- See Also:
-
SQL_LEFT_JOIN
- See Also:
-
SQL_INNER_JOIN
- See Also:
-
SQL_WHERE
- See Also:
-
SQL_ORDER_BY
- See Also:
-
SQL_GROUP_BY
- See Also:
-
SQL_AND
- See Also:
-
SQL_LIMIT
- See Also:
-
SQL_DESC
- See Also:
-
SQL_REPLACE
- See Also:
-
SQL_ON_DUP_KEY_UPDATE
- See Also:
-
SQL_UNION_ALL
- See Also:
-
con
-
-
Constructor Details
-
CommonDAO
protected CommonDAO() -
CommonDAO
-
-
Method Details
-
lastInsertId
Takes last generated key fromps
.- Parameters:
ps
-- Returns:
- Throws:
SQLException
-
foundRows
SelectsFOUND_ROWS()
for given statement.- Parameters:
st
-- Returns:
- Throws:
SQLException
-
updateOrInsert
protected int updateOrInsert(String updatePsQuery, String insertPsQuery, Object... params) throws SQLException Updates and if no records updated then inserting a new one.- Parameters:
updatePsQuery
- UPDATE query with ? placeholders.insertPsQuery
- INSERT query with ? placeholders.params
-PreparedQuery
parameters for both queries.- Returns:
- ID of a newly inserted record, or
0
- Throws:
SQLException
-
getPageLimit
Generates pageLIMIT offset, rows
query.- Parameters:
page
- page instance.- Returns:
-
setRecordCount
- Throws:
SQLException
-
getPeriodSql
-
setPeriodParamValue
protected int setPeriodParamValue(Period period, PreparedStatement ps, int index) throws SQLException - Throws:
SQLException
-
getIds
protected Set<Integer> getIds(String tableName, String linkColumn, String selectColumn, int id) throws SQLException - Throws:
SQLException
-
getIds
protected List<Integer> getIds(String tableName, String linkColumn, String selectColumn, String posColumn, int id) throws SQLException Queries int list SELECTselectColumn
FROMtableName
WHERElinkColumn
=id
ORDER BYposColumn
- Parameters:
tableName
-linkColumn
-selectColumn
-posColumn
-id
-- Returns:
- Throws:
SQLException
-
getGroupedIds
protected Map<Integer,Set<Integer>> getGroupedIds(String tableName, String linkColumn, String selectColumn) throws SQLException - Throws:
SQLException
-
getGroupedIds
protected Map<Integer,List<Integer>> getGroupedIds(String tableName, String linkColumn, String selectColumn, String posColumn) throws SQLException - Throws:
SQLException
-
getById
protected <T> T getById(String tableName, int id, CommonDAO.ObjectExtractor<T> extractor) throws SQLException - Throws:
SQLException
-
deleteById
- Throws:
SQLException
-
update
protected <T extends Id> void update(T record, CommonDAO.RecordUpdater<T> updater) throws SQLException - Throws:
SQLException
-
updateIds
protected void updateIds(String tableName, String linkColumn, String valueColumn, Object id, Set<Integer> values) throws SQLException - Throws:
SQLException
-
updateIds
protected void updateIds(String tableName, String linkColumn, String valueColumn, String posColumn, int id, List<Integer> values) throws SQLException - Throws:
SQLException
-
updateColumn
protected void updateColumn(String tableName, int id, String columnName, String value) throws SQLException - Throws:
SQLException
-