From 471a6ce1d534d6a508fb315f2cc22cf65ac0d66e Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 6 May 2013 11:17:23 -0700 Subject: [PATCH] Add a version of createTableIfMissing minus uinqueness constraints. Most callers don't want or need 'em and have to import List and Collections just to conveniently pass in an empty list. --- .../java/com/samskivert/jdbc/BaseLiaison.java | 15 ++++++++++++++- .../java/com/samskivert/jdbc/DatabaseLiaison.java | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/samskivert/jdbc/BaseLiaison.java b/src/main/java/com/samskivert/jdbc/BaseLiaison.java index ea01fe73..81cfb630 100644 --- a/src/main/java/com/samskivert/jdbc/BaseLiaison.java +++ b/src/main/java/com/samskivert/jdbc/BaseLiaison.java @@ -9,6 +9,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Collections; import java.util.List; import com.samskivert.util.StringUtil; @@ -185,8 +186,20 @@ public abstract class BaseLiaison implements DatabaseLiaison return true; } + /** + * Created a new table of the given name with the given column names and column definitions; + * the given set of unique constraints (or null) and the given primary key columns (or null). + * Returns true if the table was successfully created, false if it already existed. + */ + public boolean createTableIfMissing (Connection conn, String table, List columns, + List declarations, + List primaryKeyColumns) throws SQLException { + return createTableIfMissing(conn, table, columns, declarations, + Collections.>emptyList(), primaryKeyColumns); + } + @Override // from DatabaseLiaison - public boolean createTableIfMissing (Connection conn, String table, List columns, + public boolean createTableIfMissing (Connection conn, String table, List columns, List definitions, List> uniqueConstraintColumns, List primaryKeyColumns) diff --git a/src/main/java/com/samskivert/jdbc/DatabaseLiaison.java b/src/main/java/com/samskivert/jdbc/DatabaseLiaison.java index ed271ea1..8ef1751a 100644 --- a/src/main/java/com/samskivert/jdbc/DatabaseLiaison.java +++ b/src/main/java/com/samskivert/jdbc/DatabaseLiaison.java @@ -137,6 +137,16 @@ public interface DatabaseLiaison ColumnDefinition columnDef) throws SQLException; + /** + * Created a new table of the given name with the given column names and column definitions; + * the given set of unique constraints (or null) and the given primary key columns (or null). + * Returns true if the table was successfully created, false if it already existed. + */ + public boolean createTableIfMissing (Connection conn, String table, List columns, + List declarations, + List primaryKeyColumns) + throws SQLException; + /** * Created a new table of the given name with the given column names and column definitions; * the given set of unique constraints (or null) and the given primary key columns (or null).