Skip to content

Commit

Permalink
remove BaseClient
Browse files Browse the repository at this point in the history
it's useless
  • Loading branch information
HSGamer committed Sep 11, 2024
1 parent 1f7ff76 commit 4e8bd2f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import me.hsgamer.hscore.database.Driver;
import me.hsgamer.hscore.database.Setting;
import me.hsgamer.hscore.database.client.sql.BaseSqlClient;
import me.hsgamer.hscore.database.client.sql.SqlClient;
import me.hsgamer.hscore.database.driver.h2.H2BaseDriver;
import org.h2.jdbcx.JdbcDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class H2Client extends BaseSqlClient<JdbcDataSource> {
public class H2Client implements SqlClient<JdbcDataSource> {
private final Setting setting;
private final JdbcDataSource dataSource;

/**
Expand All @@ -18,7 +19,7 @@ public class H2Client extends BaseSqlClient<JdbcDataSource> {
* @param setting the setting
*/
public H2Client(Setting setting) {
super(setting);
this.setting = setting;
Driver driver = setting.getDriver();
if (!(driver instanceof H2BaseDriver)) {
throw new IllegalArgumentException("The driver must be H2");
Expand All @@ -29,6 +30,11 @@ public H2Client(Setting setting) {
dataSource.setPassword(setting.getPassword());
}

@Override
public Setting getSetting() {
return setting;
}

@Override
public JdbcDataSource getOriginal() {
return dataSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.hsgamer.hscore.database.client.hibernate;

import me.hsgamer.hscore.database.BaseClient;
import me.hsgamer.hscore.database.Client;
import me.hsgamer.hscore.database.Driver;
import me.hsgamer.hscore.database.Setting;
import org.hibernate.SessionFactory;
Expand All @@ -12,7 +12,8 @@
/**
* The Hibernate client
*/
public class HibernateClient extends BaseClient<Configuration> {
public class HibernateClient implements Client<Configuration> {
private final Setting setting;
private final Configuration configuration;

/**
Expand All @@ -21,7 +22,7 @@ public class HibernateClient extends BaseClient<Configuration> {
* @param setting the setting
*/
public HibernateClient(Setting setting) {
super(setting);
this.setting = setting;
Driver driver = setting.getDriver();

this.configuration = new Configuration()
Expand All @@ -33,6 +34,11 @@ public HibernateClient(Setting setting) {
setting.getClientProperties().forEach((key, value) -> configuration.setProperty(key, value.toString()));
}

@Override
public Setting getSetting() {
return setting;
}

@Override
public Configuration getOriginal() {
return configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import me.hsgamer.hscore.database.Driver;
import me.hsgamer.hscore.database.LocalDriver;
import me.hsgamer.hscore.database.Setting;
import me.hsgamer.hscore.database.client.sql.BaseSqlClient;
import me.hsgamer.hscore.database.client.sql.SqlClient;

import java.sql.Connection;
import java.sql.SQLException;

/**
* The SQL client with HikariCP
*/
public class HikariSqlClient extends BaseSqlClient<HikariDataSource> {
public class HikariSqlClient implements SqlClient<HikariDataSource> {
private final Setting setting;
private final HikariDataSource hikariDataSource;

/**
Expand All @@ -22,7 +23,7 @@ public class HikariSqlClient extends BaseSqlClient<HikariDataSource> {
* @param setting the setting
*/
public HikariSqlClient(Setting setting) {
super(setting);
this.setting = setting;
Driver driver = setting.getDriver();
final HikariConfig config = new HikariConfig();
config.setDriverClassName(driver.getDriverClassName());
Expand Down Expand Up @@ -50,6 +51,11 @@ public HikariSqlClient(Setting setting) {
this.hikariDataSource = new HikariDataSource(config);
}

@Override
public Setting getSetting() {
return setting;
}

@Override
public HikariDataSource getOriginal() {
return hikariDataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.hsgamer.hscore.database.Driver;
import me.hsgamer.hscore.database.Setting;
import me.hsgamer.hscore.database.client.sql.BaseSqlClient;
import me.hsgamer.hscore.database.client.sql.SqlClient;

import java.sql.Connection;
import java.sql.DriverManager;
Expand All @@ -12,7 +12,8 @@
/**
* The SQL client with the Java's Driver Manager
*/
public class JavaSqlClient extends BaseSqlClient<Properties> {
public class JavaSqlClient implements SqlClient<Properties> {
private final Setting setting;
private final Properties properties;
private final String dbURL;
private final java.sql.Driver sqlDriver;
Expand All @@ -23,7 +24,7 @@ public class JavaSqlClient extends BaseSqlClient<Properties> {
* @param setting the setting
*/
public JavaSqlClient(Setting setting) {
super(setting);
this.setting = setting;
Driver driver = setting.getDriver();
this.properties = new Properties();
try {
Expand All @@ -37,6 +38,11 @@ public JavaSqlClient(Setting setting) {
this.dbURL = driver.convertURL(setting);
}

@Override
public Setting getSetting() {
return setting;
}

@Override
public Connection getConnection() throws SQLException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import me.hsgamer.hscore.database.BaseClient;
import me.hsgamer.hscore.database.Client;
import me.hsgamer.hscore.database.Driver;
import me.hsgamer.hscore.database.Setting;

Expand All @@ -13,7 +13,8 @@
/**
* The JPA persistence client
*/
public class PersistenceClient extends BaseClient<EntityManagerFactory> {
public class PersistenceClient implements Client<EntityManagerFactory> {
private final Setting setting;
private final EntityManagerFactory entityManagerFactory;

/**
Expand All @@ -23,7 +24,7 @@ public class PersistenceClient extends BaseClient<EntityManagerFactory> {
* @param setting The setting of the persistence client
*/
public PersistenceClient(String name, Setting setting) {
super(setting);
this.setting = setting;
Driver driver = setting.getDriver();
Map<String, Object> properties = new HashMap<>();
properties.put("jakarta.persistence.jdbc.url", driver.convertURL(setting));
Expand All @@ -34,6 +35,11 @@ public PersistenceClient(String name, Setting setting) {
this.entityManagerFactory = Persistence.createEntityManagerFactory(name, properties);
}

@Override
public Setting getSetting() {
return setting;
}

@Override
public EntityManagerFactory getOriginal() {
return entityManagerFactory;
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 4e8bd2f

Please sign in to comment.