Low Level Database Access: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Hendrik Brummermann No edit summary |
imported>Hendrik Brummermann No edit summary |
||
| Line 11: | Line 11: | ||
== Database abstraction == |
== Database abstraction == |
||
The level code database access code is encapsulated in DAO classes. Only these classes use JDBC to send SQL queries to the database. |
|||
You start a transaction by obtaining a DBTransaction object from the [http://stendhal.game-host.org/hudson/job/marauroa_HEAD/javadoc/marauroa/server/db/TransactionPool.html TransactionPool]. The you use the methods of the [http://stendhal.game-host.org/hudson/job/marauroa_HEAD/javadoc/marauroa/server/db/DBTransaction.html DBTransaction] object to talk to the database. Note that many methods expect a parameter map as second parameter. This allows you to use <nowiki>[variables]</nowiki> in your SQL statement without having to worry about escaping input parameters to prevent SQL injection attacks. |
|||
DBTransaction, however, does not execute the SQL statements itself. It internally forwards them to a subclass of DatabaseAdapter. This is a very tiny abstraction layer of to hide SQL dialects used by different database systems. |
|||
[[Image:Classdiagram_database_access.png]] |
|||
== Writing your own DAO == |
== Writing your own DAO == |
||