Refactor and update of some modules in the Cthulu project

We made a commit before I create the new branch. Where do I start... Well I know there is some iffy redundant Database connection being passed back and forth. That would be the BotDatabase.java module. I will need to change the design of that module, but that might be a good place to start. Why not..

So here is the BotDatabase.java.


Ok, so the connection is made AccountHandler.java, an that's ok I guess. However, we can probably set it up a bit better than that. We want to follow the rule of only using the connection when we need it, and there isn't any point of opening the connection early. It will reside in the memory, and the longer it is open the more of a chance of something going wrong. So, we want to create the connection right when we need it, run the query, and close the connection. I think I have an idea. We can make the BotDatabase.java class autocloseable, making it so it can be a resource in a try block. We can directly control the scope this way, and the 'close()' method will close and dispose of the database connection. This is the old 'runQuery()' method



Here is the new method



Looks good, added some Java 8. Hmm, looks like I can do better. For now I'm just going to move to updating the whole class. I just realized after that I will have to update AccountHandler.java. However, here is a look at the updated BotDatabase.java class.


There was problems during runtime, but were easy fixes and the repo is now stable.

Comments

Popular Posts