Refactoring Database Access in Marauroa: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Hendrik Brummermann started a faq |
imported>Hendrik Brummermann →FAQ: Porting |
||
| Line 19: | Line 19: | ||
[[Image:Marauroa.server.game.db.png]] |
[[Image:Marauroa.server.game.db.png]] |
||
== FAQ == |
== Concept FAQ == |
||
=== Where did IDatabase / JDBCDatabase go? === |
=== Where did IDatabase / JDBCDatabase go? === |
||
| Line 42: | Line 42: | ||
DAORegistry.get().register(CharacterDAO.class, new SomeGameCharaterDAO()); |
DAORegistry.get().register(CharacterDAO.class, new SomeGameCharaterDAO()); |
||
Note: In the register call the first parameter is the parent clase you want to replace. |
Note: In the register call the first parameter is the parent clase you want to replace. |
||
=== What are those database adapters for? === |
|||
The are a thin layer of database abstraction. This allows us to not only support MySQL but also database systems with don't require an external server. |
|||
=== Why is there a method getLastInsertId? === |
|||
It is a replacement for "select LAST_INSERT_ID() as inserted_id" which is a MySQL "feature". By using getLastInsertId() instead of that SQL statement, your code will work with other database systems as well (unless you use other system specific functions). |
|||
== Porting FAQ == |
|||
=== Does this mean I have to adjust my game? === |
|||
That depends. If you did not do any low level database stuff, there should be no changes required. As a rule of thumb: If your code compiles with the new version of Marauroa, you are fine. |
|||
=== What happened to IDatabase/JDBCDatabase? === |
|||
It was replaced by smaller DAO classes. See above for how to use them. |
|||
=== What happened to Transaction, JDBCTransaction, Accessor, JDBCAccess? === |
|||
They where replaced with DBTransaction. You can get a DBTransaction from the TransactionPool. Make sure that you commit or rollback it after use. |
|||
=== I provided my own subclass of IDatabase/JDBCDatabase === |
|||
Please have a look at the ...DAO classes in the marauroa.server.game.db package and split your sub class accordingly. After that is done you need to register them in the DAORegistry with the class of the original DAO and an instance of your class. |
|||