/** * Create a new prepared statement for further use. * * @param sql * @param language * @return x * @throws MException */ public DbPrepared createStatement(String sql, String language) throws MException { return new DbPrepared(this, sql, language); }
/** * <p>deleteObject.</p> * * @param con a {@link de.mhus.lib.sql.DbConnection} object. * @param object a {@link java.lang.Object} object. * @throws java.lang.Exception if any. */ public void deleteObject(DbConnection con, Object object) throws Exception { for (Feature f : features) f.deleteObject(con,object); HashMap<String, Object> attributes = new HashMap<String, Object>(); for (Field f : pk) { attributes.put(f.name, f.getFromTarget(object)); } schema.internalDeleteObject(con, name, object, attributes); sqlDelete.getStatement(con).execute(attributes); }
/** * <p>existsObject.</p> * * @param con a {@link de.mhus.lib.sql.DbConnection} object. * @param keys an array of {@link java.lang.Object} objects. * @return a boolean. * @throws java.lang.Exception if any. */ public boolean existsObject(DbConnection con, Object[] keys) throws Exception { HashMap<String, Object> attributes = new HashMap<String, Object>(); int nr = 0; for (Object key : keys) { attributes.put(String.valueOf(nr), key); nr++; } DbResult ret = sqlPrimary.getStatement(con).executeQuery(attributes); if (!ret.next()) { ret.close(); return false; } ret.close(); return true; }
int c = query.getStatement(con).executeUpdate(attributes); if ( c != 1) throw new MException("update failed, updated objects " + c);
public DbPrepared getStatement(String name) throws MException { String[] query = provider.getQuery(name); return new DbPrepared(this, query[1], query[0]); }
/** * <p>createObject.</p> * * @param con a {@link de.mhus.lib.sql.DbConnection} object. * @param object a {@link java.lang.Object} object. * @throws java.lang.Exception if any. */ public void createObject(DbConnection con, Object object) throws Exception { for (Feature f : features) f.preCreateObject(con,object); HashMap<String, Object> attributes = new HashMap<String, Object>(); for (Field f : fList) { attributes.put(f.name, f.getFromTarget(object)); } schema.internalCreateObject(con, name, object, attributes); sqlInsert.getStatement(con).execute(attributes); for (Feature f : features) f.postCreateObject(con,object); for (FieldRelation f : relationList) { f.created(con,object); } }
nr++; DbResult ret = sqlPrimary.getStatement(con).executeQuery(attributes); if (!ret.next()) { ret.close();
/** * <p>saveObject.</p> * * @param con a {@link de.mhus.lib.sql.DbConnection} object. * @param object a {@link java.lang.Object} object. * @throws java.lang.Exception if any. */ public void saveObject(DbConnection con, Object object) throws Exception { for (Feature f : features) f.preSaveObject(con,object); HashMap<String, Object> attributes = new HashMap<String, Object>(); for (Field f : fList) { attributes.put(f.name, f.getFromTarget(object)); } for (FieldRelation f : relationList) { f.prepareSave(con,object); } schema.internalSaveObject(con, name, object, attributes); int c = sqlUpdate.getStatement(con).executeUpdate(attributes); if ( c != 1) throw new MException("update failed, updated objects " + c); for (Feature f : features) f.postSaveObject(con,object); for (FieldRelation f : relationList) { f.saved(con,object); } }
nr++; DbResult ret = sqlPrimary.getStatement(con).executeQuery(attributes); if (!ret.next()) { ret.close();
int c = sqlUpdateForce.getStatement(con).executeUpdate(attributes); if ( c != 1) throw new MException("update failed, updated objects " + c);
nr++; DbResult ret = sqlPrimary.getStatement(con).executeQuery(attributes); if (!ret.next()) { ret.close();