-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the SJDB wiki!
This Wiki will guide you into how to use SJDB.
Required acknowledgements:
-
Basic Java: You'll need to learn Java to use the SJDB API.
-
Java Reflection(Optional): Learn this if you need to do advanced operations with the SJDB API.
If you need help installing SJDB click here
If you only need to use the SJDB API you should go with Maven. If you don't have Maven, you should either get Maven or use Classpath method, but if you really need Maximum Flexibility and Dynamic loading, use Reflection.
This tutorial applies if you installed SJDB via Classpath or Maven methods
Creating and accessing a Database:
import io.github.demnetwork.sjdb.*
public class Main {
public static void main(String[] args) {
DatabaseManager mgr = new DatabaseManager(); // Creating a new Instance of DatabaseManager
try {
mgr.createDatabase("username", "password", "path/to/newDatabase.sdb"); // Creating a new Database
} catch (IOException e) {
System.out.println("Unable to create Database: ");
e.printStackTrace();
}
Database db = null;
try {
db = mgr.access("path/to/newDatabase.sdb", "username", "password");
} catch (Throwable t) {
System.out.println("Unable to access the Database");
t.printStackTrace();
}
if (db != null) {
System.out.println("\'Database.getRoot().toString()\' output: " + db.getRoot().toString());
}
}
}Don't worry if you don't know what this does right now, I'll explain you what this does later.
This tutorial applies if you installed SJDB via Reflection method
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;
public class Main {
private static int bn = 0;
public static void main(String[] args) throws Exception {
File f = new File("./SJDB/sjdb.jar"); // Get File Object
if (!f.exists()) {
throw new Error("Cannot find SJDB jar file"); // Throw error if file is not found
}
URLClassLoader cl = new URLClassLoader(new URL[] { f.toURI().toURL() }); // Create a class loader
Class<?> runtimeClass = cl.loadClass("io.github.demnetwork.sjdb.internal.SJDBRuntime"); // Get the SJDBRuntime class
bn = ((Integer) runtimeClass.getMethod("getBuildNumber").invoke(null)).intValue(); // Get the Build Number from SJDBRuntime
if (bn != 1) {
cl.close(); // Close URLClassLoader
throw new Error("Incompatible SJDB Version."); // Throw error due to incompatible version
}
Class<?> databaseManagerClass = cl.loadClass("io.github.demnetwork.sjdb.DatabaseManager");
Object databaseMgr = databaseManagerClass.getConstructor().newInstance();
Method dbCreate = databaseManagerClass.getMethod("createDatabase", String.class, String.class, String.class);
dbCreate.invoke(databaseMgr, "username", "password", "path/to/newDtabase.sdb");
Method dbAccess = databaseManagerClass.getMethod("access", String.class, String.class, String.class);
Object db = dbAccess.invoke("path/to/newDatabase.sdb", "username", "password");
Class<?> dbClass = cl.loadClass("io.github.demnetwork.sjdb.Database");
Class<?> dbRootClass = cl.loadClass("io.github.demnetwork.sjdb.dbelements.DBRootElement");
Object root = dbClass.getMethod("getRoot").invoke();
System.out.println("\'Database.getRoot().toString()\' result: " + root.toString());
}
}Don't worry if you don't know how the SJDB API works, I'll explain that later.
SJDB Is licensed under the MIT License, and by using the SJDB API you agree to the license below:
Copyright (c) 2024 Arthur Yoshikasu Arakaki
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The license above states that you can use, modify, and distribute the software, even commercially, as long as the license above is included.