> {
* @param the table class of the primary key targeted by the specified foreign key field
* @return the element in the table P that his primary key correspond to the foreign key value of this element.
*/
- public > P getReferencedEntry(SQLFKField field) throws ORMException {
+ public > P getReferencedEntry(SQLFKField field) throws DBException {
T fkValue = get(field);
if (fkValue == null) return null;
- return ORM.getFirst(field.getForeignElementClass(), field.getPrimaryField().eq(fkValue), null);
+ return DB.getFirst(field.getForeignElementClass(), field.getPrimaryField().eq(fkValue), null);
}
/**
@@ -202,10 +202,10 @@ public abstract class SQLElement> {
* @param the table class of the foreign key that reference a primary key of this element.
* @return all elements in the table F for which the specified foreign key value correspond to the primary key of this element.
*/
- public > SQLElementList getReferencingForeignEntries(SQLFKField field, SQLOrderBy orderBy, Integer limit, Integer offset) throws ORMException {
+ public > SQLElementList getReferencingForeignEntries(SQLFKField field, SQLOrderBy orderBy, Integer limit, Integer offset) throws DBException {
T value = get(field.getPrimaryField());
if (value == null) return new SQLElementList<>();
- return ORM.getAll(field.getSQLElementType(), field.eq(value), orderBy, limit, offset);
+ return DB.getAll(field.getSQLElementType(), field.eq(value), orderBy, limit, offset);
}
public boolean isValidForSave() {
@@ -225,11 +225,11 @@ public abstract class SQLElement> {
}
@SuppressWarnings("unchecked")
- public E save() throws ORMException {
+ public E save() throws DBException {
if (!isValidForSave())
throw new IllegalStateException(toString() + " has at least one undefined value and can't be saved.");
- ORM.initTable((Class)getClass());
+ DB.initTable((Class)getClass());
try {
if (stored) { // mettre à jour les valeurs dans la base
@@ -243,7 +243,7 @@ public abstract class SQLElement> {
if (modifiedValues.isEmpty()) return (E) this;
- ORM.update((Class)getClass(), getFieldId().eq(getId()), modifiedValues);
+ DB.update((Class)getClass(), getFieldId().eq(getId()), modifiedValues);
}
else { // ajouter dans la base
@@ -268,7 +268,7 @@ public abstract class SQLElement> {
}
try (PreparedStatement ps = db.getNativeConnection().prepareStatement(
- "INSERT INTO " + tableName() + " (" + concat_fields + ") VALUES (" + concat_vals + ")",
+ "INSERT INTO " + DB.tablePrefix + tableName() + " (" + concat_fields + ") VALUES (" + concat_vals + ")",
Statement.RETURN_GENERATED_KEYS)) {
int i = 1;
@@ -287,19 +287,19 @@ public abstract class SQLElement> {
modifiedSinceLastSave.clear();
} catch (SQLException e) {
- throw new ORMException("Error while saving data", e);
+ throw new DBException("Error while saving data", e);
}
return (E) this;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- protected static > void addValueToSQLObjectList(List