Package org.europa.together.business
Interface DatabaseActions
- All Known Implementing Classes:
JdbcActions
@API(status=STABLE,
since="1.0",
consumers="JdbcActions")
@Component
public interface DatabaseActions
DatabaseActions is a simple helper class to execute SQL queries and other
database operations out of the DAO Context. To establish a JDBC connection
for unit tests call the constructor:
DatabaseActions(boolean activateTestMode);
DatabaseActions(boolean activateTestMode);
- Since:
- 1.0
- Version:
- 2.0
- Author:
- elmar.dott@gmail.com
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Establish an JDBC connection.int
countResultSets
(ResultSet results) Count the size of a ResultSet.executeQuery
(String sql) Execute a plain SQL query and get the ResultSet.boolean
executeSqlFromClasspath
(String sqlFile) Load an SQL file from the classpath and execute the script.Return a object with all JDBC connection meta date.
-
Field Details
-
FEATURE_ID
Identifier for the given feature.- See Also:
-
-
Method Details
-
connect
Establish an JDBC connection. If the propertyFile parameter is empty, then the method load by default the configuration from the classpath. The path to the external property file have to be relative to the execution path.- Parameters:
propertyFile
- as String- Returns:
- true on success
-
executeQuery
Execute a plain SQL query and get the ResultSet. If there exist multiple SELECT statements, then the ResultSet contains only the rusultSet of the last SELECT statement.- Parameters:
sql
- as String- Returns:
- result as ResultSet
- Throws:
SQLException
-
executeSqlFromClasspath
Load an SQL file from the classpath and execute the script. Attention: This function should be used to populate a database and so on. It is not designed to handle multiple ResultSets by using SELECT. If multiple SELECT statements appears in an SQL file, then only the ResultSet of the last SELECT statement will be available.
Internal call this function for each single SQL statement the executeQuery() method.- Parameters:
sqlFile
- as String- Returns:
- true on success
-
countResultSets
Count the size of a ResultSet.- Parameters:
results
- as ResultSet- Returns:
- count the results
- Throws:
SQLException
-
getJdbcMetaData
Return a object with all JDBC connection meta date.- Returns:
- JdbcConnection as Object
- Throws:
SQLException
-