Commit a0689ec7 authored by Giant's avatar Giant
Browse files

Rollback temporary database system fix.

parent 1053d617
......@@ -112,36 +112,34 @@
<configuration>
<artifactSet>
<includes>
<!--
<include>nl.giantit.minecraft:dbDriver</include>
-->
<include>com.google.code.gson:gson</include>
</includes>
</artifactSet>
<!--
<filters>
<filter>
<artifact>nl.giantit.minecraft:dbDriver</artifact>
<excludes>
<exclude>nl/giantit/minecraft/database/Database*.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/h2/H2Driver*.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/mysql/MySQLDriver*.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/sqlite/SQLiteDriver*.class</exclude>
<exclude>nl/giantit/minecraft/database/Database.class</exclude>
<exclude>nl/giantit/minecraft/database/Database$dbType.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/h2/H2Driver.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/h2/H2Driver$1.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/mysql/MySQLDriver.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/mysql/MySQLDriver$1.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/sqlite/SQLiteDriver.class</exclude>
<exclude>nl/giantit/minecraft/database/drivers/sqlite/SQLiteDriver$1.class</exclude>
</excludes>
</filter>
</filters>
-->
<relocations>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>nl.giantit.minecraft.giantcore.lib.gson</shadedPattern>
</relocation>
<!--
<relocation>
<pattern>nl.giantit.minecraft.database</pattern>
<shadedPattern>nl.giantit.minecraft.giantcore.database</shadedPattern>
</relocation>
-->
</relocations>
</configuration>
</execution>
......@@ -222,13 +220,11 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<!--
<dependency>
<groupId>nl.giantit.minecraft</groupId>
<artifactId>dbDriver</artifactId>
<version>1.3</version>
<version>1.3.2</version>
</dependency>
-->
<!-- /GENERAL -->
<!-- PERM -->
......
package nl.giantit.minecraft.giantcore.database;
package nl.giantit.minecraft.database;
import nl.giantit.minecraft.giantcore.database.drivers.h2.H2Driver;
import nl.giantit.minecraft.giantcore.database.drivers.mysql.MySQLDriver;
import nl.giantit.minecraft.giantcore.database.drivers.sqlite.SQLiteDriver;
import nl.giantit.minecraft.database.drivers.h2.H2Driver;
import nl.giantit.minecraft.database.drivers.mysql.MySQLDriver;
import nl.giantit.minecraft.database.drivers.sqlite.SQLiteDriver;
import org.bukkit.plugin.Plugin;
......
package nl.giantit.minecraft.giantcore.database.drivers.h2;
package nl.giantit.minecraft.database.drivers.h2;
import nl.giantit.minecraft.giantcore.database.DatabaseType;
import nl.giantit.minecraft.giantcore.database.Driver;
import nl.giantit.minecraft.giantcore.database.QueryResult;
import nl.giantit.minecraft.giantcore.database.query.AlterQuery;
import nl.giantit.minecraft.giantcore.database.query.CreateQuery;
import nl.giantit.minecraft.giantcore.database.query.DeleteQuery;
import nl.giantit.minecraft.giantcore.database.query.DropQuery;
import nl.giantit.minecraft.giantcore.database.query.IndexQuery;
import nl.giantit.minecraft.giantcore.database.query.InsertQuery;
import nl.giantit.minecraft.giantcore.database.query.Query;
import nl.giantit.minecraft.giantcore.database.query.SelectQuery;
import nl.giantit.minecraft.giantcore.database.query.TruncateQuery;
import nl.giantit.minecraft.giantcore.database.query.UpdateQuery;
import nl.giantit.minecraft.database.DatabaseType;
import nl.giantit.minecraft.database.Driver;
import nl.giantit.minecraft.database.QueryResult;
import nl.giantit.minecraft.database.query.AlterQuery;
import nl.giantit.minecraft.database.query.CreateQuery;
import nl.giantit.minecraft.database.query.DeleteQuery;
import nl.giantit.minecraft.database.query.DropQuery;
import nl.giantit.minecraft.database.query.IndexQuery;
import nl.giantit.minecraft.database.query.InsertQuery;
import nl.giantit.minecraft.database.query.Query;
import nl.giantit.minecraft.database.query.SelectQuery;
import nl.giantit.minecraft.database.query.TruncateQuery;
import nl.giantit.minecraft.database.query.UpdateQuery;
import org.bukkit.plugin.Plugin;
......@@ -206,12 +207,6 @@ public class H2Driver implements Driver {
return QueryResult.QR();
}
@Override
public SelectQuery select(String f) {
SelectQuery sQ = new H2SelectQuery(this);
return sQ.select(f);
}
@Override
public SelectQuery select(String... fields) {
SelectQuery sQ = new H2SelectQuery(this);
......
package nl.giantit.minecraft.giantcore.database.drivers.mysql;
package nl.giantit.minecraft.database.drivers.mysql;
import nl.giantit.minecraft.giantcore.database.Driver;
import nl.giantit.minecraft.giantcore.database.DatabaseType;
import nl.giantit.minecraft.giantcore.database.query.Query;
import nl.giantit.minecraft.giantcore.database.QueryResult;
import nl.giantit.minecraft.giantcore.database.query.AlterQuery;
import nl.giantit.minecraft.giantcore.database.query.CreateQuery;
import nl.giantit.minecraft.giantcore.database.query.DeleteQuery;
import nl.giantit.minecraft.giantcore.database.query.DropQuery;
import nl.giantit.minecraft.giantcore.database.query.IndexQuery;
import nl.giantit.minecraft.giantcore.database.query.InsertQuery;
import nl.giantit.minecraft.giantcore.database.query.SelectQuery;
import nl.giantit.minecraft.giantcore.database.query.TruncateQuery;
import nl.giantit.minecraft.giantcore.database.query.UpdateQuery;
import nl.giantit.minecraft.database.Driver;
import nl.giantit.minecraft.database.DatabaseType;
import nl.giantit.minecraft.database.query.Query;
import nl.giantit.minecraft.database.QueryResult;
import nl.giantit.minecraft.database.query.AlterQuery;
import nl.giantit.minecraft.database.query.CreateQuery;
import nl.giantit.minecraft.database.query.DeleteQuery;
import nl.giantit.minecraft.database.query.DropQuery;
import nl.giantit.minecraft.database.query.IndexQuery;
import nl.giantit.minecraft.database.query.InsertQuery;
import nl.giantit.minecraft.database.query.SelectQuery;
import nl.giantit.minecraft.database.query.TruncateQuery;
import nl.giantit.minecraft.database.query.UpdateQuery;
import org.bukkit.plugin.Plugin;
......@@ -216,12 +216,6 @@ public class MySQLDriver implements Driver {
return QueryResult.QR();
}
@Override
public SelectQuery select(String f) {
SelectQuery sQ = new MySQLSelectQuery(this);
return sQ.select(f);
}
@Override
public SelectQuery select(String... fields) {
SelectQuery sQ = new MySQLSelectQuery(this);
......
package nl.giantit.minecraft.giantcore.database.drivers.sqlite;
package nl.giantit.minecraft.database.drivers.sqlite;
import nl.giantit.minecraft.giantcore.database.Driver;
import nl.giantit.minecraft.giantcore.database.DatabaseType;
import nl.giantit.minecraft.giantcore.database.QueryResult;
import nl.giantit.minecraft.giantcore.database.query.AlterQuery;
import nl.giantit.minecraft.giantcore.database.query.CreateQuery;
import nl.giantit.minecraft.giantcore.database.query.DeleteQuery;
import nl.giantit.minecraft.giantcore.database.query.DropQuery;
import nl.giantit.minecraft.giantcore.database.query.IndexQuery;
import nl.giantit.minecraft.giantcore.database.query.InsertQuery;
import nl.giantit.minecraft.giantcore.database.query.Query;
import nl.giantit.minecraft.giantcore.database.query.SelectQuery;
import nl.giantit.minecraft.giantcore.database.query.TruncateQuery;
import nl.giantit.minecraft.giantcore.database.query.UpdateQuery;
import nl.giantit.minecraft.database.Driver;
import nl.giantit.minecraft.database.DatabaseType;
import nl.giantit.minecraft.database.QueryResult;
import nl.giantit.minecraft.database.query.AlterQuery;
import nl.giantit.minecraft.database.query.CreateQuery;
import nl.giantit.minecraft.database.query.DeleteQuery;
import nl.giantit.minecraft.database.query.DropQuery;
import nl.giantit.minecraft.database.query.IndexQuery;
import nl.giantit.minecraft.database.query.InsertQuery;
import nl.giantit.minecraft.database.query.Query;
import nl.giantit.minecraft.database.query.SelectQuery;
import nl.giantit.minecraft.database.query.TruncateQuery;
import nl.giantit.minecraft.database.query.UpdateQuery;
import org.bukkit.plugin.Plugin;
......@@ -206,12 +206,6 @@ public class SQLiteDriver implements Driver {
return QueryResult.QR();
}
@Override
public SelectQuery select(String f) {
SelectQuery sQ = new SQLiteSelectQuery(this);
return sQ.select(f);
}
@Override
public SelectQuery select(String... fields) {
SelectQuery sQ = new SQLiteSelectQuery(this);
......
package nl.giantit.minecraft.giantcore;
import nl.giantit.minecraft.giantcore.database.Database;
import nl.giantit.minecraft.database.Database;
import nl.giantit.minecraft.giantcore.core.Eco.Eco;
import nl.giantit.minecraft.giantcore.core.Items.Items;
import nl.giantit.minecraft.giantcore.perms.PermHandler;
......
package nl.giantit.minecraft.giantcore;
import nl.giantit.minecraft.giantcore.database.Database;
import nl.giantit.minecraft.database.Database;
import nl.giantit.minecraft.giantcore.Misc.Messages;
import nl.giantit.minecraft.giantcore.core.Eco.Eco;
import nl.giantit.minecraft.giantcore.perms.PermHandler;
......
package nl.giantit.minecraft.giantcore.database;
/**
*
* @author Giant
*/
public enum DatabaseType {
SQLite("SQLite"),
MySQL("MySQL"),
hTwo("h2");
private String name;
private DatabaseType(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}
package nl.giantit.minecraft.giantcore.database;
import nl.giantit.minecraft.giantcore.database.query.AlterQuery;
import nl.giantit.minecraft.giantcore.database.query.CreateQuery;
import nl.giantit.minecraft.giantcore.database.query.DeleteQuery;
import nl.giantit.minecraft.giantcore.database.query.DropQuery;
import nl.giantit.minecraft.giantcore.database.query.IndexQuery;
import nl.giantit.minecraft.giantcore.database.query.InsertQuery;
import nl.giantit.minecraft.giantcore.database.query.Query;
import nl.giantit.minecraft.giantcore.database.query.SelectQuery;
import nl.giantit.minecraft.giantcore.database.query.TruncateQuery;
import nl.giantit.minecraft.giantcore.database.query.UpdateQuery;
import org.bukkit.plugin.Plugin;
import java.util.List;
import java.util.Map;
/**
*
* @author Giant
*/
public interface Driver {
public enum Type {
SELECT,
UPDATE,
INSERT,
DELETE,
TRUNCATE,
CREATE,
INDEX,
ALTER,
DROP;
}
public void close();
public boolean isConnected();
public boolean tableExists(String table);
public QueryResult execQuery(Query q);
public QueryResult updateQuery(Query q);
public SelectQuery select(String f);
public SelectQuery select(String... fields);
public SelectQuery select(List<String> fields);
public SelectQuery select(Map<String, String> fields);
public UpdateQuery update(String table);
public InsertQuery insert(String table);
public DeleteQuery delete(String table);
public TruncateQuery Truncate(String table);
public CreateQuery create(String table);
public IndexQuery createIndex(String index);
public AlterQuery alter(String table);
public DropQuery drop(String table);
public String getPrefix();
public Query create(Type t);
public DatabaseType getType();
public Plugin getPlugin();
}
package nl.giantit.minecraft.giantcore.database;
import java.util.ArrayList;
import java.util.HashMap;
/**
*
* @author Giant
*/
public class QueryResult {
private int pointer = 0;
private int size;
private boolean hasResult = true;
private ArrayList<HashMap<String, String>> data;
private QueryResult(ArrayList<HashMap<String, String>> data) {
this.pointer = 0;
this.data = data;
this.size = data.size();
}
private QueryResult() {
this.hasResult = false;
}
public QueryRow getRow() {
if(data.size() > pointer) {
QueryRow qR = new QueryRow(data.get(pointer));
pointer++;
return qR;
}
pointer = 0;
return null;
}
public QueryRow getRow(int point) {
if(data.size() > point) {
QueryRow qR = new QueryRow(data.get(point));
return qR;
}
return null;
}
public void first() {
this.pointer = 0;
}
public void last() {
this.pointer = this.size - 1;
}
public int size() {
return this.size;
}
public ArrayList<HashMap<String, String>> getRawData() {
return this.data;
}
public boolean hasResultSet() {
return this.hasResult;
}
public class QueryRow {
private HashMap<String, String> row;
private QueryRow(HashMap<String, String> row) {
this.row = row;
}
public String getString(String key) {
if(row.containsKey(key.toLowerCase())) {
return row.get(key.toLowerCase());
}
return null;
}
public boolean getBoolean(String key) {
if(row.containsKey(key.toLowerCase())) {
//return Boolean.parseBoolean(row.get(key));
String v = row.get(key.toLowerCase());
return v.equalsIgnoreCase("true") || v.equals("1") || v.equals("yes") || v.equals("y");
}
return false;
}
public int getInt(String key) {
try{
if(row.containsKey(key.toLowerCase())) {
return Integer.parseInt(row.get(key.toLowerCase()));
}
}catch(NumberFormatException e) {
return 0;
}
return 0;
}
public Integer getInteger(String key) {
try{
if(row.containsKey(key.toLowerCase())) {
return Integer.valueOf(row.get(key.toLowerCase()));
}
}catch(NumberFormatException e) {
return 0;
}
return 0;
}
public float getFloat(String key) {
try{
if(row.containsKey(key.toLowerCase())) {
return Float.parseFloat(row.get(key.toLowerCase()));
}
}catch(NumberFormatException e) {
return 0F;
}
return 0F;
}
public double getDouble(String key) {
try{
if(row.containsKey(key.toLowerCase())) {
return Double.parseDouble(row.get(key.toLowerCase()));
}
}catch(NumberFormatException e) {
return 0D;
}
return 0D;
}
public long getLong(String key) {
try{
if(row.containsKey(key.toLowerCase())) {
return Long.parseLong(row.get(key.toLowerCase()));
}
}catch(NumberFormatException e) {
return 0L;
}
return 0L;
}
}
public static QueryResult QR(ArrayList<HashMap<String, String>> data) {
return new QueryResult(data);
}
public static QueryResult QR() {
return new QueryResult();
}
}
package nl.giantit.minecraft.giantcore.database.drivers.h2;
import nl.giantit.minecraft.giantcore.database.Driver;
import nl.giantit.minecraft.giantcore.database.QueryResult;
import nl.giantit.minecraft.giantcore.database.query.AlterQuery;
import nl.giantit.minecraft.giantcore.database.query.Column;
import nl.giantit.minecraft.giantcore.database.query.Group;
import nl.giantit.minecraft.giantcore.database.query.Query;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Giant
*/
public class H2AlterQuery implements AlterQuery {
private final Driver db;
private String t;
private boolean ren = false;
private String renTo;
private final List<Column> cL = new ArrayList<Column>();
private boolean prepared = false;
private String query;
public H2AlterQuery(Driver db) {
this.db = db;
}
@Override
public AlterQuery setTable(String table) {
this.t = table;
return this;
}
@Override
public AlterQuery rename(String table) {
this.ren = true;
this.renTo = table;
return this;
}
@Override
public Column addColumn(String column) {
return this.addColumn(new H2Column().setName(column));
}
@Override
public Column addColumn(Column column) {
this.cL.add(column);
return column;
}
@Override
public Query parse() {
if(!this.prepared) {
this.prepared = true;
StringBuilder sB = new StringBuilder();
sB.append("ALTER TABLE ");
sB.append(this.t.replace("#__", this.db.getPrefix()));
sB.append("\n ");
if(this.ren) {
sB.append(" RENAME TO ");
sB.append(this.renTo.replace("#__", this.db.getPrefix()));
}else{
sB.append(" ADD ");
int i = 0;
for(Column c : this.cL) {
if(!c.isParsed()) {
c.parse();
}
if(i > 0) {
sB.append(", ");
}else{
++i;
}
sB.append(c.getParsedColumn());
}
sB.append(" ");