@@ -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 (Id id );
250255
251256 /**
252257 * Obtiene el id del modelo
0 commit comments