SecondExample.java :  » Database-ORM » ODAL » com » completex » objective » persistency » examples » ex002 » Java Open Source

Java Open Source » Database ORM » ODAL 
ODAL » com » completex » objective » persistency » examples » ex002 » SecondExample.java
package com.completex.objective.persistency.examples.ex002;

import com.completex.objective.components.persistency.Persistency;
import com.completex.objective.components.persistency.core.adapter.DefaultPersistencyAdapter;
import com.completex.objective.components.persistency.transact.Transaction;
import com.completex.objective.persistency.examples.ExamplesHelper;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;

/**
 * @author Gennady Krizhevsky
 */
public class SecondExample {
    public static void main(String[] args) throws Exception {
        run(args);
    }

    private static void run(String[] args) throws IOException, SQLException {
        if (args.length > 0) {
            GenObjects.configPath = args[0];
        }
        //
        // Clean up:
        //
        ExamplesHelper.removeLock();
        //
        // Create instance of Persistency:
        //
        Persistency persistency = new DefaultPersistencyAdapter(GenObjects.configPath);
        //
        // Create person object:
        //
        ExplPerson person = new ExplPerson();
        person.setBirthDate(new Date());
        person.setFirstName("John");
        person.setLastName("Smith");
        //
        // Open transaction:
        //
        Transaction transaction = persistency.getTransactionManager().begin();
        //
        // Save person object:
        //
        persistency.insert(person);
        //
        // Load it from the database:
        //
        person = (ExplPerson) persistency.load(person);
        //
        // Commit transaction & return connection to the pool:
        //
        persistency.getTransactionManager().commit(transaction);
        //
        // Print it out:
        //
        System.out.println("Loaded person: " + person);
        //
        // Shutdown: 
        //
        persistency.getTransactionManager().shutdown();
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.