Skip to content
Demo for Celesta 7.x usage
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
README.adoc
pom.xml

README.adoc

Celesta Demo

This project demonstrates the simple RESTful service based on relational DB using Celesta and Spring Boot.

Build and Test

To build the project, run mvn verify: code for cursor classes will be generated in target\generated-sources\celesta... folder. Then you may run the Spring Boot application in App class.

This application exports two REST handlers.

{
	"id": "no1",
	"date": "2017-01-02",
	"customerId": "CUST1",
	"customerName": "John Doe",
	"lines": [{
			"itemId": "A",
			"qty": 5
		},
		{
			"itemId": "B",
			"qty": 4
		}
	]
}
{
   "A": 10,
   "B": 8
}

Database Structure

Database definition file is demo.sql.

You can try to modify it and re-run the application on non-empty database (see below how to connect to PostgreSQL) to test the automatic migration facility.

Unit tests

See how service layer is tested in DocumentServiceTest.

The test class is annotated with @CelestaTest, and each test method has CallContext parameter. Behind the scenes Celesta runs with in-memory H2 database and the correct CallContext is provided for your tests.

Using 'real' database connection

This application by default runs on H2-in-memory DB.

You may try to use any other RDBMS supported by Celesta, e. g. PostgreSQL. In order to do this, first create an empty database on your server (e. g. named celesta).

Database connection is set in application.yml file. Instead of

celesta:
  h2:
    inMemory: true

you may write

celesta:
  jdbc:
    url: jdbc:postgresql://127.0.0.1:5432/celesta
    username: <your_username>
    password: <your_password>

(see Celesta documentation for complete Celesta options reference).

To start the application with connection to PostgreSQL you will also need PostgreSQL JDBC driver, which you can simply add to dependencies:

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.4</version>
</dependency>
You can’t perform that action at this time.