https://github.com/ext/dbobject
Simple SQL ORM for Java
https://github.com/ext/dbobject
Last synced: 9 months ago
JSON representation
Simple SQL ORM for Java
- Host: GitHub
- URL: https://github.com/ext/dbobject
- Owner: ext
- License: bsd-3-clause
- Created: 2011-01-21T16:08:52.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2011-01-21T17:18:06.000Z (over 15 years ago)
- Last Synced: 2025-04-06T10:44:47.668Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 129 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
Simple SQL ORM for Java
=======================
Not the most efficient as it makes more queries than needed, quite easy to
optimize if needed. I initially write it as a simple abstraction for a single
table, but started reusing it more and more so I decided to upload it here.
Sample
------
public class Party extends DBObject implements se.bth.libsla.Party {
private static DBObjectState query;
private @Column("id") int _id;
private @Column("sla_id") @References(SLA.class) SLA _sla;
private @Column("role_id") @References(Role.class) Role _role;
private @Column("peer_data") @Serializes(Peer.class) Peer _peer;
private @Column("signed") int _signed;
static public void initialize_queries(DataLayer db) throws Exception {
query = initialize(Party.class, db, "party");
}
/* ... */
}
Documentation
-------------
1. First create your own class, represented by a table in the database.
2. Add a static initialization function and call it before creating any
instances, preferably at the same place where the database connection is
made.
3. For each column you want represented add the @Column annotation where the
value is the column name.
- If you have foreign keys you can add @References to create an instance of
another class.
- For serialized data use @Serializes
- SQL enumeration can either be a String, Integer or int.
4. To store changes use the inherited persist() method. If the object was loaded
from database it will be updated, otherwise it will be inserted.
5. To query rows use the selection() method with criteria.