29 lines
878 B
Java
29 lines
878 B
Java
package de.vanitasvitae.fasel.db;
|
|
|
|
import java.io.File;
|
|
import java.sql.SQLException;
|
|
|
|
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
|
import com.j256.ormlite.support.ConnectionSource;
|
|
|
|
public class H2DatabaseCreator implements DatabaseService.DatabaseCreator {
|
|
|
|
private final File directory;
|
|
|
|
public H2DatabaseCreator(File directory) {
|
|
if (directory == null) {
|
|
throw new IllegalArgumentException("Directory cannot be null!");
|
|
}
|
|
this.directory = directory;
|
|
}
|
|
|
|
@Override
|
|
public ConnectionSource getConnectionSource(String databaseName) throws SQLException {
|
|
return new JdbcConnectionSource(getH2DatabaseURL(directory, databaseName));
|
|
}
|
|
|
|
private static String getH2DatabaseURL(File directory, String databaseName) {
|
|
return "jdbc:h2:" + new File(directory, databaseName).getAbsolutePath();
|
|
}
|
|
}
|