Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Commit 9d9c01a

Browse files
committed
Addition of repositories
1 parent 22fad59 commit 9d9c01a

File tree

10 files changed

+157
-155
lines changed

10 files changed

+157
-155
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
<artifactId>mysql-connector-java</artifactId>
9696
<scope>runtime</scope>
9797
</dependency>
98+
<dependency>
99+
<groupId>org.apache.commons</groupId>
100+
<artifactId>commons-dbcp2</artifactId>
101+
<version>2.0</version>
102+
</dependency>
98103
</dependencies>
99104

100105
<build>

src/main/java/pl/simplemethod/codebin/CodebinApplication.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
public class CodebinApplication {
1717

1818
public static void main(String[] args) {
19-
ConfigurableApplicationContext ctx = SpringApplication.run(CodebinApplication.class, args);
20-
ContextWrapper.initWrapper(ctx);
19+
SpringApplication.run(CodebinApplication.class, args);
2120
}
2221

2322
@Bean

src/main/java/pl/simplemethod/codebin/dao/ImagesDao.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/main/java/pl/simplemethod/codebin/model/Containers.java

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@
99
@Table(name = "containers")
1010
public class Containers implements Serializable {
1111

12+
1213
@Id
1314
@GeneratedValue(strategy = GenerationType.IDENTITY)
14-
@Column(name = "id_container")
15+
@Column(name = "id")
1516
private Integer id;
1617

1718
@NonNull
1819
@Column
1920
private String name;
2021

2122
@NonNull
22-
@OneToOne
23+
@Column(name = "id_docker")
24+
private String idDocker;
25+
26+
@NonNull
27+
@OneToOne(cascade = CascadeType.ALL)
28+
@JoinColumn(name = "images_id", referencedColumnName = "id")
2329
private Images image;
2430

2531
@NonNull
@@ -38,39 +44,13 @@ public class Containers implements Serializable {
3844
@Column(name = "disk_quota")
3945
private Long diskQuota;
4046

41-
@NonNull
42-
@Column(name = "create_time")
43-
private Long createTime;
44-
45-
@NonNull
46-
@Column(name = "premium_status")
47-
private Boolean premiumStatus;
48-
49-
@NonNull
50-
@Column
51-
private String type;
52-
5347
@NonNull
5448
@Column(name = "status")
5549
private Integer status;
5650

5751
@NonNull
58-
@Column(name = "docker_id")
59-
private String docker_id;
60-
61-
public Containers(String name, Images image, Integer exposedPorts, Integer hostPorts, Long ramMemory, Long diskQuota, Long createTime, Boolean premiumStatus, String type, Integer status, String docker_id) {
62-
this.name = name;
63-
this.image = image;
64-
this.exposedPorts = exposedPorts;
65-
this.hostPorts = hostPorts;
66-
this.ramMemory = ramMemory;
67-
this.diskQuota = diskQuota;
68-
this.createTime = createTime;
69-
this.premiumStatus = premiumStatus;
70-
this.type = type;
71-
this.status = status;
72-
this.docker_id = docker_id;
73-
}
52+
@Column(name = "create_time")
53+
private Long createTime;
7454

7555
public Integer getId() {
7656
return id;
@@ -88,6 +68,14 @@ public void setName(String name) {
8868
this.name = name;
8969
}
9070

71+
public String getIdDocker() {
72+
return idDocker;
73+
}
74+
75+
public void setIdDocker(String idDocker) {
76+
this.idDocker = idDocker;
77+
}
78+
9179
public Images getImage() {
9280
return image;
9381
}
@@ -128,43 +116,47 @@ public void setDiskQuota(Long diskQuota) {
128116
this.diskQuota = diskQuota;
129117
}
130118

131-
public Long getCreateTime() {
132-
return createTime;
133-
}
134-
135-
public void setCreateTime(Long createTime) {
136-
this.createTime = createTime;
137-
}
138-
139-
public Boolean getPremiumStatus() {
140-
return premiumStatus;
141-
}
142-
143-
public void setPremiumStatus(Boolean premiumStatus) {
144-
this.premiumStatus = premiumStatus;
119+
public Integer getStatus() {
120+
return status;
145121
}
146122

147-
public String getType() {
148-
return type;
123+
public void setStatus(Integer status) {
124+
this.status = status;
149125
}
150126

151-
public void setType(String type) {
152-
this.type = type;
127+
public Long getCreateTime() {
128+
return createTime;
153129
}
154130

155-
public Integer getStatus() {
156-
return status;
131+
public void setCreateTime(Long createTime) {
132+
this.createTime = createTime;
157133
}
158134

159-
public void setStatus(Integer status) {
135+
public Containers(String name, String idDocker, Images image, Integer exposedPorts, Integer hostPorts, Long ramMemory, Long diskQuota, Integer status, Long createTime) {
136+
this.name = name;
137+
this.idDocker = idDocker;
138+
this.image = image;
139+
this.exposedPorts = exposedPorts;
140+
this.hostPorts = hostPorts;
141+
this.ramMemory = ramMemory;
142+
this.diskQuota = diskQuota;
160143
this.status = status;
144+
this.createTime = createTime;
161145
}
162146

163-
public String getDocker_id() {
164-
return docker_id;
165-
}
166-
167-
public void setDocker_id(String docker_id) {
168-
this.docker_id = docker_id;
147+
@Override
148+
public String toString() {
149+
return "Containers{" +
150+
"id=" + id +
151+
", name='" + name + '\'' +
152+
", docker_id='" + idDocker + '\'' +
153+
", image=" + image +
154+
", exposedPorts=" + exposedPorts +
155+
", hostPorts=" + hostPorts +
156+
", ramMemory=" + ramMemory +
157+
", diskQuota=" + diskQuota +
158+
", status=" + status +
159+
", createTime=" + createTime +
160+
'}';
169161
}
170162
}

src/main/java/pl/simplemethod/codebin/model/Images.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Images {
1010

1111
@Id
1212
@GeneratedValue(strategy = GenerationType.IDENTITY)
13-
@Column(name = "id_images")
13+
@Column(name = "id")
1414
private Integer id;
1515

1616
@NonNull
@@ -21,14 +21,6 @@ public class Images {
2121
@Column(name = "type")
2222
private String type;
2323

24-
@NonNull
25-
@Column(name = "docker_id")
26-
private String docker_id;
27-
28-
@NonNull
29-
@Column(name = "create_time")
30-
private Long createTime;
31-
3224
public Integer getId() {
3325
return id;
3426
}
@@ -53,26 +45,19 @@ public void setType(String type) {
5345
this.type = type;
5446
}
5547

56-
public String getDocker_id() {
57-
return docker_id;
58-
}
59-
60-
public void setDocker_id(String docker_id) {
61-
this.docker_id = docker_id;
48+
@Override
49+
public String toString() {
50+
return "Images{" +
51+
"id=" + id +
52+
", name='" + name + '\'' +
53+
", type='" + type + '\'' +
54+
'}';
6255
}
6356

64-
public Long getCreateTime() {
65-
return createTime;
66-
}
67-
68-
public void setCreateTime(Long createTime) {
69-
this.createTime = createTime;
70-
}
71-
72-
public Images(String name, String type, String docker_id, Long createTime) {
57+
public Images(String name, String type) {
7358
this.name = name;
7459
this.type = type;
75-
this.docker_id = docker_id;
76-
this.createTime = createTime;
7760
}
61+
62+
public Images(){}
7863
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package pl.simplemethod.codebin.model;
2+
3+
import javax.persistence.*;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
@Entity
8+
@Table(name = "users")
9+
public class Users {
10+
11+
@Id
12+
@GeneratedValue(strategy = GenerationType.IDENTITY)
13+
@Column(name = "id")
14+
private Integer id;
15+
16+
@Column(unique = true, nullable = false)
17+
private String token;
18+
19+
@Column(unique = true)
20+
private String subscription;
21+
22+
@OneToMany
23+
List<Containers> containers = new ArrayList<>();
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package pl.simplemethod.codebin.repository;
2+
3+
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.stereotype.Repository;
6+
import org.springframework.transaction.annotation.Transactional;
7+
import pl.simplemethod.codebin.model.Containers;
8+
9+
import java.util.List;
10+
11+
12+
@Repository
13+
@Transactional
14+
public interface ContainersRepository extends JpaRepository<Containers, Long> {
15+
16+
List<Containers> getById(Integer id);
17+
18+
List<Containers> getByHostPorts(Integer ports);
19+
20+
List<Containers> getByIdDocker(String docker_id);
21+
22+
}
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
package pl.simplemethod.codebin.repository;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4-
import org.springframework.data.jpa.repository.Query;
54
import org.springframework.stereotype.Repository;
5+
import org.springframework.transaction.annotation.Transactional;
66
import pl.simplemethod.codebin.model.Images;
77

88
import java.util.List;
9+
10+
911
@Repository
10-
public interface ImagesRepository extends JpaRepository<Images, Integer> {
12+
@Transactional
13+
public interface ImagesRepository extends JpaRepository<Images, Long> {
14+
15+
List<Images> getById(Integer id);
1116

12-
@Query(value = "SELECT * FROM images u WHERE u.id_images = ?1", nativeQuery = true)
13-
List<Images> getById(Integer id);
17+
List<Images> getByName(String name);
1418

15-
@Query(value = "SELECT * FROM images u WHERE u.name = ?1", nativeQuery = true)
16-
List<Images> getByName(String name);
19+
Images getFirstByName(String name);
1720

18-
@Query(value = "SELECT * FROM images u WHERE u.type = ?1", nativeQuery = true)
19-
List<Images> getByType(String type);
21+
List<Images> getByType(String type);
2022

21-
@Query(value = "SELECT * FROM images u WHERE u.docker_id = ?1", nativeQuery = true)
22-
List<Images> getbyDockerID(String type);
2323

24-
@Query(value = "SELECT * FROM images u ", nativeQuery = true)
25-
List<Images> getAll();
2624
}

0 commit comments

Comments
 (0)