[LIB] PersistenceLib - Easily save your objects! [MySQL] [SQLite]

Discussion in 'Resources' started by ELCHILEN0, Mar 17, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ELCHILEN0

    Introduction:
    PersistenceLib is an easy to use Object Relational Mapping tool for storing your POJO's in any type of database! It features database creation, alteration, inserts, updates deletes and cascading relationships! This was created initially as a fork of alta189's SimpleSave. Please note: This library is in its alpha stage and is not near as polished as it will eventually be!

    Usage:
    1. Prepare a connection with the desired database.
    Code:
    MySQLConfiguration configuration = new MySQLConfiguration();
     
    configuration.setHost("localhost")
                    .setPort("3306")
                    .setDatabase("database")
                    .setUsername("username")
                    .setPassword("password");
     
    MySQLDatabase database = new MySQLDatabase(configuration);
    2. (Optional) Register the classes that will be saved.
    Code:
    try {
            database.registerTable(Employee.class);
    } catch (TableRegistrationException e) {
            e.printStackTrace();
    }
    3. Connect to the database.
    Code:
    database.connect();
    4. Load, Save or Drop your Objects!
    Code:
    ArrayList<Employee> employees = database.findAll(Employee.class);
     
    ArrayList<Employee> employeesCriteria = database.findBy(Employee.class, "id = 1");
     
     
    database.saveAll(employees);
    database.saveAll(employeesCriteria);
     
    database.dropAll(employees);
    database.dropAll(employeesCriteria);
    5. Disconnect from the database.
    Code:
    database.disconnect();
    Download:
    The latest source can be found here!
    * Pull requests are appreciated!​

    Changelog:
    Code:
    (+) Change, (-) Deletion,(=) Bugfix, (!) Modification
    Version 1.0.1
    - (+) Added support for TIME and TIMESTAMP.
     
    Version 1.1.0
    - (+) Added transactions.
     
    Version 1.0.1
    - (+) Added optional CascadeType to relationship mappings.
    - (=) Changed SQLite types.
     
    Version 1.0.0
    - (=) Initial release!
    Extra:
    I hope you find this useful and helps you in any of your projects!

    Recent Changes:
    Version 1.0.1
    - (+) Added support for TIME and TIMESTAMP.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    beastman3226

    Does this store every one of the initialized objects?
     
  3. Offline

    ELCHILEN0

    It does not store any objects in the database unless the object is explicitly saved. You can choose which objects you want saved.
     
  4. Offline

    microgeek

    Brilliant!
     
  5. Offline

    beastman3226

    ELCHILEN0 I don't understand the function of the methods is what I meant.
     
  6. Offline

    ELCHILEN0

    Thanks!
    The library gives an easy way to persist objects in non-relational databases. It handles everything from creating tables to inserting, updating or deleting entries as well as child entries annotated in your objects. To save an object you simply do database.save(o). This will handle all child objects as well as the appropriate inserts, updates or deletes. Essentially it gives you a way to persist objects without writing a single line of SQL.
     
  7. Offline

    Rprrr

    ELCHILEN0
    Nice! I will probably use this in one of my plugins in the near future. At the looks of it, it's pretty awesome, so I can't wait to use this. :)!
     
  8. Offline

    ELCHILEN0

    Thats great to hear! If you have any trouble with it dont hesitate to ask :)
     
  9. Offline

    MiniDigger

    ELCHILEN0 can you post the Employee class? I fail at createing my own. It always says ' Class 'myclass' does not have an Id annotation present.' What am I doing wrong?
     
Thread Status:
Not open for further replies.

Share This Page