
api.sql.SQLDatabaseConnection Maven / Gradle / Ivy
package api.sql;
import api.Column;
import api.DatabaseConnection;
import api.Table;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
/**
* A connection to SQL databases
*/
public interface SQLDatabaseConnection extends DatabaseConnection {
class Row {
private final Map columnValues;
public Row(Map columnValues) {
assert columnValues != null;
this.columnValues = columnValues;
}
public Optional get(Column column){
assert column != null;
if (!columnValues.containsKey(column)){
return Optional.empty();
}
return Optional.of(columnValues.get(column));
}
public Set getColumns(){
return columnValues.keySet();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Row row = (Row) o;
return columnValues.equals(row.columnValues);
}
@Override
public int hashCode() {
return Objects.hash(columnValues);
}
@Override
public String toString() {
return "Row{" +
"columnValues=" + columnValues +
'}';
}
}
/**
* Inserts a row into the table.
* @param table Table where to insert the row
* @param row The row to be inserted into the table
*/
void insert(Table table, Row row);
/**
* Reads all data from a table.
* @param table Table to read the data from.
* @return The data of the table
*/
Stream readTable(Table table);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy