-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connecting to the database has been improved
From now SQLite is a default database
- Loading branch information
Showing
9 changed files
with
100 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
# Project exclude paths | ||
/out/ | ||
/target/ | ||
/T-DataBasesAPI.iml | ||
/T-DataBasesAPI.iml | ||
/database.db | ||
/.idea/ | ||
/javadocs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/pl/timsixth/databasesapi/database/DatabaseConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package pl.timsixth.databasesapi.database; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
|
||
public final class DatabaseConnector { | ||
|
||
/** | ||
* Connects to database | ||
* | ||
* @param dataBase database to connect | ||
* @throws SQLException when can not connect to database | ||
* @throws IOException when can not create file | ||
* @throws ClassNotFoundException when can not find database driver | ||
*/ | ||
public static void connect(IDataBase dataBase) throws SQLException, IOException, ClassNotFoundException { | ||
if (dataBase instanceof ISQLite) { | ||
ISQLite sqlLite = (ISQLite) dataBase; | ||
|
||
File database = sqlLite.createDataBase(dataBase.getDataBase() + ".db"); | ||
sqlLite.openConnection(database); | ||
return; | ||
} | ||
|
||
dataBase.openConnection(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/pl/timsixth/databasesapi/database/DatabaseFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package pl.timsixth.databasesapi.database; | ||
|
||
import org.bukkit.configuration.file.FileConfiguration; | ||
import pl.timsixth.databasesapi.DatabasesApiPlugin; | ||
import pl.timsixth.databasesapi.database.type.MySQL; | ||
import pl.timsixth.databasesapi.database.type.SQLite; | ||
|
||
public final class DatabaseFactory { | ||
|
||
/** | ||
* Creates database instance | ||
* | ||
* @param dataBaseType type from config.yml | ||
* @param databasesApiPlugin database api plugin, to get config | ||
* @return created database instance | ||
*/ | ||
public static IDataBase createDatabase(DataBaseType dataBaseType, DatabasesApiPlugin databasesApiPlugin) { | ||
FileConfiguration fileConfiguration = databasesApiPlugin.getConfig(); | ||
|
||
if (dataBaseType == DataBaseType.MYSQL) { | ||
ISQLDataBase mysql = new MySQL(); | ||
mysql.setDataBase(fileConfiguration.getString("database")); | ||
mysql.setHostname(fileConfiguration.getString("hostname")); | ||
mysql.setPassword(fileConfiguration.getString("password")); | ||
mysql.setPort(fileConfiguration.getInt("port")); | ||
mysql.setUsername(fileConfiguration.getString("username")); | ||
|
||
return mysql; | ||
} | ||
|
||
ISQLite sqlite = new SQLite(databasesApiPlugin); | ||
sqlite.setDataBase(fileConfiguration.getString("database")); | ||
|
||
return sqlite; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: T-DatabasesApi | ||
main: pl.timsixth.databasesapi.DatabasesApiPlugin | ||
version: '1.9.2' | ||
version: '1.10.0' | ||
author: timsixth |