Dieser Commit ist enthalten in:
Ursprung
bd626bb4e6
Commit
e9a39d007d
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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) {
|
||||||
|
@ -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) {
|
||||||
|
@ -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 {
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
closeConnection(connection);
|
|
||||||
throw new SecurityException("Could not test connection validity", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (connections) {
|
synchronized (connections) {
|
||||||
connections.push(connection);
|
connections.push(connection);
|
||||||
connections.notify();
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
|
if(o != null)
|
||||||
SqlTypeMapper.getMapper(o.getClass()).write(st, i+1, o);
|
SqlTypeMapper.getMapper(o.getClass()).write(st, i+1, o);
|
||||||
|
else
|
||||||
|
st.setNull(i+1, Types.NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return runnable.run(st);
|
return runnable.run(st);
|
||||||
|
@ -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() {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren