You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 9, 2024. It is now read-only.
Possibility to use different databases per StorageObject
Planned Features
Linking objects together by their id's (e.g. linking a user to a guild and just having the Guild object having the
user object inside it when loaded)
More database support (e.g. PostgreSQL, SQLite, etc.)
Example
publicclassExample {
publicstaticvoidmain(String[] args) {
System.out.println("------------ [ Example ] ------------");
// Create the database instance, this manages the connection to the databaseMySQLStorageDatabasedatabase = newMySQLStorageDatabase("localhost", 3306, "root", "password", "test");
// Create the service instance for the TestObjectMySQLStorageService<TestObject> service = newMySQLStorageService<>(database, TestObject.class);
// Startup the service so it can do some stuff that needs to be done before it can be usedservice.startupService();
// Create a new TestObject instance using the serviceTestObjecttestObject = service.createInstance();
// Let's log the object before we save itSystem.out.println("Before save: " + testObject);
// Save the object to the databaseservice.upsert(testObject);
// Now Let's set the testObject to null so we can load it from the database (first we get the id)intid = testObject.getId();
// Set the testObject to nulltestObject = null;
// Let's log the object before we load itSystem.out.println("Before load: " + testObject);
// Load the object from the databasetestObject = service.find(id);
// Let's log the object after we loaded itSystem.out.println("After load: " + testObject);
// Now change the name of the objecttestObject.setName("VertCode");
// Now let's save the object againservice.upsert(testObject);
// Let's log the object after we saved itSystem.out.println("After save: " + testObject);
// Now we set the object to null again and load it again to show that the name has changed in the databasetestObject = null;
// Load the object from the databasetestObject = service.find(id);
// Let's log the object after we loaded itSystem.out.println("After load: " + testObject);
// Now we know this works, let's delete the object from the databaseservice.delete(testObject);
// To show that the object is deleted, we set it to null again and load it againtestObject = null;
// Load the object from the databasetestObject = service.find(id);
// Let's log the object after we loaded itSystem.out.println("After load: " + testObject);
System.out.println("------------ [ Example ] ------------");
}
@NoArgsConstructor(force = true)
@Getter@Setter@StorageMetadata(
tableName = "example"
)
publicstaticclassTestObjectextendsStorageObject<Integer> {
@StorageId(
automaticallyGenerated = true
)
@StorageField(
columnName = "id"
)
@Setter(AccessLevel.NONE)
privateintid;
@StorageField(
columnName = "name"
)
privateStringname;
publicTestObject(Stringname) {
this.name = name;
}
@OverridepublicIntegergetIdentifier() {
returnthis.id;
}
@OverridepublicStringtoString() {
return"TestObject{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
}
About
A easy way to store objects to MySQL, MongoDB or JSON