Seperate SchematicData #45

Zusammengeführt
Lixfel hat 8 Commits von seperate_schemdata nach master 2023-02-24 10:32:22 +01:00 zusammengeführt
2 geänderte Dateien mit 74 neuen und 9 gelöschten Zeilen
Nur Änderungen aus Commit e52e9c5ccd werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -0,0 +1,69 @@
package de.steamwar.sql;
import de.steamwar.sql.internal.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.sql.PreparedStatement;
import java.util.zip.GZIPInputStream;
@AllArgsConstructor
public class NodeData {
static {
new SqlTypeMapper<>(PipedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("PipedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream);
new SqlTypeMapper<>(ByteArrayInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("ByteArrayInputStream is write only datatype"); }, PreparedStatement::setBinaryStream);
}
private static final Table<NodeData> table = new Table<>(NodeData.class);
private static final Statement updateDatabase = new Statement("UPDATE NodeData SET SchemData = ?, NodeFormat = ? WHERE NodeId = ?");
private static final Statement selSchemData = new Statement("SELECT SchemData FROM NodeData WHERE NodeId = ?");
private static final SelectStatement<NodeData> get = table.select(Table.PRIMARY);
public static NodeData get(SchematicNode node) {
if(node.isDir())
throw new IllegalArgumentException("Node is a directory");
return get.select(node);
}
@Getter
@Field(keys = {Table.PRIMARY})
private final int nodeId;
@Field
private boolean nodeFormat;
public InputStream schemData() throws IOException {
try {
return selSchemData.select(rs -> {
rs.next();
InputStream schemData = rs.getBinaryStream("SchemData");
try {
if(rs.wasNull() || schemData.available() == 0) {
throw new SecurityException("SchemData is null");
}
return new GZIPInputStream(schemData);
} catch (IOException e) {
throw new SecurityException("SchemData is wrong", e);
}
}, nodeId);
} catch (Exception e) {
throw new IOException(e);
}
}
public void saveFromStream(InputStream blob, boolean newFormat) {
updateDatabase.update(blob, newFormat, nodeId);
nodeFormat = newFormat;
}
public boolean getNodeFormat() {
return nodeFormat;
}
}

Datei anzeigen

@ -44,7 +44,7 @@ public class SchematicNode {
private static final Table<SchematicNode> table = new Table<>(SchematicNode.class);
private static final Statement create = table.insertFields(true, "NodeOwner", "NodeName", "ParentNode", "NodeItem", "NodeType");
private static final Statement update = table.update(Table.PRIMARY, "NodeName", "ParentNode", "NodeItem", "NodeType", "NodeRank", "ReplaceColor", "AllowReplay", "NodeFormat");
private static final Statement update = table.update(Table.PRIMARY, "NodeName", "ParentNode", "NodeItem", "NodeType", "NodeRank", "ReplaceColor", "AllowReplay");
private static final Statement delete = table.delete(Table.PRIMARY);
private static final SelectStatement<SchematicNode> byId = new SelectStatement<>(table, nodeSelector + "WHERE NodeId = ?");
@ -89,9 +89,6 @@ public class SchematicNode {
private boolean replaceColor;
@Field(def = "1")
private boolean allowReplay;
@Setter(AccessLevel.PACKAGE)
@Field(def = "1")
private boolean nodeFormat;
private String brCache;
@ -106,8 +103,7 @@ public class SchematicNode {
SchematicType nodeType,
int nodeRank,
boolean replaceColor,
boolean allowReplay,
boolean nodeFormat
boolean allowReplay
) {
this.nodeId = nodeId;
this.nodeOwner = nodeOwner;
@ -120,7 +116,6 @@ public class SchematicNode {
this.nodeRank = nodeRank;
this.replaceColor = replaceColor;
this.allowReplay = allowReplay;
this.nodeFormat = nodeFormat;
}
public static List<SchematicNode> getAll(SteamwarUser user) {
@ -381,10 +376,11 @@ public class SchematicNode {
return nodeType == null;
}
@Deprecated
public boolean getSchemFormat() {
if(isDir())
throw new SecurityException("Node is Directory");
return nodeFormat;
return NodeData.get(this).getNodeFormat();
}
public int getRank() {
@ -462,7 +458,7 @@ public class SchematicNode {
private void updateDB() {
this.lastUpdate = Timestamp.from(Instant.now());
update.update(nodeName, parentNode, nodeItem, nodeType, nodeRank, replaceColor, allowReplay, nodeFormat, nodeId);
update.update(nodeName, parentNode, nodeItem, nodeType, nodeRank, replaceColor, allowReplay, nodeId);
TAB_CACHE.clear();
}