Current state
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-11-15 18:40:48 +01:00
Ursprung bd626bb4e6
Commit e9a39d007d
6 geänderte Dateien mit 37 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -37,8 +37,8 @@ public class NodeMember {
private static final Table<NodeMember> table = new Table<>(NodeMember.class); private static final Table<NodeMember> table = new Table<>(NodeMember.class);
private static final SelectStatement<NodeMember> getNodeMember = table.select(Table.PRIMARY); private static final SelectStatement<NodeMember> getNodeMember = table.select(Table.PRIMARY);
private static final SelectStatement<NodeMember> getNodeMembers = table.selectFields("Node"); private static final SelectStatement<NodeMember> getNodeMembers = table.selectFields("NodeId");
private static final SelectStatement<NodeMember> getSchematics = table.selectFields("Member"); private static final SelectStatement<NodeMember> getSchematics = table.selectFields("UserId");
private static final Statement create = table.insertAll(); private static final Statement create = table.insertAll();
private static final Statement delete = table.delete(Table.PRIMARY); private static final Statement delete = table.delete(Table.PRIMARY);
@ -47,11 +47,11 @@ public class NodeMember {
@Field(keys = {Table.PRIMARY}) @Field(keys = {Table.PRIMARY})
private final int userId; private final int userId;
public int getNodeId() { public int getNode() {
return nodeId; return nodeId;
} }
public int getUserId() { public int getMember() {
return userId; return userId;
} }

Datei anzeigen

@ -139,7 +139,7 @@ public class SchematicNode {
public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) { public static SchematicNode createSchematicNode(int owner, String name, Integer parent, String type, String item) {
if (parent != null && parent == 0) if (parent != null && parent == 0)
parent = null; parent = null;
int nodeId = create.insertGetKey(owner, name, parent, type, item); int nodeId = create.insertGetKey(owner, name, parent, item, type);
return getSchematicNode(nodeId); return getSchematicNode(nodeId);
} }
@ -447,7 +447,7 @@ public class SchematicNode {
private void updateDB() { private void updateDB() {
this.lastUpdate = Timestamp.from(Instant.now()); this.lastUpdate = Timestamp.from(Instant.now());
update.update(nodeId, nodeOwner, nodeName, parentNode, nodeItem, nodeType, lastUpdate, nodeRank, replaceColor, allowReplay, nodeFormat); update.update(nodeId, nodeOwner, nodeName, parentNode, lastUpdate, nodeItem, nodeType, nodeRank, replaceColor, allowReplay, nodeFormat);
this.brCache.clear(); this.brCache.clear();
TAB_CACHE.clear(); TAB_CACHE.clear();
} }
@ -480,7 +480,7 @@ public class SchematicNode {
final Set<NodeMember> nodeMembers = NodeMember.getSchematics(user.getId()); final Set<NodeMember> nodeMembers = NodeMember.getSchematics(user.getId());
AtomicInteger i = new AtomicInteger(); AtomicInteger i = new AtomicInteger();
i.set(currentNode.getId()); i.set(currentNode.getId());
while (currentNode.getParentNode() != null && nodeMembers.stream().noneMatch(nodeMember -> nodeMember.getNodeId() == i.get())) { while (currentNode.getParentNode() != null && nodeMembers.stream().noneMatch(nodeMember -> nodeMember.getNode() == i.get())) {
currentNode = currentNode.getParentNode(); currentNode = currentNode.getParentNode();
i.set(currentNode.getId()); i.set(currentNode.getId());
builder.insert(0, split) builder.insert(0, split)

Datei anzeigen

@ -47,7 +47,8 @@ public class UserConfig {
} }
public static String getConfig(int player, String config) { public static String getConfig(int player, String config) {
return select.select(player, config).value; UserConfig value = select.select(player, config);
return value != null ? value.value : null;
} }
public static void updatePlayerConfig(UUID uuid, String config, String value) { public static void updatePlayerConfig(UUID uuid, String config, String value) {

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.sql.internal; package de.steamwar.sql.internal;
import java.io.InputStream;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -63,6 +64,7 @@ public final class SqlTypeMapper<T> {
primitiveMapper(double.class, Double.class, "REAL", ResultSet::getDouble, PreparedStatement::setDouble); primitiveMapper(double.class, Double.class, "REAL", ResultSet::getDouble, PreparedStatement::setDouble);
new SqlTypeMapper<>(String.class, "TEXT", ResultSet::getString, PreparedStatement::setString); new SqlTypeMapper<>(String.class, "TEXT", ResultSet::getString, PreparedStatement::setString);
new SqlTypeMapper<>(Timestamp.class, "TIMESTAMP", ResultSet::getTimestamp, PreparedStatement::setTimestamp); new SqlTypeMapper<>(Timestamp.class, "TIMESTAMP", ResultSet::getTimestamp, PreparedStatement::setTimestamp);
new SqlTypeMapper<>(InputStream.class, "BLOB", ResultSet::getBinaryStream, PreparedStatement::setBinaryStream);
} }
private static <T> void primitiveMapper(Class<T> primitive, Class<T> wrapped, String sqlType, SQLReader<T> reader, SQLWriter<T> writer) { private static <T> void primitiveMapper(Class<T> primitive, Class<T> wrapped, String sqlType, SQLReader<T> reader, SQLWriter<T> writer) {

Datei anzeigen

@ -122,7 +122,6 @@ public class Statement implements AutoCloseable {
} }
public Statement(String sql, boolean returnGeneratedKeys) { public Statement(String sql, boolean returnGeneratedKeys) {
System.out.println(sql);
this.sql = sql; this.sql = sql;
this.returnGeneratedKeys = returnGeneratedKeys; this.returnGeneratedKeys = returnGeneratedKeys;
synchronized (statements) { synchronized (statements) {
@ -159,34 +158,35 @@ public class Statement implements AutoCloseable {
private <T> T withConnection(SQLRunnable<T> runnable, Object... objects) { private <T> T withConnection(SQLRunnable<T> runnable, Object... objects) {
Connection connection = aquireConnection(); Connection connection = aquireConnection();
T result;
try { try {
result = tryWithConnection(connection, runnable, objects);
} catch (SQLException e) {
try { try {
if(connection.isClosed() || !connection.isValid(1)) { return tryWithConnection(connection, runnable, objects);
} finally {
if(connectionInvalid(connection)) {
closeConnection(connection); closeConnection(connection);
return withConnection(runnable, objects); } else {
synchronized (connections) {
connections.push(connection);
connections.notify();
}
} }
} catch (SQLException ex) {
closeConnection(connection);
throw new SecurityException("Could not test connection validity", ex);
} }
} catch (SQLException e) {
synchronized (connections) { if(connectionInvalid(connection)) {
connections.push(connection); return withConnection(runnable, objects);
connections.notify(); } else {
throw new SecurityException("Failing sql statement", e);
} }
throw new SecurityException("Failing sql statement", e);
} }
}
synchronized (connections) { private boolean connectionInvalid(Connection connection) {
connections.push(connection); try {
connections.notify(); return connection.isClosed();
} catch (SQLException e) {
logger.log(Level.INFO, "Could not check SQL connection status", e); // No database logging possible at this state
return true;
} }
return result;
} }
private <T> T tryWithConnection(Connection connection, SQLRunnable<T> runnable, Object... objects) throws SQLException { private <T> T tryWithConnection(Connection connection, SQLRunnable<T> runnable, Object... objects) throws SQLException {
@ -201,7 +201,10 @@ public class Statement implements AutoCloseable {
for (int i = 0; i < objects.length; i++) { for (int i = 0; i < objects.length; i++) {
Object o = objects[i]; Object o = objects[i];
SqlTypeMapper.getMapper(o.getClass()).write(st, i+1, o); if(o != null)
SqlTypeMapper.getMapper(o.getClass()).write(st, i+1, o);
else
st.setNull(i+1, Types.NULL);
} }
return runnable.run(st); return runnable.run(st);

Datei anzeigen

@ -75,7 +75,7 @@ public class Table<T> {
} }
public Statement updateFields(String[] fields, String... kfields) { public Statement updateFields(String[] fields, String... kfields) {
return new Statement("UPDATE " + name + " SET " + Arrays.stream(fields).map(f -> f + " = ?").collect(Collectors.joining(", ")) + " WHERE " + Arrays.stream(kfields).map(f -> f + " = ?").collect(Collectors.joining(", "))); return new Statement("UPDATE " + name + " SET " + Arrays.stream(fields).map(f -> f + " = ?").collect(Collectors.joining(", ")) + " WHERE " + Arrays.stream(kfields).map(f -> f + " = ?").collect(Collectors.joining(" AND ")));
} }
public Statement insert(String name) { public Statement insert(String name) {
@ -100,7 +100,7 @@ public class Table<T> {
} }
public Statement deleteFields(String... kfields) { public Statement deleteFields(String... kfields) {
return new Statement("DELETE FROM " + name + " WHERE " + Arrays.stream(kfields).map(f -> f + " = ?").collect(Collectors.joining(", "))); return new Statement("DELETE FROM " + name + " WHERE " + Arrays.stream(kfields).map(f -> f + " = ?").collect(Collectors.joining(" AND ")));
} }
void ensureExistanceInSqlite() { void ensureExistanceInSqlite() {