1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Projection_Planning/src/main/java/DB/Table.java
2021-01-05 15:58:57 +01:00

54 lines
1.6 KiB
Java

package DB;
import Exceptions.AlreadyOnTable;
import Exceptions.NotFoundInTable;
import java.util.Map;
public abstract class Table {
final protected String tableName;
final protected String check;
final protected String checkValue;
protected Table(String tableName, String check, String checkValue) throws NotFoundInTable {
this.tableName = tableName;
this.check = check;
this.checkValue = checkValue;
if (!exist())
throw new NotFoundInTable(this.tableName);
}
protected Table(String tableName, String check, String checkValue, Map<String, String> values) throws AlreadyOnTable {
this.tableName = tableName;
this.check = check;
this.checkValue = checkValue;
DB.create(this.getClass(), this.tableName, this.check, values);
}
protected Table(String tableName, String check, Map<String, String> values) {
this.tableName = tableName;
this.check = check;
this.checkValue = DB.create(this.getClass(), this.tableName, values);
}
protected <T> T get(Class<T> cl, String value) {
return DB.get(cl, tableName, value, check, checkValue);
}
protected boolean set(String value, String newValue) {
return DB.set(tableName, value, newValue, check, checkValue);
}
public boolean exist() {
return DB.exist(tableName, check, checkValue);
}
public boolean delete() {
return DB.delete(tableName, check, checkValue);
}
@Override
public String toString() {
return checkValue;
}
}