From fbcbbbe3b3597835d802f4224020cce0ef2a837c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Gerrit=20Schettler-K=C3=B6hler?= Date: Tue, 15 Jun 2021 13:05:54 +0200 Subject: [PATCH] Initial version of getting started with devon4j --- .../files/FriendEntity.java | 27 ++++++++ .../files/Placeholder.java | 9 +++ .../files/V0001__CreateFriendTable.sql | 7 ++ devon4j-getting-started/index.asciidoc | 69 +++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 devon4j-getting-started/files/FriendEntity.java create mode 100644 devon4j-getting-started/files/Placeholder.java create mode 100644 devon4j-getting-started/files/V0001__CreateFriendTable.sql create mode 100644 devon4j-getting-started/index.asciidoc diff --git a/devon4j-getting-started/files/FriendEntity.java b/devon4j-getting-started/files/FriendEntity.java new file mode 100644 index 000000000..78af5268d --- /dev/null +++ b/devon4j-getting-started/files/FriendEntity.java @@ -0,0 +1,27 @@ +package com.example.friendexample.friendmanagement.dataaccess.api; + +import java.sql.Timestamp; + +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name = "Friend") +public class FriendEntity { + + private String name; + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/devon4j-getting-started/files/Placeholder.java b/devon4j-getting-started/files/Placeholder.java new file mode 100644 index 000000000..9b5cedde7 --- /dev/null +++ b/devon4j-getting-started/files/Placeholder.java @@ -0,0 +1,9 @@ +private int age; +private String company; + +public String getCompany() { + return company; +} +public void setCompany(String company) { + this.company = company; +} \ No newline at end of file diff --git a/devon4j-getting-started/files/V0001__CreateFriendTable.sql b/devon4j-getting-started/files/V0001__CreateFriendTable.sql new file mode 100644 index 000000000..bd92e60f9 --- /dev/null +++ b/devon4j-getting-started/files/V0001__CreateFriendTable.sql @@ -0,0 +1,7 @@ +CREATE TABLE `Friend` ( + + id BIGINT NOT NULL AUTO_INCREMENT, + modificationCounter INTEGER NOT NULL, + name varchar(50) + +) \ No newline at end of file diff --git a/devon4j-getting-started/index.asciidoc b/devon4j-getting-started/index.asciidoc new file mode 100644 index 000000000..6ca4468c6 --- /dev/null +++ b/devon4j-getting-started/index.asciidoc @@ -0,0 +1,69 @@ += Getting started with devon4j +==== +This tutorial starts with an empty folder and will show you how to start your project. You will be setting up the complete IDE and will be writing your first business logic with devon4j. + +## Prerequisites +Basic java skills + +## Learning goals +After this tutorial you will be able to start your project and write your first business logic with devon4j. +==== + +This is a getting started tutorial. You will be guided through the necessary steps, with short explanations on what you are doing. You do not need to understand everything at this point - you get it later. + +Before you can start writing your fist business logic you will have to setup your development environment. We will do this with devon IDE. devon IDE is a tool that sets up your environment according to settings stored in a repository. This settings are usually provided by your project. +[step] +-- +installDevonfwIde(["java","mvn", "vscode"]) +-- + +For this tutorial we will use a tool called CobiGen which is included in devon IDE. CobiGen will be used later to generate most of your code. To use it we have to prepare it, once. +[step] +-- +installCobiGen() +-- + +==== +Great, now we can start developing. + +The first step is to create a devon4j project. We will use devon IDE for that so we do not have to do it by hand. +[step] +-- +createDevon4jProject("com.example.friendexample") +-- +Now you have an empty project. +==== + +In the next step we want to generate an API to store some information about our friends. We start by creating an database entity called FriendEntity. +[step] +-- +createFile("friendexample/core/src/main/java/com/example/friendexample/friendmanagement/dataaccess/api/FriendEntity.java", "files/FriendEntity.java") +-- + +Before we start generating code we need to build the application once to ensure that all dependencies are downloaded. +[step] +-- +buildJava("friendexample", false) +-- + +CobiGen is integrated via plugin in the VS Code IDE. We will use it to generate code from one single java class based on existing templates. +[step] +-- +adaptTemplatesCobiGen() +cobiGenJava("friendexample/core/src/main/java/com/example/friendexample/friendmanagement/dataaccess/api/FriendEntity.java",[1,3,5,6,8]) +-- + +==== +devonfw supports the automatic migration of databases with flyway. We will use this feature to create a database table for our friends entity. +[step] +-- +createFile("friendexample/core/src/main/resources/db/type/h2/V0001__CreateFriendTable.sql", "files/V0001__CreateFriendTable.sql") +-- +devonfw will use this file to migrate the database to the state we want when we start the application. +==== + +Now, we will start the server. +[step] +-- +runServerJava("devonfw/workspaces/main/friendexample/server", { "startupTime": 40, "port": 8080, "path": "friend" }) +-- \ No newline at end of file