Beguin working on a better way to handle SQL syntax :D

This commit is contained in:
Sauilitired 2014-10-28 17:03:19 +01:00
parent 40e6b7e165
commit 13a2d4234b
5 changed files with 133 additions and 2 deletions

View File

@ -82,8 +82,15 @@ public class PWE {
// com.sk89q.worldedit.masks.Mask mask = s.getMask();
// return mask == null;
// }
// catch (Throwable e) {
//
//
// return true;
//
//
// }
return true;
}

View File

@ -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
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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;
}
}