feature: Metadata Mapping pattern (#1932)
* metadata-mapping * Update README.md * add class diagram * update README.md * fix identation * Update pom.xml * fix indentation * fix ci * remove e.printstack * fix ci * update class diagram * fix ci * fix ci * fix sc * fix smells * Update DatabaseUtil.java * fix coverage * Update DatabaseUtil.java * Update DatabaseUtil.java * Update DatabaseUtil.java * Update metadata-mapping/README.md Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com> * fix review * fix review * Update App.java * Update App.java * fix review Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
package com.iluwatar.metamapping.utils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
|
||||
/**
|
||||
* Create h2 database.
|
||||
*/
|
||||
@Slf4j
|
||||
public class DatabaseUtil {
|
||||
private static final String DB_URL = "jdbc:h2:mem:metamapping";
|
||||
private static final String CREATE_SCHEMA_SQL = "DROP TABLE IF EXISTS `user`;"
|
||||
+ "CREATE TABLE `user` (\n"
|
||||
+ " `id` int(11) NOT NULL AUTO_INCREMENT,\n"
|
||||
+ " `username` varchar(255) NOT NULL,\n"
|
||||
+ " `password` varchar(255) NOT NULL,\n"
|
||||
+ " PRIMARY KEY (`id`)\n"
|
||||
+ ");";
|
||||
|
||||
/**
|
||||
* Hide constructor.
|
||||
*/
|
||||
private DatabaseUtil() {}
|
||||
|
||||
/**
|
||||
* Create database.
|
||||
*/
|
||||
static {
|
||||
LOGGER.info("create h2 database");
|
||||
var source = new JdbcDataSource();
|
||||
source.setURL(DB_URL);
|
||||
try (var statement = source.getConnection().createStatement()) {
|
||||
statement.execute(CREATE_SCHEMA_SQL);
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("unable to create h2 data source", e);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user