[Insight] [Resource] A Different way to use SQL Queries/ResultSets

Discussion in 'Resources' started by Goblom, Feb 19, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Goblom

    A Few days ago i started working on my FriendZone plugin, and i realized that this will cause the server to constantly lag whenever a query is made to the sql database. So i decided to go with a Threaded Querying system.

    This Threaded Querying system (from the few times i have tested it) seems to not interfere with the servers performance. This is pretty neat because well, not many plugins that use sql do this and it tends to slow the server down when there is a large volume of data present.

    Another thing i decided to do with FriendZone is add a sort of Caching system, this system stores all data in the sql database inside the plugin. This Caching system makes it possible for FriendZone to only query the sql for ResultSets once for every table that FriendZone uses. Well how is that possible?

    Since, i think doing something like this can benefit all (if not most) plugins and developers that use SQL; I decided that i wanted to share the work with you.

    Threaded Querying System --> https://gist.github.com/Goblom/9099566
    Code:java
    1. Database db = new Database();
    2.  
    3. db.setSystem(new Database.System() {
    4. public Connection connect() {
    5. // Load Drivers and such
    6. return connection_made;
    7. }
    8. });
    9.  
    10. db.update("INSERT INTO `example_table` ('id','username','online') VALUES ('NULL','Goblom','true');");
    11.  
    12. db.query("SELECT * FROM `example_table`", new Database.QueryHandler() {
    13. public void onDataRecieveEvent(DataRecieveEvent event) {
    14. // Do stuff with Result Set
    15. // event.getResult();
    16. }
    17. });


    Caching System.... --> https://gist.github.com/Goblom/9100329
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page