A simple tool for your database
Now we put all functionalities together.
First we have to create a database. After that, we have to ensure there is a connection to it. Accomplished these steps, we are able to operate within our database, namely setting and getting data.
public static void main(String[] args) throws IOException
{
String m_user = "admin"; // your user name
String m_password = "admin"; // your password
String m_dbpath = "path/orientdb/databases/"; // path to orientdb directory
String m_dbname = "University"; // name of your database
// Establish connection and create raw database
CDatabaseConnector db_connector = new CDatabaseConnector(m_user, m_password, m_dbpath+m_dbname);
db_connector.connect();
// set raw schema, class and index definitions
CDatabaseCreator db_creator = new CDatabaseCreator(db_connector.acquirePoolConnection());
db_creator.setRawClasses();
db_connector.releasePoolConnection();
// provide classes to get and set data in database
CDatabaseGetData db_getter = new CDatabaseGetData();
CDatabaseSetData db_setter = new CDatabaseSetData();
// load predefined classes into database
db_setter.setDatabase(db_connector.acquirePoolConnection());
db_setter.setPredefinedData();
db_connector.releasePoolConnection();
// user input
userInput(db_setter, db_getter, db_connector);
}
The CDatabaseConnector class establishes a connection either to an existing database, or builds up a new one. CDatabaseCreator sets the schema, indexes and classes. As an argument it gets passed a pool connection of our CDatabaseConnector class.
When these steps are done, we can create instances of CDatabaseGetData and CDatabaseSetData to provide accessibility to our database.
The method userInput() is executed until the user presses a defined key and gets userinput via the command shell.
The code of this little tool is provided below. With the subsections 4.1. to 4.5. you will have no problems to understand it and adapt it to your needs.
Hope you had fun and learned a few things.