+ Creating Database connection
+ POJOs for: - Address - Author - Book - Category - Customer - Publisher Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
parent
1ca0791cde
commit
aab20c1c48
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.iml
|
||||
/target
|
||||
.idea
|
||||
config.json
|
||||
|
9
config.json.example
Normal file
9
config.json.example
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"database": {
|
||||
"hostname": "localhost",
|
||||
"port": 3306,
|
||||
"database": "itech",
|
||||
"username": "itech",
|
||||
"password": "123456"
|
||||
}
|
||||
}
|
39
src/main/java/de/hsel/itech/config/Configuration.java
Normal file
39
src/main/java/de/hsel/itech/config/Configuration.java
Normal file
@ -0,0 +1,39 @@
|
||||
package de.hsel.itech.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Configuration {
|
||||
|
||||
private Database database;
|
||||
|
||||
|
||||
public static Configuration get(String fileName) {
|
||||
Gson gson = new Gson();
|
||||
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(new File(fileName));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assert reader != null;
|
||||
return gson.fromJson(reader, Configuration.class);
|
||||
}
|
||||
|
||||
}
|
23
src/main/java/de/hsel/itech/config/Database.java
Normal file
23
src/main/java/de/hsel/itech/config/Database.java
Normal file
@ -0,0 +1,23 @@
|
||||
package de.hsel.itech.config;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Database {
|
||||
|
||||
String hostname;
|
||||
int port;
|
||||
String database;
|
||||
String username;
|
||||
String password;
|
||||
}
|
42
src/main/java/de/hsel/itech/db/Database.java
Normal file
42
src/main/java/de/hsel/itech/db/Database.java
Normal file
@ -0,0 +1,42 @@
|
||||
package de.hsel.itech.db;
|
||||
|
||||
import de.hsel.itech.config.Configuration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
public class Database {
|
||||
|
||||
public Database() {
|
||||
try {
|
||||
Class.forName("com.mariadb.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Connection getConnection() {
|
||||
Configuration config = Configuration.get("config.json");
|
||||
try {
|
||||
return DriverManager.getConnection("jdbc:mariadb://" + config.getDatabase().getHostname() + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase(), config.getDatabase().getUsername(), config.getDatabase().getPassword());
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
23
src/main/java/de/hsel/itech/db/pojo/Address.java
Normal file
23
src/main/java/de/hsel/itech/db/pojo/Address.java
Normal file
@ -0,0 +1,23 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Address {
|
||||
|
||||
private Customer customer;
|
||||
private long id;
|
||||
private String name;
|
||||
private String street;
|
||||
private String number;
|
||||
private int zipCode;
|
||||
private String city;
|
||||
}
|
19
src/main/java/de/hsel/itech/db/pojo/Author.java
Normal file
19
src/main/java/de/hsel/itech/db/pojo/Author.java
Normal file
@ -0,0 +1,19 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Author {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
}
|
34
src/main/java/de/hsel/itech/db/pojo/Book.java
Normal file
34
src/main/java/de/hsel/itech/db/pojo/Book.java
Normal file
@ -0,0 +1,34 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Year;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Book {
|
||||
|
||||
private int isbn;
|
||||
private Author author;
|
||||
private Publisher publisher;
|
||||
private Category category;
|
||||
private String title;
|
||||
private Year year;
|
||||
|
||||
/**
|
||||
* saved in cents
|
||||
*/
|
||||
private int price;
|
||||
private String description;
|
||||
private String image;
|
||||
|
||||
|
||||
|
||||
}
|
19
src/main/java/de/hsel/itech/db/pojo/Category.java
Normal file
19
src/main/java/de/hsel/itech/db/pojo/Category.java
Normal file
@ -0,0 +1,19 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Category {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String image;
|
||||
}
|
21
src/main/java/de/hsel/itech/db/pojo/Customer.java
Normal file
21
src/main/java/de/hsel/itech/db/pojo/Customer.java
Normal file
@ -0,0 +1,21 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Customer {
|
||||
|
||||
private long id;
|
||||
private String email;
|
||||
private String name;
|
||||
private String password;
|
||||
private boolean admin;
|
||||
}
|
18
src/main/java/de/hsel/itech/db/pojo/Publisher.java
Normal file
18
src/main/java/de/hsel/itech/db/pojo/Publisher.java
Normal file
@ -0,0 +1,18 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Publisher {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
}
|
Loading…
Reference in New Issue
Block a user