From 13a2d4234b15ae71bd8568635784a3450f62d1d1 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Tue, 28 Oct 2014 17:03:19 +0100 Subject: [PATCH] Beguin working on a better way to handle SQL syntax :D --- .../com/intellectualcrafters/plot/PWE.java | 11 ++++- .../plot/database/sqlobjects/PlotTable.java | 13 +++++ .../plot/database/sqlobjects/SQLField.java | 24 ++++++++++ .../plot/database/sqlobjects/SQLTable.java | 48 +++++++++++++++++++ .../plot/database/sqlobjects/SQLType.java | 39 +++++++++++++++ 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/PlotTable.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLField.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLTable.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLType.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java index a2b4f7a67..8e84eedbc 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PWE.java @@ -82,9 +82,16 @@ public class PWE { // com.sk89q.worldedit.masks.Mask mask = s.getMask(); // return mask == null; // } + + + // catch (Throwable e) { -// return true; -// } +// +// +// return true; +// +// +// } return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/PlotTable.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/PlotTable.java new file mode 100644 index 000000000..01b4b0f5a --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/PlotTable.java @@ -0,0 +1,13 @@ +package com.intellectualcrafters.plot.database.sqlobjects; + +/** + * Created by Citymonstret on 2014-10-28. + */ +public class PlotTable extends SQLTable { + + public PlotTable() { + super("plots"); + } + + public +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLField.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLField.java new file mode 100644 index 000000000..86526e392 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLField.java @@ -0,0 +1,24 @@ +package com.intellectualcrafters.plot.database.sqlobjects; + +/** + * Created by Citymonstret on 2014-10-28. + */ +public class SQLField { + + private SQLType type; + private Object value; + + public SQLField(SQLType type, Object value) { + this.type = type; + this.value = value; + } + + public SQLType getType() { + return this.type; + } + + public Object getValue() { + return this.value; + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLTable.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLTable.java new file mode 100644 index 000000000..2aa281d3f --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLTable.java @@ -0,0 +1,48 @@ +package com.intellectualcrafters.plot.database.sqlobjects; + +import com.intellectualcrafters.plot.Settings; + +/** + * Created by Citymonstret on 2014-10-28. + */ +public abstract class SQLTable { + + private String name; + private SQLField[] fields; + private String primaryKey; + + public SQLTable(String name, String primaryKey, SQLField ... fields) { + this.name = Settings.DB.PREFIX + name; + this.fields = fields; + this.primaryKey = primaryKey; + } + + @Override + public String toString() { + return this.name; + } + + public SQLField[] getFields() { + return this.fields; + } + + private void createFromFields() { + StringBuilder statement = new StringBuilder(); + statement.append("CREATE TABLE `" + name + "` IF NOT EXISTS ("); + for(SQLField field : fields) { + switch(field.getType()) { + case INTEGER: + break; + case VARCHAR: + break; + case BOOL: + break; + default: + break; + } + } + } + + public abstract void create(); + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLType.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLType.java new file mode 100644 index 000000000..97f067ebc --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/sqlobjects/SQLType.java @@ -0,0 +1,39 @@ +package com.intellectualcrafters.plot.database.sqlobjects; + +/** + * Created by Citymonstret on 2014-10-28. + */ +public enum SQLType { + + INTEGER(0, "integer", Integer.class, 11), + VARCHAR("", "varchar", String.class, 300), + BOOL(false, "bool", Boolean.class, 1); + + private Object defaultValue; + private String sqlName; + private Class javaClass; + private int length; + + SQLType(Object defaultValue, String sqlName, Class javaClass, int length) { + this.defaultValue = defaultValue; + this.sqlName = sqlName; + this.javaClass = javaClass; + this.length = length; + } + + public int getLength() { + return this.length; + } + @Override + public String toString() { + return this.sqlName; + } + + public Class getJavaClass() { + return this.javaClass; + } + + public Object getDefaultValue() { + return this.defaultValue; + } +}