EoD SQL (Ease of Development) ist eine API, die über Annotationen SQL-Queries an Methoden erlaubt und diese dann zur Laufzeit ausführt. Ein Beispiel zeigt die Arbeitsweise am schnellsten:
public interface UserQuery extends BaseQuery {
@Select("SELECT * FROM users WHERE id = ?1")
public User getUserById(long id);
@Select("SELECT * FROM users")
public DataSet<User> getAllUsers();
@Update("UPDATE users SET user_name = ?{1.userName}, email_address = ?{1.emailAddress} " +
"dob = ?{1.dob} WHERE id = ?{1.id}")
public void updateUser(User user);
@Update(sql = "INSERT INTO users (user_name, email_address, dob) VALUES " +
"(?{1.userName}, ?{1.emailAddress}, ?{1.dob})",
keys = GeneratedKeys.RETURNED_KEYS_FIRST_COLUMN)
public User insertUser(User user);
}
Mit
UserQuery QUERY = QueryTool.getQuery(UserQuery.class);
wird dann ein Objekt erzeugt, was die Schnittstelle implementiert. Dann sind Aufrufe wir QUERY.getAllUsers() möglich
Zusammenfassung von der Webseite;
EoD SQL is a very small API that allows binding of SQL Queries to Java Objects. The API is designed to be compatible with the "Ease of Development" API that could be found in J2SE 1.6 beta, but not in the final release. The EoD API’s main principal is that it maps SQL ResultSet’s to objects, and not the other way around. Most OR mapping layers try to replicate the database structure in objects, where EoD SQL lets you write the SQL code, while it allows for easy access to Java Objects that map to the ResultSet.
Advantages to EoD SQL:
- Super light weight
- Very easy to work with
- Generally well documented (tell me where it’s not)
- More features than the original EoD RI
- No compile-time anything needed
- No XML, or other configuration files needed
- Should work with any JDBC database
- Lets you code whatever SQL you like
- Object mapping is loose (extra columns in the results are ignored, as are extra fields in the data object)
What EoD SQL is not:
- EoD SQL will not parse or validate your SQL in any way
- EoD SQL is not a database or database connector, it sits on top of JDBC
- EoD SQL will not get you girls