Loading and Saving Tutorial
Loading and saving are the easiest part in using the SQLObjectConverter because they do not involve customizations and configurations.
First, create an SQLObjectConverter object, providing a connection with database selected through the constructor. If any method inside the converter is called before selecting a database within the connection will cause a com.rcextract.minecord.sql.DatabaseAccessException.
- When the connection to the database is expired, a java.sql.SQLTimeoutException will be thrown.
- If any classes related to serialization do not meet the requirements, or an internal error occurs, a com.rcextract.minecord.sql.DataLoadException will be thrown.
- Finally, other exceptions thrown from methods called within the serialization and outside of the SQLObjectConverter class will also be thrown as java.lang.Throwable. (The exception is obtained thrown InvocationTargetException.getCause()).
If you want to save multiple objects with the same type at the same time, you can do the following:
First, obtain an SQLObjectConverter object. It can be done by using the previously created one or a new one with the same connection passed through the constructor. (An SQLObjectConverter can be used for saving or loading anytime. Fields inside the SQLObjectConverter are only caches loaded from the database to help loading data, and will be cleared once the called method type changed between serialization and deserialization.) Then, do loadObject(String, int, boolean).
Code (Java):converter.loadObject("string", 1, true);
- The first argument is used to determine the row in which table you want to load. If the class of the object serialized and saved into the table implements the SQLObjectConverter API, the name will be the value() returned from the annotation com.rcextract.minecord.sql.SerializableAs annotated on the class. Otherwise, the name will be the simple name of the class. All characters within it will not be capitalized.
- The second argument is used to determine which row you want to load in a table.
- Finally, the third argument is used to determine whether the row should be deleted after the object is successfully loaded.
If you want to load all objects from a table, you can do the following:
Finally, if you want to load all objects which is assignable from a specific type, you can do the following: