Skip to content

Commit

Permalink
frick comments, frick javadocs and frick compiler for complaining it
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathGOD7 committed Apr 17, 2024
1 parent 5f99e12 commit 9f82059
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 63 deletions.
25 changes: 25 additions & 0 deletions src/main/java/io/github/deathgod7/SE7ENLib/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This file is part of SE7ENLib, created on 17/04/2024 (18:01 PM)
// Name : Logger
// Author : Death GOD 7

package io.github.deathgod7.SE7ENLib;

import io.github.deathgod7.SE7ENLib.database.DatabaseManager;

/**
* Represents the Logger
* @version 1.0
* @since 1.0
*/
public class Logger {
/**
* Util function to log the message
* @param message The message to log
*/
public static void log(String message) {
boolean x = DatabaseManager.getInstance().getDebugMode();
if (x) {
System.out.println(message);
}
}
}
156 changes: 143 additions & 13 deletions src/main/java/io/github/deathgod7/SE7ENLib/database/DatabaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,204 @@
*/
public class DatabaseManager {
private static DatabaseManager _dbmInstance;
/**
* Get the instance of DatabaseManager
* @return {@link DatabaseManager}
*/
public static DatabaseManager getInstance() {
return _dbmInstance;
}

private SQLite _sqlite;
/**
* Get the SQLite
* @return {@link SQLite}
*/
public SQLite getSQLite() { return this._sqlite; }
private MySQL _mysql;
/**
* Get the MySQL
* @return {@link MySQL}
*/
public MySQL getMySQL() { return this._mysql; }

private MongoDB _mongodb;
/**
* Get the MongoDB
* @return {@link MongoDB}
*/
public MongoDB getMongoDB() {
return this._mongodb;
}

private DatabaseInfo _dbInfo;

/**
* Get the DatabaseInfo
* @return {@link DatabaseInfo}
*/
public DatabaseInfo getDbInfo() {
return this._dbInfo;
}

/**
* Check if the database is connected
* @return {@link Boolean}
*/
public boolean isConnected() {
return (this.getConnection() != null);
}

private boolean debugMode = false;

/**
* Set the debug mode
* @param value The value to set
*/
public void setDebugMode(boolean value) {
this.debugMode = value;
}

/**
* Check the debug mode
* @return {@link Boolean}
*/
public boolean getDebugMode() {
return this.debugMode;
}

/**
* Get the connection of database
* @return {@link Object}
*/
public Object getConnection() {
if (_dbInfo.getDbType() == DatabaseType.SQLite) {
return _sqlite.getConnection();
}
else if (_dbInfo.getDbType() == DatabaseType.MySQL){
// to do mysql support
return _mysql.getConnection();
} else if (_dbInfo.getDbType() == DatabaseType.MongoDB) {
return _mongodb.getConnection();
}
else {
return null;
}
if (_dbInfo.getDbType() == DatabaseType.SQLite) { return this.getSQLite().getConnection(); }
else if (_dbInfo.getDbType() == DatabaseType.MySQL){ return this.getMySQL().getConnection(); }
else if (_dbInfo.getDbType() == DatabaseType.MongoDB) { return this.getMongoDB().getConnection(); }
else { return null; }
}

/**
* Get the database (all)
* @return {@link Object}
*/
public Object getDatabase() {
if (_dbInfo.getDbType() == DatabaseType.SQLite) { return this.getSQLite(); }
else if (_dbInfo.getDbType() == DatabaseType.MySQL){ return this.getMySQL(); }
else if (_dbInfo.getDbType() == DatabaseType.MongoDB) { return this.getMongoDB(); }
else { return null; }
}

/**
* Get the database name
* @return {@link String}
*/
public String getDBName() {
return this._dbInfo.getDbName();
}

/**
* Represents the Data Type
*/
public enum DataType {
/**
* Varchar Data Type
*/
VARCHAR,
/**
* Text Data Type
*/
TEXT,
/**
* Integer Data Type
*/
INTEGER,
/**
* Boolean Data Type
*/
BOOLEAN,
/**
* Float Data Type
*/
FLOAT,
/**
* Double Data Type
*/
DOUBLE,
/**
* Date Data Type
*/
DATE,
/**
* Time Data Type
*/
TIME,
/**
* DateTime Data Type
*/
DATETIME,

// MongoDB Special
/**
* Array Data Type
*/
ARRAY,
/**
* Document Data Type
*/
DOCUMENT,
/**
* ObjectID Data Type
*/
OBJECTID
}

/**
* Represents the Order Type
*/
public enum OrderType {
/**
* Ascending Order
*/
ASCENDING,
/**
* Descending Order
*/
DESCENDING
}

/**
* Represents the Database Type
*/
public enum DatabaseType {
/**
* SQLite Database
*/
MySQL,
/**
* MySQL Database
*/
SQLite,
/**
* MongoDB Database
*/
MongoDB
}

/**
* DatabaseManager constructor that takes DatabaseInfo
* @param dbinfo The DatabaseInfo object
*/
public DatabaseManager(DatabaseInfo dbinfo){
_dbmInstance = this;
loadDB(dbinfo);
}


/**
* Close the SQL connection
* @param ps The PreparedStatement
* @param rs The ResultSet
*/
public void closeConnection(PreparedStatement ps, ResultSet rs) {
try {
if (ps != null)
Expand All @@ -102,6 +224,10 @@ public void closeConnection(PreparedStatement ps, ResultSet rs) {
}
}

/**
* Load the database based on the DatabaseInfo
* @param dbinfo The DatabaseInfo object provided while creating instance of this class
*/
private void loadDB(DatabaseInfo dbinfo) {
_dbInfo = dbinfo;

Expand All @@ -123,6 +249,10 @@ else if (dbinfo.getDbType() == DatabaseType.MongoDB){
}
}

/**
* Get the tables from the database
* @return {@link LinkedHashMap}
*/
public LinkedHashMap<String, Table> getTables() {
if (_dbInfo.getDbType() == DatabaseType.SQLite) {
return _sqlite.getTables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,59 +124,114 @@ private int getBoolInt(boolean bool) {
return bool ? 1 : 0;
}

/**
* Get the name of the column
* @return {@link String}
*/
public String getName() {
return this.name;
}

/**
* Set the name of the column
* @param name The name of the column
*/
public void setName(String name) {
this.name = name;
}

/**
* Get the data type of the column
* @return {@linkplain DataType}
*/
public DataType getDataType() {
return this.dataType;
}

/**
* Set the data type of the column
* @param dataType The data type of the column
*/
public void setDataType(DataType dataType) {
this.dataType = dataType;
}

/**
* Get the limit of the column
* @return {@link int}
*/
public int getLimit() {
return this.limit;
}

/**
* Set the limit of the column
* @param limit The limit of the column
*/
public void setLimit(int limit) {
this.limit = limit;
}

/**
* Get the value of the column
* @return {@link Object}
*/
public Object getValue() {
return this.value;
}

/**
* Set the value of the column
* @param value The value of the column
*/
public void setValue(Object value) {
this.value = value;
}


/**
* Get if the column is nullable
* @return {@link boolean}
*/
public boolean isNullable() {
return this.isNullable;
}

/**
* Set if the column is nullable
* @param value The boolean to enable or disable nullable
*/
public void setNullable(boolean value) {
this.isNullable = value;
}

/**
* Get if the column is auto increment
* @return {@link boolean}
*/
public boolean isAutoIncrement() {
return this.autoIncrement;
}

/**
* Set if the column is auto increment
* @param value The boolean value to enable or disable auto increment
*/
public void setAutoIncrement(boolean value) {
this.autoIncrement = value;
}

/**
* Get the default value of the column
* @return {@link Object}
*/
public Object getDefaultValue() {
return this.defaultValue;
}

/**
* Set the default value of the column
* @param value The default value of the column
*/
public void setDefaultValue(Object value) {
this.defaultValue = value;
}
Expand Down
Loading

0 comments on commit 9f82059

Please sign in to comment.