-
Notifications
You must be signed in to change notification settings - Fork 0
Implementing_Sofof_en
Sofof implementation depends on the Server, ListInputStream, ListOutputStream. All the work is done in them which represented as saving, reading data, listening for commands and executing them. To start building a new implementation you should start with the server. This class doesn't have to follow any rules, but it should offer the services that the default sofof server is offering e.g: interpreting the sofof.xml file, having a users management system, etc. The user will use this class directly to manage the database.
The server basically should listen to the commands and executing them. This is done with listening to a certain port using the java.io.ServerSocket class. When a user wants to connect to the server the Session object will send to the server a User object that contains information about the user identity. The server should read that object and decide to accept the connection by sending true to the Session or rejecting the connection by sending false. If the server accepted the connection it could listen now fo the commands. The Session object will send true before sending the executable command object or false before sending the query object.
When the server receives a request for executing a command (executable or query) it should first check that the user is allowed to do that. This is done only if there is a SecuritryManager instance that is implementing the SofofSecurityManager interface. If there is a one you should pass the User object with the command object to the method checkQuery(User, Query) for queries or pass User object with the executable command object to the method checkExecutable(User, Executable) to the executable commands. These methods will throw a SecurityException when the user is not allowed to do that. You can write the exception to the client and the Session object will throw that exception in the client program.
To start executing commands (queries or executables) you can call the method that is doing the main work for the command and they are query and execute. The query for queries has a ListInputStream parameter and the execute has both the ListInputStream and ListOutputStream parameters. Calling these methods will return data that you should send it to the client. These methods also can throw exceptions and you can send it to the client if it occurs and it will be thrown in the client program. Notice: You can't send any exception to the client. Only SofofException and SecurityException are allowed.
This class should write objects on the database. It has other tasks like generating ID values (Have a look to the Objects Relations to know how the ID should be generated), starting transactions, committing and rolling back.
The class has a main method write that should write the objects on the database. This method receives a list of objects that should be saved, the binding name (it could have strange values like null or empty string. you can check that values using the Database.isNoName(String) to check if the binding name actually has no name. If that is true you can replace it with a certain name that you save all the objects that don't have a binding name like SofofNoName in the default implementation) and a Class object that all the objects that will be saved are instances of it. This class should then write the objects list on the old objects (if there is) that have the same binding name and the same class (other objects that have the same bindin name but are not instances of the same class won't be affected). Now you can write the objects in the way you want e.g: you can serialize the objects to XML or JSON form, encrypted, in other databases.
This service is managed using the methods startTransaction, commit and rollback. The transaction is started after calling the startTransaction method and is finished after calling commit or rollback. When the command calls the commit method it means that you should save all the changes that the command has made. When the command calls the rollback method it means that you should remove any changes the command has made on the database from the start of the transaction.
This class should read the data that the ListOutputStream has written. It has the read method that receives the binding name and the class that you should read it's objects. It has other tasks such as it should search for any ID object in the objects fields and the fields of the object fields etc (take into your account that you should search in the array's elements). If it founds a one in the fields of a certain object it should replace the old one that has the ID object with the object that the ID is referring to in the database. You should also put in your account the ability to two objects to reference each other in their fields. You should connect the two objects with so each one field is referring to the other object.