Skip to content
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
64 changes: 64 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.orders</groupId>
<artifactId>orders</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>orders</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>14</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<!-- <scope>runtime</scope>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
13 changes: 13 additions & 0 deletions src/main/java/com/orders/OrdersApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.orders;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class OrdersApplication {

public static void main(String[] args) {
SpringApplication.run(OrdersApplication.class, args);
}

}
4 changes: 4 additions & 0 deletions src/main/java/com/orders/SeedData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.orders;

public class SeedData {
}
74 changes: 74 additions & 0 deletions src/main/java/com/orders/config/H2ServerConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package src.main.java.com.orders.config;


import org.h2.tools.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.sql.SQLException;

/**
* Configures H2 access through the JetBrains IntelliJ IDEA IDE.
* <p>
* Adapted from https://techdev.io/en/developer-blog/querying-the-embedded-h2-database-of-a-spring-boot-application
* necessary for using the database tool built into intellij
*/
@Configuration
public class H2ServerConfiguration
{

/**
* TCP port for remote connections, default 9092.
*/
@Value("${h2.tcp.port:9092}")
private String h2TcpPort;

/**
* Web port, default 8082.
*/
@Value("${h2.web.port:8082}")
private String h2WebPort;

/**
* TCP connection to connect with SQL clients to the embedded h2 database.
* <p>
* Connect to "jdbc:h2:tcp://localhost:9092/mem:testdb", username "sa", password empty.
*
* @return The created TcpServer needed to access H2.
* @throws SQLException If the server cannot be created.
*/
@Bean
@ConditionalOnExpression("${h2.tcp.enabled:true}")
public Server h2TcpServer() throws
SQLException
{
return Server.createTcpServer("-tcp",
"-tcpAllowOthers",
"-tcpPort",
h2TcpPort)
.start();
}

/**
* Web console for the embedded h2 database.
* <p>
* Go to http://localhost:8082 and connect to the database "jdbc:h2:mem:testdb", username "sa", password empty.
*
* @return The created web server needed to access H2.
* @throws SQLException If the server cannot be created.
*/
@Bean
@ConditionalOnExpression("${h2.web.enabled:true}")
public Server h2WebServer() throws
SQLException
{
return Server.createWebServer("-web",
"-webAllowOthers",
"-webPort",
h2WebPort)
.start();
}
}

82 changes: 82 additions & 0 deletions src/main/java/com/orders/models/Agent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.orders.models;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "agents")
public class Agent {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long agentcode;
private String agentname;
private String workingarea;
private double commission;
private String phone;
private String country;

@OneToMany(mappedBy = "agent", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Customer> customers = new ArrayList<>();

public Agent(){

}

public Agent(String agentname, String workingarea, double commission, String phone, String country) {
this.agentname = agentname;
this.workingarea = workingarea;
this.commission = commission;
this.phone = phone;
this.country = country;
}

public long getAgentcode() {
return agentcode;
}

public void setAgentcode(long agentcode) {
this.agentcode = agentcode;
}

public String getAgentname() {
return agentname;
}

public void setAgentname(String agentname) {
this.agentname = agentname;
}

public String getWorkingarea() {
return workingarea;
}

public void setWorkingarea(String workingarea) {
this.workingarea = workingarea;
}

public double getCommission() {
return commission;
}

public void setCommission(double commission) {
this.commission = commission;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}
}
151 changes: 151 additions & 0 deletions src/main/java/com/orders/models/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package com.orders.models;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table( name = "customers")
public class Customer {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false)
private long custcode;

@Column(nullable = false)
private String custname;

private String custcity;
private String workingarea;
private String custcountry;
private String grade;
private double openingamt;
private double receiveamt;
private double paymentamt;
private double outstandingamt;
private String phone;

@ManyToOne
@JoinColumn(name = "agentcode", nullable = false)
private Agent agent;

@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Order> orders = new ArrayList<>();

public Customer(){

}

public Customer(String custname, String custcity, String workingarea,
String custcountry, String grade, double openingamt,
double receiveamt, double paymentamt,
double outstandingamt, String phone, Agent agent) {
this.custname = custname;
this.custcity = custcity;
this.workingarea = workingarea;
this.custcountry = custcountry;
this.grade = grade;
this.receiveamt = receiveamt;
this.paymentamt = paymentamt;
this.outstandingamt = outstandingamt;
this.phone = phone;
this.agent = agent;
}

public Agent getAgent() {
return agent;
}

public void setAgent(Agent agent) {
this.agent = agent;
}

public long getCustcode() {
return custcode;
}

public void setCustcode(long custcode) {
this.custcode = custcode;
}

public String getCustname() {
return custname;
}

public void setCustname(String custname) {
this.custname = custname;
}

public String getCustcity() {
return custcity;
}

public void setCustcity(String custcity) {
this.custcity = custcity;
}

public String getWorkingarea() {
return workingarea;
}

public void setWorkingarea(String workingarea) {
this.workingarea = workingarea;
}

public String getCustcountry() {
return custcountry;
}

public void setCustcountry(String custcountry) {
this.custcountry = custcountry;
}

public String getGrade() {
return grade;
}

public void setGrade(String grade) {
this.grade = grade;
}

public double getOpeningamt() {
return openingamt;
}

public void setOpeningamt(double openingamt) {
this.openingamt = openingamt;
}

public double getReceiveamt() {
return receiveamt;
}

public void setReceiveamt(double receiveamt) {
this.receiveamt = receiveamt;
}

public double getPaymentamt() {
return paymentamt;
}

public void setPaymentamt(double paymentamt) {
this.paymentamt = paymentamt;
}

public double getOutstandingamt() {
return outstandingamt;
}

public void setOutstandingamt(double outstandingamt) {
this.outstandingamt = outstandingamt;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}
}
Loading