Sueta

TitanSQL

1.0.1_14

Another mySQL plugin

·Plugin

TitanSQL

This is another mySQL plugin. The best use is to load all data on server startup and send changes to TitanSQL as needed. TitanSQL will collect data from all plugins using it and send every 5 minutes (configable) and when server is shutting down, data will be send as bulk. Also, inserts will be sent first then deletes so it's best to make every row a unique id with no repeat ids.

I've been using this on my server for over a year and it works really well and reliable so I thought I would share it.

Example

public static Table yourMySQLTable = new Table("MySQLTable"); 
public void onEnable() 
{ 
        setupTable(); 
        loadData(); 
} 
public static void setupTable() 
    { 
        yourMySQLTable.addDataType("id", DataTypeEnum.CHARARRAY, true, false, true); 
        yourMySQLTable.addDataType("modules", DataTypeEnum.STRINGLIST, false, false, false); 
        yourMySQLTable.addDataType("owner", DataTypeEnum.UUID, false, false, false); 
        yourMySQLTable.addDataType("size", DataTypeEnum.INTEGER, false, false, false); 
        yourMySQLTable.addDataType("location", DataTypeEnum.LOCATION, false, false, false); 

        yourMySQLTable.createTable(); //create the table only if one doesn't exist. 

    } 
public static void loadData() 
{ 
//load only at startup (recommended) 
    yourMySQLTable.search(new CallbackResults() { 
        @Override 
        public void onResult(List<HashMap<String, ResultData>> results) { 
            if (results != null && results.size() >0) { 
                for (HashMap<String, ResultData> result : results) { 
                    String key = result.get("id").getString(); 
                    List<String> tmp = result.get("modules").getStringList(); 
                    UUID owner = result.get("owner").getUUID(); 
                    int size = result.get("size").getInteger(); 
                    //do something 
                } 
            } 
            System.out.println("Loaded: " + results.size()); 
        } 
    }); 
} 

public void saveData() 
{ 
//Savedata when needed. 
        yourMySQLTable.setDataField("id", this.getID()); 
        yourMySQLTable.setDataField("modules", keys); 
        yourMySQLTable.setDataField("owner", this.getOwner()); 
        yourMySQLTable.setDataField("size", this.getMax()); 
        yourMySQLTable.setDataField("location", this.getLocation()); 
        yourMySQLTable.insertData(); 
    } 
} 
public void removeField(String ID) 
{ 
//call when needed 
    yourMySQLTable.delete("id", ID); 
}

Data Types

  • BYTE
  • SHORT
  • INTEGER
  • LONG
  • FLOAT
  • DOUBLE
  • STRING
  • CHARARRAY (Fix String for Unique/Primary Fields)
  • BOOLEAN
  • ITEMSTACK
  • LOCATION
  • UUID
  • INTLIST (List<Integer>)
  • STRINGLIST (List<String>)
  • ITEMLIST (List<Itemstack>)

Methods

  • addDataType (String name, DataTypeEnum type, Boolean NOT_NULL, Boolean UNIQUE, boolean PRIMARY_KEY)
    adds field to the MySQL table, you must add all the fields in the table.
  • createTable ()
    Creates a table if it doesn't exist
  • search (final CallbackResults callback)
  • search (String type, Object what, CallbackResults callback)
  • search (final DataType type, final Object what, final CallbackResults callback)
    Search table for results
  • setDataField (String dataname, Object value)
    sets data in a field for saving
  • insertData ()
    sends all fields once there set.
  • delete (String name, Object what)
    Deletes data from table

Config

host: Host_Adrress_Here 
  port: '3306' 
  database: Database_Name_Here 
  username: Username_Name_Here 
  password: Password_Name_Here 
  enabled: false #Turn to turn once information is set 
  max_que_size: 1000 #Before sending 
  stop_sending_on_shutdown: 5.0 #Minutes 
  send_data_intervals: 5.0 #Minutes

Similar projects

Plugin →