Package sk.iway.iwcm
Class DB
java.lang.Object
sk.iway.iwcm.DB
- Direct Known Subclasses:
DocDB
,DocTreeDB
,GroupsDB
,HistoryDB
,StatDB
,TemplatesDB
,UserGroupsDB
nadtrieda DB tried, ma zakladne uzitocne funkcie
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Produces a string representation of a complete result setstatic void
static String
filterEscaped
(String escapedString) Deprecated.- use filterHtmlstatic String
filterHtml
(String data) Nahradi nebezpecne HTML znaky za entitystatic String
fixAiCiCol
(String column) Add lower/unaccent(column) for case insensitive search in Oracle/PostgreSQLstatic String
fixAiCiValue
(String value) Fix value for case insensitive search in Oracle/PostgreSQLstatic Boolean
getBoolean
(ResultSet rs, String colName) Vrati Boolean hodnotu z databazy, pricom korektne vrati aj NULLstatic String
getBooleanSql
(boolean b) Returns 1/0 or true/false dependind on DB typestatic Date
static String
vrati naformatovany datum z databazystatic String
getDbDateTime
(ResultSet db_result, String fieldName) Gets the dbDateTime attribute of the DB classstatic String
getDbDateTime
(ResultSet db_result, String fieldName, String serverName) Gets the dbDateTime attribute of the DB classstatic String
getDbString
(ResultSet db_result, String fieldName) vrati prekodovany a trimnuty string z result setu (povodne sa pouzivalo kvoli Oracle)static String
getDbString
(ResultSet db_result, String fieldName, boolean filter) vrati prekodovany a trimnuty string z result setu (povodne sa pouzivalo kvoli Oracle), ak je filter true vykona aj ResponseUtils.filterstatic String
vrati naformatovany cas z databazystatic Timestamp
getDbTimestamp
(long time) static long
getDbTimestamp
(ResultSet rs, String fieldName) Vrati long hodnotu Timestampu (ak nie je null), inak vrati 0static List<org.apache.commons.beanutils.DynaBean>
getDynaList
(String sql) Vrati List DynaBeanov pre zadane SQLstatic List<org.apache.commons.beanutils.DynaBean>
getDynaList
(String sql, List<?> params) static List<org.apache.commons.beanutils.DynaBean>
getDynaList
(String sql, List<?> params, String dbName) static String
getFullName
(ResultSet rs) static String
getFullName
(ResultSet rs, String titleName) Gets the fullName attribute of the DB objectstatic Integer
getInteger
(ResultSet rs, String colName) Vrati Integer hodnotu z databazy, pricom korektne vrati aj NULLstatic int
getIntValue
(Object o, int defaultValue) static long
getLongValue
(Object o, long defaultValue) static String
getOnlyNumbersIn
(String ids) Vrati a skontroluje IN zoznam pre SQL tak, aby obsahoval len cisla, cize z "1,xxx,2,3" spravi "1,2,3"static String
getOnlyNumbersIn
(String ids, boolean checkGroups) Vrati a skontroluje IN zoznam pre SQL tak, aby obsahoval len cisla, cize z "1,xxx,2,3" spravi "1,2,3" ak sa jedna o id-ckaGroupDetails
tak v pripade ze je zapnuty cloud sa kontroluje aj ich dostupnost pre aktualnu domenustatic int
getSqlParamsDatatable
(List<Object> params, PreparedStatement ps, int psCounter) Fill PreparedStatement with parametersstatic String
getSqlQueryDatatable
(String fieldName, String searchText, boolean addAnd, List<Object> params) static long
getTimestamp
(String dateTime) static long
getTimestamp
(String date, String time) return sql timestamp from given date and timestatic long
getTimestamp
(String date, String time, String serverName) static long
getTimestampNotAfterYear
(long timestamp, int year) Upravi hodnotu timestampu tak, aby nebola za zadanym rokom (kedze DB to tak nevedia mat)static long
getTimestampNotBeforeAfterYear
(long timestamp, int yearFrom, int yearTo) Upravi hodnotu timestampu tak, aby nebola pred a za zadanym rokom (kedze DB to tak nevedia mat)static long
getTimestampNotBeforeYear
(long timestamp, int year) Upravi hodnotu timestampu tak, aby nebola pred zadanym rokom (kedze DB to tak nevedia mat)static String
internationalToEnglish
(String source) prekoduje diakritiku a azbuku do cisteho asciistatic boolean
isHtmlAllowed
(String fieldName) Overi, ci je mozne v danom DB stlpci pouzit HTML kod, ak nie, tak sa pri citani rovno escapnu specialne znaky ako < alebo > aby nebolo mozne vykonat XSS utok https://thoughts-on-java.org/jpa-21-how-to-implement-type-converter/static String
prepareString
(String s, int maxLen) Oreze s tak, aby nebol dlhsi ako maxLenstatic BigDecimal
queryForBigDecimal
(String sql, Object... parameters) static double
queryForDouble
(String sql, Object... parameters) static int
queryForInt
(String sql, Object... parameters) static List
queryForList
(String sql, Object... parameters) static long
queryForLong
(String sql, Object... parameters) static String
queryForString
(String sql, Object... parameters) static String
removeSlashes
(String sqlParam) odstrani apostrofy zo stringu, treba volat vzdy, ked sa nejaky parameter dava priamo do SQL prikazustatic String
Deprecated.replaced byTools.replace(String, String, String)
static void
static void
setClob
(PreparedStatement ps, int pos, String data) nastavi pole text, alebo clob v preparedStatemente
-
Constructor Details
-
DB
public DB()
-
-
Method Details
-
isHtmlAllowed
Overi, ci je mozne v danom DB stlpci pouzit HTML kod, ak nie, tak sa pri citani rovno escapnu specialne znaky ako < alebo > aby nebolo mozne vykonat XSS utok https://thoughts-on-java.org/jpa-21-how-to-implement-type-converter/- Parameters:
fieldName
-- Returns:
-
resetHtmlAllowedFields
public static void resetHtmlAllowedFields() -
getDbString
public static String getDbString(ResultSet db_result, String fieldName, boolean filter) throws SQLException vrati prekodovany a trimnuty string z result setu (povodne sa pouzivalo kvoli Oracle), ak je filter true vykona aj ResponseUtils.filter- Parameters:
db_result
-fieldName
-filter
-- Returns:
- Throws:
SQLException
-
getDbString
vrati prekodovany a trimnuty string z result setu (povodne sa pouzivalo kvoli Oracle)- Parameters:
db_result
- result setfieldName
- meno fieldu v databaze- Returns:
- prekodovany a trimnuty string
- Throws:
Exception
- Description of the ExceptionSQLException
-
filterHtml
Nahradi nebezpecne HTML znaky za entity- Parameters:
data
-- Returns:
-
getDbTimestamp
Vrati long hodnotu Timestampu (ak nie je null), inak vrati 0- Parameters:
rs
-fieldName
-- Returns:
- Throws:
Exception
-
getDbTimestamp
-
getDbDate
vrati naformatovany datum z databazy- Parameters:
db_result
- result setfieldName
- meno fieldu v databaze- Returns:
- naformatovany datum z databazy
- Throws:
Exception
- Description of the ExceptionSQLException
-
getDate
- Throws:
SQLException
-
getDbTime
vrati naformatovany cas z databazy- Parameters:
db_result
- result setfieldName
- meno fieldu v databaze- Returns:
- naformatovany cas z databazy
- Throws:
Exception
- Description of the Exception
-
getDbDateTime
Gets the dbDateTime attribute of the DB class- Parameters:
db_result
- Description of the ParameterfieldName
- Description of the Parameter- Returns:
- The dbDateTime value
- Throws:
Exception
- Description of the ExceptionSQLException
-
getDbDateTime
public static String getDbDateTime(ResultSet db_result, String fieldName, String serverName) throws SQLException Gets the dbDateTime attribute of the DB class- Parameters:
db_result
- Description of the ParameterfieldName
- Description of the ParameterserverName
- Description of the Parameter- Returns:
- The dbDateTime value
- Throws:
Exception
- Description of the ExceptionSQLException
-
getTimestamp
-
getTimestamp
-
getTimestamp
return sql timestamp from given date and time- Parameters:
date
- datumtime
- cas- Returns:
- The timestamp value
-
internationalToEnglish
prekoduje diakritiku a azbuku do cisteho ascii- Parameters:
source
- Description of the Parameter- Returns:
- Description of the Return Value
-
replace
Deprecated.replaced byTools.replace(String, String, String)
Replace stringu na string- Parameters:
src
- zdrojovy stringoldStr
- co sa ma nahraditnewStr
- za co sa ma nahradit- Returns:
- string src v ktorom je nahradene oldStr za newStr
-
setClob
nastavi pole text, alebo clob v preparedStatemente- Parameters:
ps
- The new clob valuepos
- The new clob valuedata
- The new clob value- Throws:
Exception
- Description of the Exception
-
removeSlashes
odstrani apostrofy zo stringu, treba volat vzdy, ked sa nejaky parameter dava priamo do SQL prikazu- Parameters:
sqlParam
-- Returns:
-
dumpResultSet
Produces a string representation of a complete result set- Parameters:
rs
- The ResultSet to be displayed- Returns:
- The string representation
- Throws:
SQLException
- to indicate a problem with the ResultSet
-
getFullName
- Throws:
Exception
-
getFullName
Gets the fullName attribute of the DB object- Parameters:
rs
- Description of the Parameter- Returns:
- The fullName value
- Throws:
Exception
-
prepareString
Oreze s tak, aby nebol dlhsi ako maxLen- Parameters:
s
-maxLen
-- Returns:
-
getDynaList
Vrati List DynaBeanov pre zadane SQL- Parameters:
sql
- - SQL prikaz- Returns:
-
getDynaList
-
getDynaList
-
getIntValue
-
getLongValue
-
execute
-
queryForInt
-
queryForLong
-
queryForString
-
queryForDouble
-
queryForBigDecimal
-
queryForList
-
getOnlyNumbersIn
Vrati a skontroluje IN zoznam pre SQL tak, aby obsahoval len cisla, cize z "1,xxx,2,3" spravi "1,2,3"- Parameters:
ids
-- Returns:
-
getOnlyNumbersIn
Vrati a skontroluje IN zoznam pre SQL tak, aby obsahoval len cisla, cize z "1,xxx,2,3" spravi "1,2,3" ak sa jedna o id-ckaGroupDetails
tak v pripade ze je zapnuty cloud sa kontroluje aj ich dostupnost pre aktualnu domenu- Parameters:
ids
-checkGroups
- indikuje ci sa jedna o id-cka GroupDetails- Returns:
-
getTimestampNotBeforeYear
public static long getTimestampNotBeforeYear(long timestamp, int year) Upravi hodnotu timestampu tak, aby nebola pred zadanym rokom (kedze DB to tak nevedia mat)- Parameters:
timestamp
-year
-- Returns:
-
getTimestampNotAfterYear
public static long getTimestampNotAfterYear(long timestamp, int year) Upravi hodnotu timestampu tak, aby nebola za zadanym rokom (kedze DB to tak nevedia mat)- Parameters:
timestamp
-year
-- Returns:
-
getTimestampNotBeforeAfterYear
public static long getTimestampNotBeforeAfterYear(long timestamp, int yearFrom, int yearTo) Upravi hodnotu timestampu tak, aby nebola pred a za zadanym rokom (kedze DB to tak nevedia mat)- Parameters:
timestamp
-yearFrom
-yearTo
-- Returns:
-
filterEscaped
Deprecated.- use filterHtmlosetri HTML znacky v retazci - DEPRECATED, pouzi filterHtml- Parameters:
escapedString
-- Returns:
- *
-
getInteger
Vrati Integer hodnotu z databazy, pricom korektne vrati aj NULL- Parameters:
rs
-colName
-- Returns:
- Throws:
SQLException
-
getBoolean
Vrati Boolean hodnotu z databazy, pricom korektne vrati aj NULL- Parameters:
rs
-colName
-- Returns:
- Throws:
SQLException
-
getBooleanSql
Returns 1/0 or true/false dependind on DB type- Parameters:
b
-- Returns:
-
fixAiCiCol
Add lower/unaccent(column) for case insensitive search in Oracle/PostgreSQL- Parameters:
column
-- Returns:
-
fixAiCiValue
Fix value for case insensitive search in Oracle/PostgreSQL- Parameters:
value
-- Returns:
-
getSqlQueryDatatable
-
getSqlParamsDatatable
public static int getSqlParamsDatatable(List<Object> params, PreparedStatement ps, int psCounter) throws SQLException Fill PreparedStatement with parameters- Parameters:
params
- - list of Parametersps
- - prepared statementpsCounter
- - counter of parameters, starts with 1 for first parameter- Returns:
- - new counter of parameters
- Throws:
SQLException
-