IGNITE-14996 - Updated examples structure
diff --git a/assembly/assembly.xml b/assembly/assembly.xml
index d5d256b..04a7975 100644
--- a/assembly/assembly.xml
+++ b/assembly/assembly.xml
@@ -69,6 +69,7 @@
<directory>examples</directory>
<outputDirectory>/examples</outputDirectory>
<includes>
+ <include>config/**</include>
<include>src/**</include>
</includes>
</fileSet>
diff --git a/examples/README.md b/examples/README.md
new file mode 100644
index 0000000..8e1b30b
--- /dev/null
+++ b/examples/README.md
@@ -0,0 +1,21 @@
+# Apache Ignite 3 Examples
+
+This project contains code examples for Apache Ignite 3.
+
+Examples are shipped as a separate Maven project, so to start running you simply need
+to import provided `pom.xml` file into your favourite IDE.
+
+The following examples are included:
+* `TableExample` - demonstrates the usage of the `org.apache.ignite.table.Table` API
+* `KeyValueBinaryViewExample` - demonstrates the usage of the `org.apache.ignite.table.KeyValueBinaryView` API
+
+To run an example, do the following:
+1. Import the examples project into you IDE.
+2. (optional) Run one or more standalone nodes using the CLI tool:
+ ```
+ ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-1
+ ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-2
+ ...
+ ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-n
+ ```
+3. Run the preferred example in the IDE.
diff --git a/examples/src/main/resources/ignite-config.json b/examples/config/ignite-config.json
similarity index 81%
rename from examples/src/main/resources/ignite-config.json
rename to examples/config/ignite-config.json
index 785d27c..d09db83 100644
--- a/examples/src/main/resources/ignite-config.json
+++ b/examples/config/ignite-config.json
@@ -1,7 +1,7 @@
{
"node": {
"metastorageNodes": [
- "node0"
+ "node-0", "node-1", "node-2"
]
},
"network": {
diff --git a/examples/src/main/java/org/apache/ignite/example/table/KeyValueBinaryViewExample.java b/examples/src/main/java/org/apache/ignite/example/table/KeyValueBinaryViewExample.java
index b8e7610..28f6888 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/KeyValueBinaryViewExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/table/KeyValueBinaryViewExample.java
@@ -25,11 +25,26 @@
import org.apache.ignite.table.Table;
import org.apache.ignite.table.Tuple;
+/**
+ * This example demonstrates the usage of the {@link KeyValueBinaryView} API.
+ * <p>
+ * To run the example, do the following:
+ * <ol>
+ * <li>Import the examples project into you IDE.</li>
+ * <li>
+ * (optional) Run one or more standalone nodes using the CLI tool:<br>
+ * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-1}<br>
+ * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-2}<br>
+ * {@code ...}<br>
+* {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-n}<br>
+ * </li>
+ * <li>Run the example in the IDE.</li>
+ * </ol>
+ */
public class KeyValueBinaryViewExample {
public static void main(String[] args) throws Exception {
- String config = Files.readString(Path.of(ClassLoader.getSystemResource("ignite-config.json").toURI()));
-
- Ignite ignite = IgnitionManager.start("node0", config);
+ Ignite ignite = IgnitionManager.start("node-0",
+ Files.readString(Path.of("config/ignite-config.json")));
//---------------------------------------------------------------------------------
//
diff --git a/examples/src/main/java/org/apache/ignite/example/table/TableExample.java b/examples/src/main/java/org/apache/ignite/example/table/TableExample.java
index 222d772..e97c5fe 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/TableExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/table/TableExample.java
@@ -24,72 +24,86 @@
import org.apache.ignite.table.Table;
import org.apache.ignite.table.Tuple;
+/**
+ * This example demonstrates the usage of the {@link Table} API.
+ * <p>
+ * To run the example, do the following:
+ * <ol>
+ * <li>Import the examples project into you IDE.</li>
+ * <li>
+ * (optional) Run one or more standalone nodes using the CLI tool:<br>
+ * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-1}<br>
+ * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-2}<br>
+ * {@code ...}<br>
+* {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-n}<br>
+ * </li>
+ * <li>Run the example in the IDE.</li>
+ * </ol>
+ */
public class TableExample {
public static void main(String[] args) throws Exception {
- String config = Files.readString(Path.of(ClassLoader.getSystemResource("ignite-config.json").toURI()));
+ Ignite ignite = IgnitionManager.start("node-0",
+ Files.readString(Path.of("config/ignite-config.json")));
- try (Ignite ignite = IgnitionManager.start("node0", config)) {
+ //---------------------------------------------------------------------------------
+ //
+ // Creating a table. The API call below is the equivalent of the following DDL:
+ //
+ // CREATE TABLE accounts (
+ // accountNumber INT PRIMARY KEY,
+ // firstName VARCHAR,
+ // lastName VARCHAR,
+ // balance DOUBLE
+ // )
+ //
+ //---------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------
- //
- // Creating a table. The API call below is the equivalent of the following DDL:
- //
- // CREATE TABLE accounts (
- // accountNumber INT PRIMARY KEY,
- // firstName VARCHAR,
- // lastName VARCHAR,
- // balance DOUBLE
- // )
- //
- //---------------------------------------------------------------------------------
-
- Table accounts = ignite.tables().createTable("PUBLIC.accounts", tbl -> tbl
- .changeName("PUBLIC.accounts")
- .changeColumns(cols -> cols
- .create("0", c -> c.changeName("accountNumber").changeType(t -> t.changeType("int32")).changeNullable(false))
- .create("1", c -> c.changeName("firstName").changeType(t -> t.changeType("string")).changeNullable(true))
- .create("2", c -> c.changeName("lastName").changeType(t -> t.changeType("string")).changeNullable(true))
- .create("3", c -> c.changeName("balance").changeType(t -> t.changeType("double")).changeNullable(true))
+ Table accounts = ignite.tables().createTable("PUBLIC.accounts", tbl -> tbl
+ .changeName("PUBLIC.accounts")
+ .changeColumns(cols -> cols
+ .create("0", c -> c.changeName("accountNumber").changeType(t -> t.changeType("int32")).changeNullable(false))
+ .create("1", c -> c.changeName("firstName").changeType(t -> t.changeType("string")).changeNullable(true))
+ .create("2", c -> c.changeName("lastName").changeType(t -> t.changeType("string")).changeNullable(true))
+ .create("3", c -> c.changeName("balance").changeType(t -> t.changeType("double")).changeNullable(true))
+ )
+ .changeIndices(idxs -> idxs
+ .create("PK", idx -> idx
+ .changeName("PK")
+ .changeType("PK")
+ .changeColumns(cols -> cols.create("0", c -> c.changeName("accountNumber").changeAsc(true)))
)
- .changeIndices(idxs -> idxs
- .create("PK", idx -> idx
- .changeName("PK")
- .changeType("PK")
- .changeColumns(cols -> cols.create("0", c -> c.changeName("accountNumber").changeAsc(true)))
- )
- )
- );
+ )
+ );
- //---------------------------------------------------------------------------------
- //
- // Tuple API: insert operation.
- //
- //---------------------------------------------------------------------------------
+ //---------------------------------------------------------------------------------
+ //
+ // Tuple API: insert operation.
+ //
+ //---------------------------------------------------------------------------------
- Tuple newAccountTuple = accounts.tupleBuilder()
- .set("accountNumber", 123456)
- .set("firstName", "Val")
- .set("lastName", "Kulichenko")
- .set("balance", 100.00d)
- .build();
+ Tuple newAccountTuple = accounts.tupleBuilder()
+ .set("accountNumber", 123456)
+ .set("firstName", "Val")
+ .set("lastName", "Kulichenko")
+ .set("balance", 100.00d)
+ .build();
- accounts.insert(newAccountTuple);
+ accounts.insert(newAccountTuple);
- //---------------------------------------------------------------------------------
- //
- // Tuple API: get operation.
- //
- //---------------------------------------------------------------------------------
+ //---------------------------------------------------------------------------------
+ //
+ // Tuple API: get operation.
+ //
+ //---------------------------------------------------------------------------------
- Tuple accountNumberTuple = accounts.tupleBuilder().set("accountNumber", 123456).build();
+ Tuple accountNumberTuple = accounts.tupleBuilder().set("accountNumber", 123456).build();
- Tuple accountTuple = accounts.get(accountNumberTuple);
+ Tuple accountTuple = accounts.get(accountNumberTuple);
- System.out.println(
- "Retrieved using Tuple API\n" +
- " Account Number: " + accountTuple.intValue("accountNumber") + '\n' +
- " Owner: " + accountTuple.stringValue("firstName") + " " + accountTuple.stringValue("lastName") + '\n' +
- " Balance: $" + accountTuple.doubleValue("balance"));
- }
+ System.out.println(
+ "Retrieved using Tuple API\n" +
+ " Account Number: " + accountTuple.intValue("accountNumber") + '\n' +
+ " Owner: " + accountTuple.stringValue("firstName") + " " + accountTuple.stringValue("lastName") + '\n' +
+ " Balance: $" + accountTuple.doubleValue("balance"));
}
}