File tree 6 files changed +67
-9
lines changed
src/main/java/nl/bascoder/keymanager
6 files changed +67
-9
lines changed Original file line number Diff line number Diff line change 1
1
-- rim of database
2
2
CREATE TABLE owner (
3
- id INT NOT NULL PRIMARY KEY ,
3
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ,
4
4
name VARCHAR (255 ) NOT NULL
5
5
);
6
6
7
7
CREATE TABLE device (
8
- id INT NOT NULL PRIMARY KEY ,
8
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ,
9
9
name VARCHAR (255 ) NOT NULL ,
10
- owner_id INT NOT NULL ,
10
+ owner_id INTEGER NOT NULL ,
11
11
FOREIGN KEY (owner_id) REFERENCES owner (id)
12
12
ON UPDATE CASCADE
13
13
ON DELETE CASCADE
14
14
);
15
15
16
16
CREATE TABLE key (
17
- id INT NOT NULL PRIMARY KEY ,
17
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT ,
18
18
license_key VARCHAR (255 ) NOT NULL ,
19
19
in_use BOOLEAN NOT NULL DEFAULT 0 ,
20
- device_id INT DEFAULT NULL ,
20
+ device_id INTEGER DEFAULT NULL ,
21
21
FOREIGN KEY (device_id) REFERENCES device (id)
22
22
ON UPDATE CASCADE
23
23
ON DELETE SET DEFAULT
@@ -26,4 +26,3 @@ CREATE TABLE key (
26
26
CREATE UNIQUE INDEX owner_name ON owner (name);
27
27
CREATE UNIQUE INDEX device_name ON device (name);
28
28
CREATE UNIQUE INDEX license_key_id ON key (license_key);
29
-
Original file line number Diff line number Diff line change 14
14
<artifactId >sqlite-jdbc</artifactId >
15
15
<version >3.8.7</version >
16
16
</dependency >
17
+ <dependency >
18
+ <groupId >com.j256.ormlite</groupId >
19
+ <artifactId >ormlite-core</artifactId >
20
+ <version >4.48</version >
21
+ </dependency >
22
+ <dependency >
23
+ <groupId >com.j256.ormlite</groupId >
24
+ <artifactId >ormlite-jdbc</artifactId >
25
+ <version >4.48</version >
26
+ </dependency >
27
+
17
28
</dependencies >
18
29
19
30
Original file line number Diff line number Diff line change 1
1
package nl .bascoder .keymanager ;
2
2
3
+ import com .j256 .ormlite .jdbc .JdbcConnectionSource ;
4
+ import com .j256 .ormlite .support .ConnectionSource ;
5
+
3
6
import org .sqlite .SQLiteJDBCLoader ;
4
7
5
8
import java .sql .Connection ;
@@ -52,6 +55,15 @@ public static DatabaseManager getInstance() {
52
55
return instance ;
53
56
}
54
57
58
+ /**
59
+ * Returns ConnectionSource object for ormlite
60
+ * @return ConnectionSource for ormlite
61
+ * @throws SQLException if a error occured with SQL
62
+ */
63
+ public ConnectionSource getConnectionSource () throws SQLException {
64
+ return new JdbcConnectionSource (CONNECTION_URL );
65
+ }
66
+
55
67
public synchronized Connection getConnection () throws SQLException {
56
68
try {
57
69
return DriverManager .getConnection (CONNECTION_URL );
Original file line number Diff line number Diff line change 1
1
package nl .bascoder .keymanager .entity ;
2
2
3
+ import com .j256 .ormlite .field .DatabaseField ;
4
+ import com .j256 .ormlite .table .DatabaseTable ;
5
+
3
6
/**
4
7
* @author Bas van Marwijk
5
- * @since 9-11-14
6
8
* @version 1.0 - creation
9
+ * @since 9-11-14
7
10
*/
11
+ @ DatabaseTable (tableName = "device" )
8
12
public class Device {
13
+ @ DatabaseField (generatedId = true )
9
14
private long id ;
15
+ @ DatabaseField
10
16
private String name ;
17
+ @ DatabaseField (foreign = true , canBeNull = false )
11
18
private Owner owner ;
12
19
13
20
/**
@@ -63,5 +70,10 @@ public Owner getOwner() {
63
70
public void setOwner (Owner owner ) {
64
71
this .owner = owner ;
65
72
}
73
+
74
+ @ Override
75
+ public String toString () {
76
+ return name ;
77
+ }
66
78
}
67
79
Original file line number Diff line number Diff line change 1
1
package nl .bascoder .keymanager .entity ;
2
2
3
+ import com .j256 .ormlite .field .DatabaseField ;
4
+ import com .j256 .ormlite .table .DatabaseTable ;
5
+
3
6
/**
4
7
* Entity containing license licenseKey.
5
8
*
6
9
* @author Bas van Marwijk
7
- * @since 9-11-14
8
10
* @version 1.0 - creation
11
+ * @since 9-11-14
9
12
*/
13
+ @ DatabaseTable (tableName = "key" )
10
14
public class Key {
15
+ @ DatabaseField (generatedId = true )
11
16
private long id ;
17
+ @ DatabaseField
12
18
private String licenseKey ;
19
+ @ DatabaseField
13
20
private boolean inUse ;
21
+ @ DatabaseField (foreign = true , canBeNull = false )
14
22
private Device device ;
15
23
16
24
/**
@@ -84,5 +92,10 @@ public Device getDevice() {
84
92
public void setDevice (Device device ) {
85
93
this .device = device ;
86
94
}
95
+
96
+ @ Override
97
+ public String toString () {
98
+ return licenseKey ;
99
+ }
87
100
}
88
101
Original file line number Diff line number Diff line change 1
1
package nl .bascoder .keymanager .entity ;
2
2
3
+ import com .j256 .ormlite .field .DatabaseField ;
4
+ import com .j256 .ormlite .table .DatabaseTable ;
5
+
3
6
/**
4
7
* @author Bas van Marwijk
5
- * @since 9-11-14
6
8
* @version 1.0 - creation
9
+ * @since 9-11-14
7
10
*/
11
+ @ DatabaseTable (tableName = "owner" )
8
12
public class Owner {
13
+ @ DatabaseField (generatedId = true )
9
14
private long id ;
15
+ @ DatabaseField
10
16
private String name ;
11
17
12
18
/**
@@ -44,5 +50,10 @@ public String getName() {
44
50
public void setName (String name ) {
45
51
this .name = name ;
46
52
}
53
+
54
+ @ Override
55
+ public String toString () {
56
+ return name ;
57
+ }
47
58
}
48
59
You can’t perform that action at this time.
0 commit comments