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 SelectStatement<NodeMember> getNodeMember = table.select(Table.PRIMARY);
private static final SelectStatement<NodeMember> getNodeMembers = table.selectFields("Node");
private static final SelectStatement<NodeMember> getSchematics = table.selectFields("Member");
private static final SelectStatement<NodeMember> getNodeMembers = table.selectFields("NodeId");
private static final SelectStatement<NodeMember> getSchematics = table.selectFields("UserId");
private static final Statement create = table.insertAll();
private static final Statement delete = table.delete(Table.PRIMARY);
@ -47,11 +47,11 @@ public class NodeMember {
@Field(keys = {Table.PRIMARY})
private final int userId;
public int getNodeId() {
public int getNode() {
return nodeId;
}
public int getUserId() {
public int getMember() {
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) {
if (parent != null && parent == 0)
parent = null;
int nodeId = create.insertGetKey(owner, name, parent, type, item);
int nodeId = create.insertGetKey(owner, name, parent, item, type);
return getSchematicNode(nodeId);
}
@ -447,7 +447,7 @@ public class SchematicNode {
private void updateDB() {
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();
TAB_CACHE.clear();
}
@ -480,7 +480,7 @@ public class SchematicNode {
final Set<NodeMember> nodeMembers = NodeMember.getSchematics(user.getId());
AtomicInteger i = new AtomicInteger();
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();
i.set(currentNode.getId());
builder.insert(0, split)

Datei anzeigen

@ -47,7 +47,8 @@ public class UserConfig {
}
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) {

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.sql.internal;
import java.io.InputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -63,6 +64,7 @@ public final class SqlTypeMapper<T> {
primitiveMapper(double.class, Double.class, "REAL", ResultSet::getDouble, PreparedStatement::setDouble);
new SqlTypeMapper<>(String.class, "TEXT", ResultSet::getString, PreparedStatement::setString);
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) {

Datei anzeigen

@ -122,7 +122,6 @@ public class Statement implements AutoCloseable {
}
public Statement(String sql, boolean returnGeneratedKeys) {
System.out.println(sql);
this.sql = sql;
this.returnGeneratedKeys = returnGeneratedKeys;
synchronized (statements) {
@ -159,34 +158,35 @@ public class Statement implements AutoCloseable {
private <T> T withConnection(SQLRunnable<T> runnable, Object... objects) {
Connection connection = aquireConnection();
T result;
try {
result = tryWithConnection(connection, runnable, objects);
} catch (SQLException e) {
try {
if(connection.isClosed() || !connection.isValid(1)) {
return tryWithConnection(connection, runnable, objects);
} finally {
if(connectionInvalid(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);
}
synchronized (connections) {
connections.push(connection);
connections.notify();
} catch (SQLException e) {
if(connectionInvalid(connection)) {
return withConnection(runnable, objects);
} else {
throw new SecurityException("Failing sql statement", e);
}
throw new SecurityException("Failing sql statement", e);
}
}
synchronized (connections) {
connections.push(connection);
connections.notify();
private boolean connectionInvalid(Connection connection) {
try {
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 {
@ -201,7 +201,10 @@ public class Statement implements AutoCloseable {
for (int i = 0; i < objects.length; 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);

Datei anzeigen

@ -75,7 +75,7 @@ public class Table<T> {
}
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) {
@ -100,7 +100,7 @@ public class Table<T> {
}
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() {