Refactoring Database Access in Marauroa: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Kymara
m unhandy -> hard to maintain
imported>Kymara
 
(46 intermediate revisions by 3 users not shown)
Line 1: Line 1:
At the moment database access in marauroa is designed for a single thread application. While this works most of the time in turn based games (yes, Stendhal is turn based internally), it prevents doing non time critical stuff in another thread. In Stendhal we have the problem that any update or delete operation to the gameEvents table that takes more than a couple of seconds, kills the server.
Database access in marauroa was designed for a single thread application. While this works most of the time in turn based games (yes, Stendhal is turn based internally), it prevents doing non time critical stuff in another thread. In Stendhal we have the problem that any update or delete operation to the gameEvents table that takes more than a couple of seconds, kills the server.


== Requirements ==
== Requirements ==
Line 36: Line 36:


Imagine you want to subclass the CharacterDAO with your class SomeGameCharacterDAO:
Imagine you want to subclass the CharacterDAO with your class SomeGameCharacterDAO:
<source lang="java">
public class SomeGameCharacterDAO extends CharacterDAO {
public class SomeGameCharacterDAO extends CharacterDAO {
...
...
</source>

You simply register it as
You simply register it as
<source lang="java">
DAORegistry.get().register(CharacterDAO.class, new SomeGameCharacterDAO());
DAORegistry.get().register(CharacterDAO.class, new SomeGameCharacterDAO());
</source>
Note: In the register call the first parameter is the parent class you want to replace.
Note: In the register call the first parameter is the parent class you want to replace.


Line 46: Line 49:
=== What are those database adapters for? ===
=== What are those database adapters for? ===


They 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.
They are a thin layer of database abstraction. This allows us to not only support MySQL but also database systems which don't require an external server.



=== Why is there a method getLastInsertId? ===
=== Why is there a method getLastInsertId? ===
Line 80: Line 82:


The following diff shows the complete list of changes that were required to port JMaPacman. I think it may help you to get a feeling on how to adjust your own code.
The following diff shows the complete list of changes that were required to port JMaPacman. I think it may help you to get a feeling on how to adjust your own code.
<!--

Don't use syntax highlighting here because it does not work well with the diff characters and bold formation
<source lang="java">
-->
public class MaPacmanRPRuleProcessor implements IRPRuleProcessor
public class MaPacmanRPRuleProcessor implements IRPRuleProcessor
{
{
Line 162: Line 167:
}
}
}
}


[[Category:Marauroa]]