Skip to content

Commit

Permalink
#551:
Browse files Browse the repository at this point in the history
Abstracted and changed database init script functionality to support use of SQL-like scripts with non-JDBC connections.

Supports #525
  • Loading branch information
AnkBurov authored and rnorth committed Feb 3, 2018
1 parent a6d8bf2 commit 198fa8c
Show file tree
Hide file tree
Showing 12 changed files with 592 additions and 294 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.6.1] - 2018-01-31
## UNRELEASED

### Fixed

- Fixed extraneous insertion of `useSSL=false` in all JDBC URL strings, even for DBs that do not understand it. Usage is now restricted to MySQL by default and can be overridden by authors of `JdbcDatabaseContainer` subclasses ([\#568](https://github.com/testcontainers/testcontainers-java/issues/568))

### Changed
- Abstracted and changed database init script functionality to support use of SQL-like scripts with non-JDBC connections. ([\#551](https://github.com/testcontainers/testcontainers-java/pull/551))

## [1.6.0] - 2018-01-28

### Fixed
Expand Down
23 changes: 23 additions & 0 deletions modules/database-commons/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-parent</artifactId>
<version>0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>database-commons</artifactId>
<name>TestContainers :: Database-Commons</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>testcontainers</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.testcontainers.delegate;

import java.util.Collection;

/**
* @param <CONNECTION> connection to the database
* @author Eugeny Karpov
*/
public abstract class AbstractDatabaseDelegate<CONNECTION> implements DatabaseDelegate {

/**
* Database connection
*/
private CONNECTION connection;

private boolean isConnectionStarted = false;

/**
* Get or create new connection to the database
*/
protected CONNECTION getConnection() {
if (!isConnectionStarted) {
connection = createNewConnection();
isConnectionStarted = true;
}
return connection;
}

@Override
public void execute(Collection<String> statements, String scriptPath, boolean continueOnError, boolean ignoreFailedDrops) {
int lineNumber = 0;
for (String statement : statements) {
lineNumber++;
execute(statement, scriptPath, lineNumber, continueOnError, ignoreFailedDrops);
}
}

@Override
public void close() {
if (isConnectionStarted) {
closeConnectionQuietly(connection);
isConnectionStarted = false;
}
}

/**
* Quietly close the connection
*/
protected abstract void closeConnectionQuietly(CONNECTION connection);

/**
* Template method for creating new connections to the database
*/
protected abstract CONNECTION createNewConnection();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.testcontainers.delegate;

import java.util.Collection;

/**
* Database delegate
*
* Gives an abstraction from concrete database
*
* @author Eugeny Karpov
*/
public interface DatabaseDelegate extends AutoCloseable {

/**
* Execute statement by the implementation of the delegate
*/
void execute(String statement, String scriptPath, int lineNumber, boolean continueOnError, boolean ignoreFailedDrops);

/**
* Execute collection of statements
*/
void execute(Collection<String> statements, String scriptPath, boolean continueOnError, boolean ignoreFailedDrops);

/**
* Close connection to the database
*
* Overridden to suppress throwing Exception
*/
@Override
void close();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.testcontainers.exception;

/**
* Inability to create connection to the database
*
* @author Eugeny Karpov
*/
public class ConnectionCreationException extends RuntimeException {

public ConnectionCreationException(String message, Throwable cause) {
super(message, cause);
}
}
Loading

0 comments on commit 198fa8c

Please sign in to comment.