Skip to content

Commit

Permalink
dbcsql v1.0.4
Browse files Browse the repository at this point in the history
Better example
  • Loading branch information
ghpv committed May 29, 2023
1 parent 38198ba commit 6fd81ae
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package ee.taltech.dbcsql.iface.gui;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;

import ee.taltech.dbcsql.core.phase.GenerationRequest;
import ee.taltech.dbcsql.core.phase.TranslatorInputException;
Expand Down Expand Up @@ -38,6 +42,8 @@ public class MainViewBuilder
private TextField paramPrefix = new TextField();
private TextField opPrefix = new TextField();
private MemoryPersistence memoryPersistence = new MemoryPersistence();
private static final String EXAMPLE_CONTEXT = "example_context.dsl";
private static final String EXAMPLE_CONTRACT = "example_contract.dsl";

public MainViewBuilder()
{
Expand Down Expand Up @@ -100,15 +106,15 @@ public MainViewBuilder()
private TextArea makeContextView()
{
TextArea contextView = new TextArea();
contextView.setText("table test\n{\n\tid INTEGER;\n};\nidentifier for test is id;");
contextView.setText(getResourceFileAsString(EXAMPLE_CONTEXT));
contextView.setPromptText("// Context goes here");
return contextView;
}

private TextArea makeContractView()
{
TextArea contractView = new TextArea();
contractView.setText("operation add_test\n{\n\tp_id;\n}\npreconditions\n{\n}\npostconditions\n{\n\tinserted test a\n\t{\n\t\tid = p_id;\n\t};\n}");
contractView.setText(getResourceFileAsString(EXAMPLE_CONTRACT));
contractView.setPromptText("// Contract goes here");
return contractView;
}
Expand Down Expand Up @@ -169,8 +175,37 @@ private InputStream streamFromString(String str)
return new ByteArrayInputStream(str.getBytes());
}

private static String getResourceFileAsString(String fileName)
{
try
{
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
try (InputStream is = classLoader.getResourceAsStream(fileName))
{
if (is == null)
{
return null;
}
try
(
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr)
) {
return reader
.lines()
.collect(Collectors.joining(System.lineSeparator()));
}
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}

public Scene build()
{
return mainScene;
}

}
17 changes: 17 additions & 0 deletions iface/gui/src/main/resources/example_context.dsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
table x
{
x_code INTEGER;
y_code SMALLINT;
z SMALLINT;
};
identifier for x is x_code;
table state=y
{
y_code SMALLINT;
state_name=y_name VARCHAR;
};
identifier for y is y_code;
connection between x and y
{
y_code = y_code;
};
21 changes: 21 additions & 0 deletions iface/gui/src/main/resources/example_contract.dsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
operation "delete an x"
{
p_x_code;
}
preconditions
{
exists x child (x_code=p_x_code and z>100);
exists state parent (state_name = 'Inactive');
connection between child and parent;
}
postconditions
{
deleted child;
}
comment 'Delete an x instance if it is in the state
inactive and its z value is bigger than 100.

Contracts refer to the elements in the conceptual data model.
Conceptual data model specifies entity type state with an attribute state_name.
In the database corresponding table and column names are y and y_name, respectively.
The mapping is specified in the context description.';
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<packaging>pom</packaging>

<properties>
<revision>1.0.3</revision>
<revision>1.0.4</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>18</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
Expand Down

0 comments on commit 6fd81ae

Please sign in to comment.