commit | author | age
|
c387eb
|
1 |
/* |
U |
2 |
* BaseLink - Generic object relational mapping |
|
3 |
* Copyright (C) 2011 Ulrich Hilger, http://uhilger.de |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
|
8 |
* (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see http://www.gnu.org/licenses/ |
|
17 |
*/ |
|
18 |
|
|
19 |
package de.uhilger.baselink; |
|
20 |
|
|
21 |
import java.sql.Connection; |
|
22 |
import java.sql.PreparedStatement; |
|
23 |
import java.sql.ResultSet; |
|
24 |
|
|
25 |
/** |
|
26 |
* Classes that map objects to and from database records need to implement this interface. |
|
27 |
* |
|
28 |
* @author Copyright (c) Ulrich Hilger, http://uhilger.de |
|
29 |
* @author Published under the terms and conditions of |
|
30 |
* the <a href="http://www.gnu.org/licenses/" target="_blank">GNU General Public License</a> |
|
31 |
*/ |
|
32 |
public interface Record { |
|
33 |
|
|
34 |
/** indicator to include BLOBS in read / write operations */ |
|
35 |
public static final boolean WITH_BLOBS = true; |
|
36 |
/** indicator to exclude BLOBS from read / write operations */ |
|
37 |
public static final boolean WITHOUT_BLOBS = false; |
|
38 |
|
|
39 |
/** |
|
40 |
* Get the name of the database table this record references |
|
41 |
* @return the table name |
|
42 |
*/ |
|
43 |
public String getTableName(); |
|
44 |
|
|
45 |
/** |
|
46 |
* Get contents of this record as an object |
|
47 |
* @param resultSet a resultSet that points to the record to get as an object |
|
48 |
* @param includeBlobs indicator whether or not to include BLOBs |
|
49 |
* @return an object having the data of this record |
|
50 |
* @throws Exception |
|
51 |
*/ |
|
52 |
public Object toObject(ResultSet resultSet, boolean includeBlobs) throws Exception; |
|
53 |
|
|
54 |
/** |
|
55 |
* Get a statement suitable to insert a given object to the database |
|
56 |
* @param c the database connection to use for the insert |
|
57 |
* @param record the object to insert |
|
58 |
* @param autoGeneratedKeys a flag indicating whether auto-generated keys should be returned; |
|
59 |
* one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS |
|
60 |
* @return the insert statement |
|
61 |
* @throws Exception |
|
62 |
*/ |
|
63 |
public PreparedStatement getInsertStmt(Connection c, Object record, int autoGeneratedKeys) |
|
64 |
throws Exception; |
|
65 |
|
|
66 |
/** |
|
67 |
* Get a statement suitable to insert a given object to the database |
|
68 |
* @param c the database connection to use for the insert |
|
69 |
* @param record the object to insert |
|
70 |
* @return the insert statement |
|
71 |
* @throws Exception |
|
72 |
*/ |
|
73 |
public PreparedStatement getInsertStatment(Connection c, Object record) |
|
74 |
throws Exception; |
|
75 |
|
|
76 |
/** |
|
77 |
* Get a statement suitable to update a given object in the database |
|
78 |
* @param c the database connection to use for the update |
|
79 |
* @param record the object to update |
|
80 |
* @return the update statement |
|
81 |
* @throws Exception |
|
82 |
*/ |
|
83 |
public PreparedStatement getUpdateStatment(Connection c, Object record) |
|
84 |
throws Exception; |
|
85 |
|
|
86 |
/** |
|
87 |
* Get a statement suitable to delete a given object from the database |
|
88 |
* @param c the database connection to use for the delete |
|
89 |
* @param record the object to delete |
|
90 |
* @return the delete statement |
|
91 |
* @throws Exception |
|
92 |
*/ |
|
93 |
public PreparedStatement getDeleteStatment(Connection c, Object record) |
|
94 |
throws Exception; |
|
95 |
} |