-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About Creating Database Issues #212
Comments
The exception is caused by a “null” root. This may be caused by a previous start of the storage with the root object not supplied or being null. or set the root explicitly: final EmbeddedStorageManager storageManager = EmbeddedStorage.start(Paths.get("data"));
Object loadedRoot = storageManager.root();
if(loadedRoot == null) {
System.out.println("Storage root is null");
storageManager.setRoot(new DataRoot());
storageManager.storeRoot();
}
final DataRoot root = (DataRoot) storageManager.root(); |
Can data loading only be done through Lazy? |
By default, the complete object graph (starting with the defined root) is loaded into memory when the storage starts. |
I always use it directly |
After the storage has started all data (except the lazy referenced data) is available in memory. Here is simple example that loads and stores some data: public class SimpleExample {
public static class MyRoot {
private List<UUID> data = new ArrayList<>();
public void add(UUID uuid) {
this.data.add(uuid);
}
public List<UUID> getList() {
return this.data;
}
}
public static void main(String[] args) {
//start storageManager
EmbeddedStorageManager storage = EmbeddedStorage.start(Paths.get("SimpleExample"));
//Init storage root if not yet done
if(storage.root() == null) {
storage.setRoot(new MyRoot());
storage.storeRoot();
}
//get storage root object
MyRoot myRoot = (MyRoot) storage.root();
//read loaded data
System.out.println("Data loaded: " + myRoot.getList());
//add an item
myRoot.add(UUID.randomUUID());
//store the modified object
storage.store(myRoot.getList());
//shutdown storage
storage.shutdown();
}
} |
How can I avoid generating logs or other files every time I load data? Every time I load data from a certain directory, a file is generated, which takes up a lot of space |
Can you please provide more details on the generated file like its name and location? |
In the channel_1 directory, some dat files will be generated when saving data. If saved repeatedly, the generated dat file will be about twice as large as before |
If possible, can I delete all the original files before storing Data and then re store Data? |
The “.dat” files contain the stored data. Every store appends its data to those files. Deleting an object is done by removing all references to it and persisting those modifications. The deleted data will be removed from the storage files by the storage garbage collector later, see Housekeeping for details. //deleting the first element by removing all references and storing the modification
myRoot.getList().remove(0);
storage.store(myRoot.getList()); If you want to delete an old storage completely you can delete the whole storage directory (the one that contains the channel_x directories) and all its content only if the storage is shut down. Do not delete the “.dat” files only, this will corrupt the storage. |
Is it true that creating it takes a lot of time? |
EmbeddedStorageFoundation<?> foundation = EmbeddedStorageConfiguration.Builder()
|
Excuse me, if I directly use the following case, I will report a null exception. What is the problem?
//Application specific root instance
Final DataRoot root=new DataRoot();
//Initialize a storage manager ("the database") with the given directory
Final Embedded Storage Manager storageManager=Embedded Storage. start(
Root,//root object
Paths. get ("data")//Storage directory
);
The text was updated successfully, but these errors were encountered: