From 7bbf5eb963152c49de55b3b398bba1f943ff5580 Mon Sep 17 00:00:00 2001 From: Seil0 Date: Sun, 5 Jan 2020 00:04:22 +0100 Subject: [PATCH] sqlite part 0 --- prototype/build.gradle | 2 ++ .../org/hso/ecommerce/db/CustomerConfig.java | 11 +++++++++-- .../org/hso/ecommerce/db/SQLiteDialect.java | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 prototype/src/main/java/org/hso/ecommerce/db/SQLiteDialect.java diff --git a/prototype/build.gradle b/prototype/build.gradle index 6cecc52..4644f65 100644 --- a/prototype/build.gradle +++ b/prototype/build.gradle @@ -23,8 +23,10 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-devtools' implementation 'org.hsqldb:hsqldb' + implementation 'org.xerial:sqlite-jdbc:3.28.0' testCompile("org.springframework.boot:spring-boot-starter-test") } diff --git a/prototype/src/main/java/org/hso/ecommerce/db/CustomerConfig.java b/prototype/src/main/java/org/hso/ecommerce/db/CustomerConfig.java index 4ea9ec5..d0c36ac 100644 --- a/prototype/src/main/java/org/hso/ecommerce/db/CustomerConfig.java +++ b/prototype/src/main/java/org/hso/ecommerce/db/CustomerConfig.java @@ -2,9 +2,11 @@ package org.hso.ecommerce.db; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration; import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @@ -16,11 +18,16 @@ public class CustomerConfig extends AbstractJdbcConfiguration { @Bean public DataSource dataSource() { - return new EmbeddedDatabaseBuilder() + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("org.sqlite.JDBC"); + dataSource.setUrl("jdbc:sqlite:mydb.db"); + return dataSource; + +/* return new EmbeddedDatabaseBuilder() .generateUniqueName(true) .setType(EmbeddedDatabaseType.HSQL) .addScript("classpath:db/customers.sql") - .build(); + .build();*/ } @Bean diff --git a/prototype/src/main/java/org/hso/ecommerce/db/SQLiteDialect.java b/prototype/src/main/java/org/hso/ecommerce/db/SQLiteDialect.java new file mode 100644 index 0000000..e3ccc4b --- /dev/null +++ b/prototype/src/main/java/org/hso/ecommerce/db/SQLiteDialect.java @@ -0,0 +1,17 @@ +package org.hso.ecommerce.db; + +import org.hibernate.dialect.Dialect; + +import java.sql.Types; + +public class SQLiteDialect extends Dialect { + + public SQLiteDialect() { + registerColumnType(Types.BIT, "integer"); + registerColumnType(Types.TINYINT, "tinyint"); + registerColumnType(Types.SMALLINT, "smallint"); + registerColumnType(Types.INTEGER, "integer"); + // other data types + } + +}