Class DatabaseUtils
Methods to support special queries that are vendor dependent.
Database types are "mysql", "oracle", "sqlserver", and "unknown".
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetDatabaseDriverName(jakarta.persistence.EntityManager em) Deprecated.static StringgetDatabaseType(jakarta.persistence.EntityManager em) Get the database type backing an JPA entity manager.static StringgetForLikeStr(String searchStr, String databaseDriverName) Escapes a JPQL LIKE expression value.static StringgetLikeStr(String searchStr, String databaseDriverName) Returns a JPQL LIKE expression value from an input string.
E.g.static DatabaseMetaDatagetMetaData(jakarta.persistence.EntityManager em) Get the metadata of the database backing an JPA entity manager.static StringgetStartWithStr(String searchStr, String databaseDriverName) Returns a JPQL LIKE expression value from an input string.
-
Field Details
-
UNKNOWN
The Constant UNKNOWN.- See Also:
-
SQLSERVER
The Constant SQLSERVER.- See Also:
-
ORACLE
The Constant ORACLE.- See Also:
-
MYSQL
The Constant MYSQL.- See Also:
-
-
Method Details
-
getLikeStr
Returns a JPQL LIKE expression value from an input string.
E.g. for Oracle this will escape the string and then prepend and append "%".No input (null) will return a "match all" expression.
Empty string will return an exact search for an empty string.
Note: This is currently not supported in the ison UI.You cannot specify a search for a database NULL value.
- Parameters:
searchStr- the search strdatabaseDriverName- the database driver name- Returns:
- the like str
-
getStartWithStr
Returns a JPQL LIKE expression value from an input string. E.g. for Oracle this will escape the string and then append "%".No input (null) will return a "match all" expression.
Empty string will return an exact search for an empty string.
Note: This is currently not supported in the ison UI.You cannot specify a search for a database NULL value.
- Parameters:
searchStr- the search strdatabaseDriverName- the database driver name- Returns:
- the start with str
-
getForLikeStr
Escapes a JPQL LIKE expression value.E.g. for Oracle this will escape the characters "_" and "%" by prepending them with "?".
No input (null) will return a "match all" expression.
Empty string will return an exact search for an empty string.
Note: This is currently not supported in the ison UI.You cannot specify a search for a database NULL value.
- Parameters:
searchStr- the search strdatabaseDriverName- the database driver name- Returns:
- the for like str
-
getDatabaseType
Get the database type backing an JPA entity manager.Type is extracted from the JDBC URL as lowercase string. E.g. "sqlserver" from jdbc:sqlserver://127.0.0.1:1433;databaseName=priint_PublishingHubDB
Supported types are "mysql", "sqlserver", "oracle", and "unknown"
- Parameters:
em- the em- Returns:
- the database type
-
getMetaData
Get the metadata of the database backing an JPA entity manager.Example usages of this method for an MSSQL
- getMetaData(em).getDatabaseProductName() => Microsoft SQL Server
- getMetaData(em).getDatabaseProductVersion() => 12.00.2269
- getMetaData(em).getDriverName() => Microsoft JDBC Driver 4.0 for SQL Server
- getMetaData(em).getDriverVersion() => 4.0.2206.100
- getMetaData(em).getURL() => jdbc:sqlserver://127.0.0.1:1433;databaseName=priint_PublishingHubDB;sendStringParametersAsUnicode=true;...
- Parameters:
em- the em- Returns:
- the meta data
-
getDatabaseDriverName
Deprecated.Either usegetDatabaseType(EntityManager)orgetMetaData(EntityManager)Gets the database driver name.- Parameters:
em- the em- Returns:
- the database driver name
-
getDatabaseType(EntityManager)orgetMetaData(EntityManager)