Merge pull request 'Add SchematicNode.java to Standalone' (#166) from standalone_schematicsystem into standalone
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #166
Dieser Commit ist enthalten in:
Commit
f4e90146fe
@ -21,6 +21,7 @@ package de.steamwar.sql;
|
|||||||
|
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -80,4 +81,24 @@ public interface Provider {
|
|||||||
String getConfig(int player, String config);
|
String getConfig(int player, String config);
|
||||||
void updatePlayerConfig(int id, String config, String value);
|
void updatePlayerConfig(int id, String config, String value);
|
||||||
void removePlayerConfig(int id, String config);
|
void removePlayerConfig(int id, String config);
|
||||||
|
|
||||||
|
void createSchematicNode(int owner, String name, Integer parent, String type, String item);
|
||||||
|
SchematicNode getSchematicNode(int owner, String name, Integer parent);
|
||||||
|
List<SchematicNode> getSchematicNodeInNode(Integer parent);
|
||||||
|
List<SchematicNode> getSchematicDirectoryInNode(Integer parent);
|
||||||
|
SchematicNode getSchematicDirectory(String name, Integer parent);
|
||||||
|
SchematicNode getSchematicNode(String name, Integer parent);
|
||||||
|
SchematicNode getSchematicNode(int id);
|
||||||
|
List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent);
|
||||||
|
List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType);
|
||||||
|
List<SchematicNode> getAllSchematicsOfType(int owner, String schemType);
|
||||||
|
List<SchematicNode> getAllSchematicsOfType(String schemType);
|
||||||
|
List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent);
|
||||||
|
List<SchematicNode> getAllSchematicsAccessibleByUser(int user);
|
||||||
|
List<SchematicNode> getAllParentsOfNode(int node);
|
||||||
|
Integer countNodes();
|
||||||
|
void updateSchematicNode(SchematicNode node);
|
||||||
|
void deleteSchematicNode(SchematicNode node);
|
||||||
|
InputStream getSchematicData(SchematicNode node) throws IOException;
|
||||||
|
void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat);
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.sql;
|
package de.steamwar.sql;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.sql.Blob;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
public class SQLProvider implements Provider {
|
public class SQLProvider implements Provider {
|
||||||
|
|
||||||
@ -354,4 +357,249 @@ public class SQLProvider implements Provider {
|
|||||||
public void removePlayerConfig(int id, String config) {
|
public void removePlayerConfig(int id, String config) {
|
||||||
deleteConfig.update(id, config);
|
deleteConfig.update(id, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Statement createNode = new Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)");
|
||||||
|
private static final Statement getSchematicNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
|
||||||
|
private static final Statement getSchematicNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
|
||||||
|
private static final Statement getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getDirsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName");
|
||||||
|
private static final Statement getDirsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicDirectory_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicNodeO_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ");
|
||||||
|
private static final Statement getSchematicNodeO = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getSchematicNodeId = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?");
|
||||||
|
private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName");
|
||||||
|
private static final Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName");
|
||||||
|
private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName");
|
||||||
|
private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
||||||
|
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
|
||||||
|
private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
||||||
|
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
||||||
|
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?");
|
||||||
|
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
||||||
|
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
||||||
|
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
||||||
|
|
||||||
|
private static final Statement.ResultSetUser<List<SchematicNode>> toSchematicList = rs -> {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
nodes.add(nodeFromResultSet(rs));
|
||||||
|
}
|
||||||
|
return nodes;
|
||||||
|
};
|
||||||
|
private static final Statement.ResultSetUser<SchematicNode> toSchematicNode = rs -> {
|
||||||
|
if (rs.next()) {
|
||||||
|
return nodeFromResultSet(rs);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
private static SchematicNode nodeFromResultSet(ResultSet set) throws SQLException {
|
||||||
|
Integer parent = set.getInt("ParentNode");
|
||||||
|
if(set.wasNull()) {
|
||||||
|
parent = null;
|
||||||
|
}
|
||||||
|
String type = set.getString("NodeType");
|
||||||
|
boolean isDir = true;
|
||||||
|
Integer rank = null;
|
||||||
|
boolean schemFormat = false;
|
||||||
|
if (type != null) {
|
||||||
|
isDir = false;
|
||||||
|
rank = set.getInt("NodeRank");
|
||||||
|
schemFormat = set.getBoolean("NodeFormat");
|
||||||
|
}
|
||||||
|
return new SchematicNode(
|
||||||
|
set.getInt("NodeId"),
|
||||||
|
set.getInt("NodeOwner"),
|
||||||
|
set.getString("NodeName"),
|
||||||
|
parent,
|
||||||
|
set.getString("NodeItem"),
|
||||||
|
type,
|
||||||
|
isDir,
|
||||||
|
rank,
|
||||||
|
set.getTimestamp("LastUpdate"),
|
||||||
|
schemFormat
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createSchematicNode(int owner, String name, Integer parent, String type, String item) {
|
||||||
|
createNode.update(owner, name, parent, type, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||||
|
|
||||||
|
if(parent == null) {
|
||||||
|
return getSchematicNode_Null.select(toSchematicNode, owner, name);
|
||||||
|
} else {
|
||||||
|
return getSchematicNode.select(toSchematicNode, owner, name, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||||
|
if(parent == null) {
|
||||||
|
return getSchematicsInNode_Null.select(toSchematicList);
|
||||||
|
}else {
|
||||||
|
return getSchematicsInNode.select(toSchematicList, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||||
|
if(parent == null) {
|
||||||
|
return getDirsInNode_Null.select(toSchematicList);
|
||||||
|
}else {
|
||||||
|
return getDirsInNode.select(toSchematicList, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||||
|
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
||||||
|
while (rs.next()) {
|
||||||
|
SchematicNode node = nodeFromResultSet(rs);
|
||||||
|
if(node.isDir())
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
if(parent == null) {
|
||||||
|
return getSchematicDirectory_Null.select(user, name);
|
||||||
|
}else {
|
||||||
|
return getSchematicDirectory.select(user, name, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(String name, Integer parent) {
|
||||||
|
if(parent == null) {
|
||||||
|
return getSchematicNodeO_Null.select(toSchematicNode, name);
|
||||||
|
}else {
|
||||||
|
return getSchematicNodeO.select(toSchematicNode, name, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(int id) {
|
||||||
|
return getSchematicNodeId.select(rs -> {
|
||||||
|
if (!rs.next())
|
||||||
|
return null;
|
||||||
|
return nodeFromResultSet(rs);
|
||||||
|
}, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
||||||
|
if(parent == null || parent == 0) {
|
||||||
|
return getAccessibleByUserByTypeInNode_Null.select(toSchematicList, owner, owner, schemType);
|
||||||
|
} else {
|
||||||
|
return getAccessibleByUserByTypeInNode.select(toSchematicList, owner, owner, schemType, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
||||||
|
return getAccessibleByUserByType.select(toSchematicList, user, user, schemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||||
|
return getAllSchemsOfTypeOwner.select(toSchematicList, owner, schemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||||
|
return getAllSchemsOfType.select(toSchematicList, schemType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||||
|
if (parent != null && parent != 0) {
|
||||||
|
if(Boolean.TRUE.equals(isSchematicAccessibleForUser.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
return rs.getInt("Accessible") > 0;
|
||||||
|
}, parent, user, user))) {
|
||||||
|
return getSchematicNodeInNode(parent);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return getAccessibleByUser.select(rs -> {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
nodes.add(nodeFromResultSet(rs));
|
||||||
|
return nodes;
|
||||||
|
}, user, user, user, user);
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||||
|
return getAllSchematicsAccessibleByUser.select(toSchematicList, user, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
|
return getAllParentsOfNode.select(toSchematicList, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer countNodes() {
|
||||||
|
return countNodes.select(rs -> {
|
||||||
|
if (rs.next()) {
|
||||||
|
return rs.getInt("count");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSchematicNode(SchematicNode node) {
|
||||||
|
updateDB.update(
|
||||||
|
node.getName(),
|
||||||
|
node.getOwner(),
|
||||||
|
node.getParent(),
|
||||||
|
node.getItem(),
|
||||||
|
node.getType(),
|
||||||
|
node.getRank(),
|
||||||
|
node.getId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteSchematicNode(SchematicNode node) {
|
||||||
|
deleteNode.update(node.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getSchematicData(SchematicNode node) throws IOException {
|
||||||
|
try {
|
||||||
|
return selSchemData.select(rs -> {
|
||||||
|
rs.next();
|
||||||
|
Blob schemData = rs.getBlob("NodeData");
|
||||||
|
if(schemData == null) {
|
||||||
|
throw new SecurityException("SchemData is null");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new GZIPInputStream(schemData.getBinaryStream());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException("SchemData is wrong", e);
|
||||||
|
}
|
||||||
|
}, node.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat) {
|
||||||
|
updateDatabase.update(blob, newFormat, node.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,33 +39,6 @@ import java.util.zip.GZIPInputStream;
|
|||||||
|
|
||||||
public class SchematicNode {
|
public class SchematicNode {
|
||||||
|
|
||||||
private static final Statement createNode = new Statement("INSERT INTO SchematicNode (NodeName, NodeOwner, ParentNode, NodeType, NodeItem) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE NodeName = VALUES(NodeName), ParentNode = VALUES(ParentNode), NodeItem = VALUES(NodeItem), NodeType = VALUES(NodeType), NodeItem = VALUES(NodeItem)");
|
|
||||||
private static final Statement getSchematicNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode is NULL");
|
|
||||||
private static final Statement getSchematicNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeName = ? AND ParentNode = ?");
|
|
||||||
private static final Statement getSchematicsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getDirsInNode_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode is NULL AND NodeType is NULL ORDER BY NodeName");
|
|
||||||
private static final Statement getDirsInNode = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE ParentNode = ? AND NodeType is NULL ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicDirectory_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicDirectory = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicNodeO_Null = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode is NULL ");
|
|
||||||
private static final Statement getSchematicNodeO = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeName = ? AND ParentNode = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getSchematicNodeId = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ?");
|
|
||||||
private static final Statement getAllSchemsOfTypeOwner = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeOwner = ? AND NodeType = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getAllSchemsOfType = new Statement("SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeType = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getAccessibleByUser = new Statement("SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) AND ((s.NodeOwner = ? AND s.ParentNode IS NULL) OR NOT s.NodeOwner = ?) GROUP BY s.NodeId ORDER BY s.NodeName");
|
|
||||||
private static final Statement getAccessibleByUserByTypeInNode = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getAccessibleByUserByTypeInNode_Null = new Statement("WITH RECURSIVE RSNB AS (WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSNB WHERE SN.NodeId = RSNB.ParentNode)SELECT * FROM RSNB WHERE ParentNode is null ORDER BY NodeName");
|
|
||||||
private static final Statement getAccessibleByUserByType = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN WHERE NodeType = ? ORDER BY NodeName");
|
|
||||||
private static final Statement getAllSchematicsAccessibleByUser = new Statement("WITH RECURSIVE RSN as (SELECT s.NodeId, s.NodeName, s.NodeOwner, s.NodeItem, s.NodeType, s.ParentNode, s.NodeRank, s.NodeFormat, s.LastUpdate FROM SchematicNode s LEFT JOIN NodeMember n ON s.NodeId = n.NodeId WHERE (s.NodeOwner = ? OR n.UserId = ?) GROUP BY s.NodeId union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.NodeItem, SN.NodeType, SN.ParentNode, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode AS SN, RSN WHERE SN.ParentNode = RSN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
|
||||||
private static final Statement isSchematicAccessibleForUser = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? union select SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT COUNT(RSN.NodeId) AS `Accessible` FROM RSN LEFT Join NodeMember NM On NM.NodeId = RSN.NodeId WHERE NodeOwner = ? OR UserId = ? LIMIT 1");
|
|
||||||
private static final Statement getAllParentsOfNode = new Statement("WITH RECURSIVE RSN AS (SELECT NodeId, NodeName, NodeOwner, ParentNode, NodeType, NodeItem, NodeRank, NodeFormat, LastUpdate FROM SchematicNode WHERE NodeId = ? UNION SELECT SN.NodeId, SN.NodeName, SN.NodeOwner, SN.ParentNode, SN.NodeType, SN.NodeItem, SN.NodeRank, SN.NodeFormat, SN.LastUpdate FROM SchematicNode SN, RSN WHERE RSN.ParentNode = SN.NodeId) SELECT * FROM RSN ORDER BY NodeName");
|
|
||||||
private static final Statement countNodes = new Statement("SELECT COUNT(NodeId) AS 'count' FROM SchematicNode");
|
|
||||||
private static final Statement updateDB = new Statement("UPDATE SchematicNode SET NodeName = ?, NodeOwner = ?, ParentNode = ?, NodeItem = ?, NodeType = ?, NodeRank = ? WHERE NodeId = ?");
|
|
||||||
private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?");
|
|
||||||
private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?");
|
|
||||||
private static final Statement deleteNode = new Statement("DELETE FROM SchematicNode WHERE NodeId = ?");
|
|
||||||
|
|
||||||
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
public static SchematicNode createSchematic(int owner, String name, Integer parent) {
|
||||||
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
|
||||||
}
|
}
|
||||||
@ -77,7 +50,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;
|
||||||
createNode.update(name, owner, parent, type, item);
|
Provider.impl.createSchematicNode(owner, name, parent, type, item);
|
||||||
return getSchematicNode(owner, name, parent);
|
return getSchematicNode(owner, name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,23 +58,29 @@ public class SchematicNode {
|
|||||||
return getSchematicNode(owner, name, parent.getId());
|
return getSchematicNode(owner, name, parent.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SchematicNode(ResultSet set) throws SQLException {
|
public SchematicNode(
|
||||||
id = set.getInt("NodeId");
|
int id,
|
||||||
owner = set.getInt("NodeOwner");
|
int owner,
|
||||||
name = set.getString("NodeName");
|
String name,
|
||||||
parent = set.getInt("ParentNode");
|
Integer parent,
|
||||||
if(set.wasNull()) {
|
String item,
|
||||||
parent = null;
|
String type,
|
||||||
}
|
boolean isDir,
|
||||||
item = set.getString("NodeItem");
|
int rank,
|
||||||
type = set.getString("NodeType");
|
Timestamp lastUpdate,
|
||||||
lastUpdate = set.getTimestamp("LastUpdate");
|
boolean schemFormat
|
||||||
if (type != null) {
|
) {
|
||||||
isDir = false;
|
this.id = id;
|
||||||
rank = set.getInt("NodeRank");
|
this.owner = owner;
|
||||||
schemFormat = set.getBoolean("NodeFormat");
|
this.name = name;
|
||||||
} else {
|
this.parent = parent;
|
||||||
isDir = true;
|
this.item = item;
|
||||||
|
this.type = type;
|
||||||
|
this.lastUpdate = lastUpdate;
|
||||||
|
this.isDir = isDir;
|
||||||
|
if (!isDir) {
|
||||||
|
this.schemFormat = schemFormat;
|
||||||
|
this.rank = rank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,136 +96,60 @@ public class SchematicNode {
|
|||||||
if (parent != null && parent == 0) {
|
if (parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
}
|
}
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
return Provider.impl.getSchematicNode(owner, name, parent);
|
||||||
if (rs.next()) {
|
|
||||||
return new SchematicNode(rs);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicNode_Null.select(user, owner, name);
|
|
||||||
} else {
|
|
||||||
return getSchematicNode.select(user, owner, name, parent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
public static List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||||
if(parent != null && parent == 0)
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicsInNode_Null.select(user);
|
|
||||||
}else {
|
|
||||||
return getSchematicsInNode.select(user, parent);
|
|
||||||
}
|
}
|
||||||
|
return Provider.impl.getSchematicNodeInNode(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
public static List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||||
if(parent != null && parent == 0)
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getDirsInNode_Null.select(user);
|
|
||||||
}else {
|
|
||||||
return getDirsInNode.select(user, parent);
|
|
||||||
}
|
}
|
||||||
|
return Provider.impl.getSchematicDirectoryInNode(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
public static SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||||
if(parent != null && parent == 0)
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
|
||||||
while (rs.next()) {
|
|
||||||
SchematicNode node = new SchematicNode(rs);
|
|
||||||
if(node.isDir())
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicDirectory_Null.select(user, name);
|
|
||||||
}else {
|
|
||||||
return getSchematicDirectory.select(user, name, parent);
|
|
||||||
}
|
}
|
||||||
|
return Provider.impl.getSchematicDirectory(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(String name, Integer parent) {
|
public static SchematicNode getSchematicNode(String name, Integer parent) {
|
||||||
if(parent != null && parent == 0)
|
if(parent != null && parent == 0) {
|
||||||
parent = null;
|
parent = null;
|
||||||
Statement.ResultSetUser<SchematicNode> user = rs -> {
|
|
||||||
while (rs.next()) {
|
|
||||||
return new SchematicNode(rs);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
if(parent == null) {
|
|
||||||
return getSchematicNodeO_Null.select(user, name);
|
|
||||||
}else {
|
|
||||||
return getSchematicNodeO.select(user, name, parent);
|
|
||||||
}
|
}
|
||||||
|
return Provider.impl.getSchematicNode(name, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getSchematicNode(int id) {
|
public static SchematicNode getSchematicNode(int id) {
|
||||||
return getSchematicNodeId.select(rs -> {
|
return Provider.impl.getSchematicNode(id);
|
||||||
if (!rs.next())
|
|
||||||
return null;
|
|
||||||
return new SchematicNode(rs);
|
|
||||||
}, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
public static List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
||||||
Statement.ResultSetUser<List<SchematicNode>> user = rs -> {
|
return Provider.impl.getAccessibleSchematicsOfTypeInParent(owner, schemType, parent);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
};
|
|
||||||
if(parent == null || parent == 0) {
|
|
||||||
return getAccessibleByUserByTypeInNode_Null.select(user, owner, owner, schemType);
|
|
||||||
} else {
|
|
||||||
return getAccessibleByUserByTypeInNode.select(user, owner, owner, schemType, parent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
public static List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
||||||
return getAccessibleByUserByType.select(rs -> {
|
return Provider.impl.getAllAccessibleSchematicsOfType(user, schemType);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, user, user, schemType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
public static List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||||
return getAllSchemsOfTypeOwner.select(rs -> {
|
return Provider.impl.getAllSchematicsOfType(owner, schemType);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
}, owner, schemType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
public static List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||||
return getAllSchemsOfType.select(rs -> {
|
return Provider.impl.getAllSchematicsOfType(schemType);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
}
|
||||||
while (rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
public static List<SchematicNode> getAllSchematicsOfType(SchematicType schemType) {
|
||||||
return nodes;
|
return Provider.impl.getAllSchematicsOfType(schemType.toDB());
|
||||||
}, schemType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) {
|
public static List<SchematicNode> deepGet(Integer parent, Predicate<SchematicNode> filter) {
|
||||||
@ -264,32 +167,11 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
public static List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||||
if (parent != null && parent != 0) {
|
return Provider.impl.getSchematicsAccessibleByUser(user, parent);
|
||||||
if(Boolean.TRUE.equals(isSchematicAccessibleForUser.select(rs -> {
|
|
||||||
rs.next();
|
|
||||||
return rs.getInt("Accessible") > 0;
|
|
||||||
}, parent, user, user))) {
|
|
||||||
return getSchematicNodeInNode(parent);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return getAccessibleByUser.select(rs -> {
|
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while(rs.next())
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
return nodes;
|
|
||||||
}, user, user, user, user);
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
public static List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||||
return getAllSchematicsAccessibleByUser.select(rs -> {
|
return Provider.impl.getAllSchematicsAccessibleByUser(user);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while(rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, user, user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllParentsOfNode(SchematicNode node) {
|
public static List<SchematicNode> getAllParentsOfNode(SchematicNode node) {
|
||||||
@ -297,13 +179,7 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<SchematicNode> getAllParentsOfNode(int node) {
|
public static List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
return getAllParentsOfNode.select(rs -> {
|
return Provider.impl.getAllParentsOfNode(node);
|
||||||
List<SchematicNode> nodes = new ArrayList<>();
|
|
||||||
while(rs.next()) {
|
|
||||||
nodes.add(new SchematicNode(rs));
|
|
||||||
}
|
|
||||||
return nodes;
|
|
||||||
}, node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchematicNode getNodeFromPath(SteamwarUser user, String s) {
|
public static SchematicNode getNodeFromPath(SteamwarUser user, String s) {
|
||||||
@ -367,12 +243,7 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Integer countNodes() {
|
public static Integer countNodes() {
|
||||||
return countNodes.select(rs -> {
|
return Provider.impl.countNodes();
|
||||||
if (rs.next()) {
|
|
||||||
return rs.getInt("count");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@ -501,32 +372,17 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateDB() {
|
private void updateDB() {
|
||||||
updateDB.update(name, owner, parent, item, type, rank, id);
|
Provider.impl.updateSchematicNode(this);
|
||||||
this.lastUpdate = Timestamp.from(Instant.now());
|
this.lastUpdate = Timestamp.from(Instant.now());
|
||||||
this.brCache.clear();
|
this.brCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
deleteNode.update(id);
|
Provider.impl.deleteSchematicNode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream schemData() throws IOException {
|
public InputStream schemData() throws IOException {
|
||||||
try {
|
return Provider.impl.getSchematicData(this);
|
||||||
return selSchemData.select(rs -> {
|
|
||||||
rs.next();
|
|
||||||
Blob schemData = rs.getBlob("NodeData");
|
|
||||||
if(schemData == null) {
|
|
||||||
throw new SecurityException("SchemData is null");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return new GZIPInputStream(schemData.getBinaryStream());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new SecurityException("SchemData is wrong", e);
|
|
||||||
}
|
|
||||||
}, id);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Clipboard load() throws IOException, NoClipboardException {
|
public Clipboard load() throws IOException, NoClipboardException {
|
||||||
@ -560,7 +416,7 @@ public class SchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateDatabase(InputStream blob, boolean newFormat) {
|
private void updateDatabase(InputStream blob, boolean newFormat) {
|
||||||
updateDatabase.update(blob, newFormat, id);
|
Provider.impl.saveSchematicNode(this, blob, newFormat);
|
||||||
schemFormat = newFormat;
|
schemFormat = newFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@ -191,5 +192,90 @@ public class StandaloneProvider implements Provider {
|
|||||||
configs.computeIfAbsent(id, player -> new HashMap<>()).remove(config);
|
configs.computeIfAbsent(id, player -> new HashMap<>()).remove(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createSchematicNode(int owner, String name, Integer parent, String type, String item) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(int owner, String name, Integer parent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicNodeInNode(Integer parent) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicDirectoryInNode(Integer parent) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicDirectory(String name, Integer parent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(String name, Integer parent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchematicNode getSchematicNode(int id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAccessibleSchematicsOfTypeInParent(int owner, String schemType, Integer parent) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllAccessibleSchematicsOfType(int user, String schemType) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsOfType(int owner, String schemType) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsOfType(String schemType) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getSchematicsAccessibleByUser(int user, Integer parent) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllSchematicsAccessibleByUser(int user) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SchematicNode> getAllParentsOfNode(int node) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer countNodes() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSchematicNode(SchematicNode node) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteSchematicNode(SchematicNode node) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getSchematicData(SchematicNode node) throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveSchematicNode(SchematicNode node, InputStream blob, boolean newFormat) {}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren