Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ent 5267 #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Basic/constants.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cordaReleaseGroup=net.corda
cordaCoreReleaseGroup=net.corda
cordaVersion=4.5-RC02
cordaCoreVersion=4.5-RC02
cordaVersion=4.6-20200713_101257-adeea5c
cordaCoreVersion=4.6-20200713_101257-adeea5c
gradlePluginsVersion=5.0.10
kotlinVersion=1.2.71
junitVersion=4.12
Expand Down
29 changes: 28 additions & 1 deletion Basic/cordapp-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,31 @@

Welcome to the example CorDapp. This CorDapp is fully documented [here](http://docs.corda.net/tutorial-cordapp.html).

This example application has modules for both Java and Kotlin and is an exploratory sample for the official [Corda online training](https://training.corda.net). It demonstrates the basic components present in a CorDapp and how they work together using a simple IOU example.
This example application has modules for both Java and Kotlin and is an exploratory sample for the official [Corda online training](https://training.corda.net). It demonstrates the basic components present in a CorDapp and how they work together using a simple IOU example.

Additional Notes:

With Corda release 4.6, open source cordapps will have to write liquibase scripts to generate the custom database tables.
For rapid development in dev mode with H2, you could use below command to generate Hibernate entities for your custom schemas. You will not
require Liquibase scripts in such a situation.

java -jar corda.jar run-migration-scripts --app-schemas

Liquibase scripts have been added to workflow-java/src/main/resojurces/migration folder.

To run the migration scripts for corda node use below command

java -jar corda.jar run-migration-scripts --core-schemas


To run the migration scripts for your custom tables defined in your Cordapp use below command

java -jar corda.jar run-migration-scripts --app-schemas

If you already have hibernate entities created in your db, prior to using Corda version 4.6, use below command to sync the database

java -jar corda.jar sync-app-schemas


Read more about hwo to add liquibase to your cordapp here.
# TODO update documentation link.
1 change: 1 addition & 0 deletions Basic/cordapp-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ buildscript {
maven {
url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases'
}
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-dev/' }
mavenLocal()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import net.corda.core.schemas.MappedSchema;
import net.corda.core.schemas.PersistentState;

import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Arrays;
import java.util.UUID;
import org.hibernate.annotations.Type;

/**
* An IOUState schema.
Expand All @@ -17,13 +19,20 @@ public IOUSchemaV1() {
super(IOUSchema.class, 1, Arrays.asList(PersistentIOU.class));
}

@Nullable
@Override
public String getMigrationResource() {
return "iou.changelog-master";
}


@Entity
@Table(name = "iou_states")
public static class PersistentIOU extends PersistentState {
@Column(name = "lender") private final String lender;
@Column(name = "borrower") private final String borrower;
@Column(name = "value") private final int value;
@Column(name = "linear_id") private final UUID linearId;
@Column(name = "linear_id") @Type (type = "uuid-char") private final UUID linearId;


public PersistentIOU(String lender, String borrower, int value, UUID linearId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.schema

import net.corda.core.schemas.MappedSchema
import net.corda.core.schemas.PersistentState
import org.hibernate.annotations.Type
import java.util.*
import javax.persistence.Column
import javax.persistence.Entity
Expand All @@ -19,6 +20,11 @@ object IOUSchemaV1 : MappedSchema(
schemaFamily = IOUSchema.javaClass,
version = 1,
mappedTypes = listOf(PersistentIOU::class.java)) {

override val migrationResource: String?
get() = "iou.changelog-master";


@Entity
@Table(name = "iou_states")
class PersistentIOU(
Expand All @@ -32,6 +38,7 @@ object IOUSchemaV1 : MappedSchema(
var value: Int,

@Column(name = "linear_id")
@Type(type = "uuid-char")
var linearId: UUID
) : PersistentState() {
// Default constructor required by hibernate.
Expand Down
1 change: 1 addition & 0 deletions Basic/cordapp-example/repositories.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ repositories {
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda' }
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-dev/' }
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

<include file="migration/iou.changelog-v1.xml"/>
</databaseChangeLog>
Comment on lines +7 to +8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have changelog v1 and v2, but only including v1 here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i will remove v2. I had added that to test database upgrades.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<changeSet author="R3.Corda" id="create_iou_state">
<createTable tableName="iou_states">
<column name="output_index" type="INT">
<constraints nullable="false"/>
</column>
<column name="transaction_id" type="NVARCHAR(64)">
<constraints nullable="false"/>
</column>
<column name="value" type="int"/>
<column name="lender" type="NVARCHAR(64)"/>
<column name="borrower" type="NVARCHAR(64)"/>
<column name="linear_id" type="NVARCHAR(64)"/>
</createTable>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

<include file="migration/iou.changelog-v1.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<changeSet author="R3.Corda" id="create_iou_state">
<createTable tableName="iou_states">
<column name="output_index" type="INT">
<constraints nullable="false"/>
</column>
<column name="transaction_id" type="NVARCHAR(64)">
<constraints nullable="false"/>
</column>
<column name="value" type="int"/>
<column name="lender" type="NVARCHAR(64)"/>
<column name="borrower" type="NVARCHAR(64)"/>
<column name="linear_id" type="NVARCHAR(64)"/>
</createTable>
</changeSet>
</databaseChangeLog>
4 changes: 2 additions & 2 deletions Features/constants.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cordaReleaseGroup=net.corda
cordaCoreReleaseGroup=net.corda
cordaVersion=4.5-RC02
cordaCoreVersion=4.5-RC02
cordaVersion=4.6-20200713_101257-adeea5c
cordaCoreVersion=4.6-20200713_101257-adeea5c
gradlePluginsVersion=5.0.10
kotlinVersion=1.2.71
junitVersion=4.12
Expand Down
29 changes: 28 additions & 1 deletion Features/queryableState-carinsurance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,31 @@ http://www.h2database.com/html/download.html
</p>

Refer here for more details regarding connecting to the node database.
https://docs.corda.net/head/node-database-access-h2.html
https://docs.corda.net/head/node-database-access-h2.html

Additional Notes:

With Corda release 4.6, open source cordapps will have to write liquibase scripts to generate the custom database tables.
For rapid development in dev mode with H2, you could use below command to generate Hibernate entities for your custom schemas. You will not
require Liquibase scripts in such a situation.

java -jar corda.jar run-migration-scripts --app-schemas

Liquibase scripts have been added to workflow-java/src/main/resojurces/migration folder.

To run the migration scripts for corda node use below command

java -jar corda.jar run-migration-scripts --core-schemas


To run the migration scripts for your custom tables defined in your Cordapp use below command

java -jar corda.jar run-migration-scripts --app-schemas

If you already have hibernate entities created in your db, prior to using Corda version 4.6, use below command to sync the database

java -jar corda.jar sync-app-schemas


Read more about hwo to add liquibase to your cordapp here.
# TODO update documentation link.
2 changes: 2 additions & 0 deletions Features/queryableState-carinsurance/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ buildscript {
mavenCentral()
jcenter()
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases' }
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-dev/' }

}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.corda.samples.schema

import net.corda.core.schemas.MappedSchema
import net.corda.core.schemas.PersistentState
import org.hibernate.annotations.Type
import java.io.Serializable
import java.util.*
import javax.persistence.*
Expand All @@ -19,10 +20,16 @@ object InsuranceSchemaV1 : MappedSchema(
version = 1,
mappedTypes = listOf(PersistentClaim::class.java, PersistentInsurance::class.java, PersistentVehicle::class.java)) {


override val migrationResource: String?
get() = "insurance.changelog-master";


@Entity
@Table(name = "CLAIM_DETAIL")
class PersistentClaim(
@Id @Column(name = "Id")
@Type(type = "uuid-char")
val uuid:UUID,

@Column(name = "claimNumber")
Expand All @@ -42,6 +49,7 @@ object InsuranceSchemaV1 : MappedSchema(
@Table(name = "VEHICLE_DETAIL")
class PersistentVehicle(
@Id @Column(name = "Id")
@Type (type = "uuid-char")
val uuid:UUID,

@Column(name = "registrationNumber")
Expand Down
1 change: 1 addition & 0 deletions Features/queryableState-carinsurance/repositories.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-dev/' }
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda' }
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<changeSet author="R3.Corda" id="create_claim_detail_state">
<createTable tableName="claim_detail">
<column name="output_index" type="INT">
<constraints nullable="false"/>
</column>
<column name="transaction_id" type="NVARCHAR(64)">
<constraints nullable="false"/>
</column>
<column name="claimAmount" type="int"/>
<column name="claimNumber" type="NVARCHAR(64)"/>
<column name="claimDescription" type="NVARCHAR(64)"/>
<column name="id" type="NVARCHAR(64)"/>

</createTable>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<changeSet author="R3.Corda" id="create_insurance_detail_state">
<createTable tableName="insurance_detail">
<column name="output_index" type="INT">
<constraints nullable="false"/>
</column>
<column name="transaction_id" type="NVARCHAR(64)">
<constraints nullable="false"/>
</column>
<column name="policyNumber" type="NVARCHAR(64)"/>
<column name="duration" type="int"/>
<column name="premium" type="int"/>
<column name="insuredvalue" type="BIGINT"/>
<column name="id" type="NVARCHAR(64)"/>
<column name="registrationnumber" type="NVARCHAR(64)"/>

</createTable>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

<include file="migration/claim-detail.changelog-v1.xml"/>
<include file="migration/insurance-detail.changelog-v1.xml"/>
<include file="migration/vehicle-detail.changelog-v1.xml"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<changeSet author="R3.Corda" id="create_vehicle_detail_state">
<createTable tableName="vehicle_detail">

<column name="id" type="NVARCHAR(64)"/>
<column name="registrationNumber" type="NVARCHAR(64)"/>
<column name="chasisNumber" type="NVARCHAR(64)"/>
<column name="make" type="NVARCHAR(64)"/>
<column name="model" type="NVARCHAR(64)"/>
<column name="variant" type="NVARCHAR(64)"/>
<column name="color" type="NVARCHAR(64)"/>
<column name="fuelType" type="NVARCHAR(64)"/>

</createTable>
</changeSet>
</databaseChangeLog>