1 package org.simantics.db.common;
3 import java.io.IOException;
4 import java.util.ArrayList;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.databoard.binding.Binding;
9 import org.simantics.databoard.serialization.SerializationException;
10 import org.simantics.databoard.serialization.Serializer;
11 import org.simantics.db.Metadata;
12 import org.simantics.db.Session;
13 import org.simantics.db.WriteGraph;
14 import org.simantics.db.exception.DatabaseException;
16 public class CommandMetadata implements Metadata {
18 public static final boolean DEBUG = false;
19 public static final String RESET_COMMAND = "// RESET";
21 private static final Binding BINDING =
22 Bindings.getBindingUnchecked(CommandMetadata.class);
23 private static final Serializer SERIALIZER =
24 Bindings.getSerializerUnchecked(BINDING);
26 public List<Command> commands;
28 public static class Command {
30 public String command;
35 public Command(long modelId, String command) {
37 this.modelId = modelId;
38 this.command = command;
42 public CommandMetadata() {
46 public byte[] serialise(Session session) {
48 return SERIALIZER.serialize(this);
49 } catch (IOException e) {
51 throw new RuntimeException(e);
55 public static CommandMetadata deserialise(Session session, byte[] input) {
57 CommandMetadata metadata = new CommandMetadata();
58 metadata.commands = new ArrayList<Command>();
62 return (CommandMetadata)SERIALIZER.deserialize(input);
63 } catch (SerializationException e) {
65 } catch (IOException e) {
71 public CommandMetadata add(Command command) {
72 commands.add(command);
76 public List<Command> getCommands() {
80 public static void add(WriteGraph graph, long modelId, String command) throws DatabaseException {
82 System.out.println("-------------------------------------------------------------");
83 System.out.println(command);
85 graph.addMetadata(graph.getMetadata(CommandMetadata.class).add(
86 new Command(modelId, command)));
89 public static void addReset(WriteGraph graph, long modelId) throws DatabaseException {
90 graph.addMetadata(graph.getMetadata(CommandMetadata.class).add(
91 new Command(modelId, RESET_COMMAND)));