Skip to content

Commit

Permalink
#3 More robust
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Mar 2, 2016
1 parent 7c93f0f commit 9116099
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.valuereporter.ValuereporterException;
import org.valuereporter.ValuereporterTechnicalException;

import java.sql.Connection;
import java.sql.DriverManager;
Expand Down Expand Up @@ -59,6 +60,13 @@ public void initializeDatabase() {
if (useEmbeddedDb) {
log.info("Creating new database at url {}", jdbcUrl);
Connection connection = connectToHsqldb();
try {
if (connection == null || connection.isClosed()){
throw new ValuereporterTechnicalException("Failed to open database at URL " + jdbcUrl, StatusType.connection_error);
}
} catch (SQLException e) {
throw new ValuereporterTechnicalException("Failed to open database at URL " + jdbcUrl, e,StatusType.connection_error);
}
createUsers(connection);
createTables(connection);
insertValues(connection);
Expand Down Expand Up @@ -90,7 +98,7 @@ public Connection connectToHsqldb() {
public boolean isHSQLdbAvailable() {
boolean isExistingDb = false;
try {
String hsqldbUrl = jdbcUrl + ";ifexists=true";
String hsqldbUrl = jdbcUrl + ";ifexists=false";
log.info("Try to connect to existing database with url {}", hsqldbUrl);
DriverManager.getConnection(hsqldbUrl, jdbcUserName, jdbcPassword);
isExistingDb = true;
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
<logger name="org.eclipse.jetty" level="WARN"/>
<logger name="org.apache.activemq" level="INFO"/>
<logger name="org.apache.cxf" level="INFO"/>
<logger name="org.apache" level="WARN"/>
<logger name="org.springframework" level="WARN"/>
<logger name="org.springframework.jdbc" level="INFO"/>
<logger name="org.apache" level="trace"/>
<logger name="org.springframework" level="trace"/>
<logger name="org.springframework.jdbc" level="trace"/>


<logger name="org.valuereporter" level="INFO"/>
<logger name="org.valuereporter" level="trace"/>
<logger name="org.springframework.web" level="INFO"/>
<root level="info">
<root level="trace">
<appender-ref ref="logfile" />
<appender-ref ref="STDOUT" />
<!--<appender-ref ref="EMAIL" />-->
Expand Down

0 comments on commit 9116099

Please sign in to comment.