Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8430e5d

Browse files
author
JesusBetaX
committed
init 9
1 parent b909fcd commit 8430e5d

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

‎src/com/jx/library/Dao.java‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public abstract class Dao<Model, Id> {
2424
* @throws SQLException
2525
*/
2626
public Model findById(Id id) throws SQLException {
27-
String sql = "SELECT * FROM " + getTableName() + " WHERE " + whereClause();
27+
String sql = "SELECT * FROM " + getTableName() + " WHERE " + whereClause(id);
2828
return findById(sql, id);
2929
}
3030

@@ -106,7 +106,7 @@ public long count() throws SQLException {
106106
* @throws SQLException
107107
*/
108108
public long count(Id id) throws SQLException {
109-
return getDataBase().count(getTableName(), whereClause(), id);
109+
return getDataBase().count(getTableName(), whereClause(id), id);
110110
}
111111

112112
/**
@@ -136,8 +136,9 @@ public boolean update(Model m) throws SQLException {
136136
if (values.isEmpty()) {
137137
return Boolean.FALSE;
138138
}
139+
Id id = getId(m);
139140
return getDataBase().update(getTableName(), values,
140-
whereClause(), getId(m)) == 1;
141+
whereClause(id), id) == 1;
141142
}
142143

143144
/**
@@ -186,7 +187,7 @@ public boolean delete(Model m) throws SQLException {
186187
*/
187188
public boolean deleteById(Id id) throws SQLException {
188189
return getDataBase().delete(getTableName(),
189-
whereClause(), id) == 1;
190+
whereClause(id), id) == 1;
190191
}
191192

192193
/**
@@ -243,10 +244,14 @@ protected Map<String, Object> onWrite(Model m) {
243244
*/
244245
protected abstract Model onRead(ResultSet rs) throws SQLException;
245246

246-
/**
247+
/**
248+
* Condición where.
249+
*
250+
* @param id del modelo
251+
*
247252
* @return condicion WHERE para editar, borrar y buscar un registro.
248253
*/
249-
protected abstract String whereClause();
254+
protected abstract String whereClause(Idid);
250255

251256
/**
252257
* Obtiene el id del modelo

‎src/com/jx/model/ProductoDao.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected Producto onRead(ResultSet rs) throws SQLException {
5454
/**
5555
* Al guardar un registro en la base de datos.
5656
*
57-
* @param modelo donde estan los datos a guardar
57+
* @param m modelo donde estan los datos a guardar
5858
*
5959
* @return valores del query
6060
*/
@@ -66,11 +66,13 @@ protected Map<String, Object> onWrite(Producto m) {
6666
return values;
6767
}
6868

69-
/**
69+
/**
70+
* @param id del modelo
71+
*
7072
* @return condicion WHERE para editar, borrar y buscar un registro.
7173
*/
7274
@Override
73-
protected String whereClause() {
75+
protected String whereClause(Longid) {
7476
return "id = ?";
7577
}
7678

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /