summaryrefslogtreecommitdiff
path: root/sql-persistence
diff options
context:
space:
mode:
Diffstat (limited to 'sql-persistence')
-rw-r--r--sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlConstructor.java11
-rw-r--r--sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java2
-rw-r--r--sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSequenceMeta.java13
-rw-r--r--sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java2
-rw-r--r--sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSessionFactory.java4
-rw-r--r--sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlUnit.java31
6 files changed, 56 insertions, 7 deletions
diff --git a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlConstructor.java b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlConstructor.java
new file mode 100644
index 0000000..35511e6
--- /dev/null
+++ b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlConstructor.java
@@ -0,0 +1,11 @@
+package io.trygvis.persistence.sql;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.CONSTRUCTOR)
+@Retention(RetentionPolicy.CLASS)
+public @interface SqlConstructor {
+}
diff --git a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java
index 361fd95..6d3ed67 100644
--- a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java
+++ b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlDao.java
@@ -27,6 +27,8 @@ public abstract class SqlDao<Id, T, S extends SqlSession, Row> {
public abstract List<T> selectWhere(String where) throws SQLException;
+ public abstract String[] createTableSql();
+
// -----------------------------------------------------------------------
// Protected
// -----------------------------------------------------------------------
diff --git a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSequenceMeta.java b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSequenceMeta.java
new file mode 100644
index 0000000..a3917bf
--- /dev/null
+++ b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSequenceMeta.java
@@ -0,0 +1,13 @@
+package io.trygvis.persistence.sql;
+
+public class SqlSequenceMeta {
+ public final String sequenceName;
+ public final String createSql;
+ public final String dropSql;
+
+ public SqlSequenceMeta(String sequenceName, String createSql, String dropSql) {
+ this.sequenceName = sequenceName;
+ this.createSql = createSql;
+ this.dropSql = dropSql;
+ }
+}
diff --git a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java
index 43f1206..fc2407d 100644
--- a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java
+++ b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSession.java
@@ -5,7 +5,7 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
-public class SqlSession {
+public abstract class SqlSession {
// TODO: Make private
public final Connection c;
diff --git a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSessionFactory.java b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSessionFactory.java
index adf36d3..acd0882 100644
--- a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSessionFactory.java
+++ b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlSessionFactory.java
@@ -13,6 +13,10 @@ public abstract class SqlSessionFactory<T extends SqlSession> {
this.ds = ds;
}
+ public SqlUnit getUnit() {
+ return unit;
+ }
+
public T newSession() throws SQLException {
Connection c = ds.getConnection();
diff --git a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlUnit.java b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlUnit.java
index 2879f5d..8eb6f98 100644
--- a/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlUnit.java
+++ b/sql-persistence/src/main/java/io/trygvis/persistence/sql/SqlUnit.java
@@ -1,18 +1,37 @@
package io.trygvis.persistence.sql;
+import java.util.ArrayList;
import java.util.List;
-import static java.util.Arrays.asList;
+import static java.util.Collections.addAll;
+import static java.util.Collections.emptyList;
public class SqlUnit {
- private final List<SqlEntityMeta> entities;
+ private final SqlEntityMeta[] entities;
+ private final SqlSequenceMeta[] sequences;
- public SqlUnit(SqlEntityMeta... entities) {
- this.entities = asList(entities);
+ public SqlUnit(SqlEntityMeta[] entities, SqlSequenceMeta[] sequences) {
+ this.entities = entities;
+ this.sequences = sequences;
}
- public List<SqlEntityMeta> getEntities() {
- return entities;
+ public List<String> create() {
+ List<String> strings = new ArrayList<>();
+
+ for (SqlSequenceMeta meta : sequences) {
+ addAll(strings, meta.createSql);
+ }
+
+ for (SqlEntityMeta meta : entities) {
+ addAll(strings, meta.createTableSql);
+ }
+
+ return strings;
+ }
+
+ public List<String> drop() {
+ // TODO: implement
+ return emptyList();
}
}