/nv-jdo

Utilities for JDO

Primary LanguageJavaApache License 2.0Apache-2.0

nv-jdo

Overview

Utilities for JDO.

Class Description
Dao Generic DAO implementation based on JDO.
TaskAdapter Empty implementation of TransactionAwareTask.
TaskExecutor Task executor with or without transaction.
Interface Description
Task Task executed by TaskExecutor.
TransactionAwareTask Sub interface of Task with additional methods for transaction.

License

Apache License, Version 2.0

Maven

<dependency>
    <groupId>com.neovisionaries</groupId>
    <artifactId>nv-jdo</artifactId>
    <version>1.19</version>
</dependency>

Source Code

https://github.com/TakahikoKawasaki/nv-jdo.git

Javadoc

http://TakahikoKawasaki.github.io/nv-jdo/

Example

//------------------------------------------------------
// Example of Dao, which is a generic DAO implementation
// based on JDO.
//------------------------------------------------------

// Persistence manager factory.
PersistenceManagerFactory factory = ...;

// Create a DAO with an entity class and the persistence manager factory.
Dao<Customer> dao = new Dao<Customer>(Customer.class, factory);

// Or using a static method.
Dao<Customer> dao = Dao.create(Customer.class, factory);

// Use the DAO.

// (1) Create an entity.
Customer customer = ...;
dao.put(customer);

// (2) Get an entity.
String customerId = ...;
Customer customer = dao.getById(customerId);

// (3) Delete an entity.
dao.delete(customer);

// (4) Delete an entity by ID.
dao.deleteById(customerId);
//------------------------------------------------------
// Example of TaskExecutor.
//------------------------------------------------------
// Persistence manager factory.
PersistenceManagerFactory factory = ...;

// Create a task executor.
TaskExecutor executor = new TaskExecutor(factory);

// Create a task.
Task task = new TaskAdapter() {
    @Override
    public void beforeTransactionBegin(PersistenceManager manager, Transaction tx) {
        tx.setOptimistic(false);
    }

    @Override
    public Object run(PersistenceManager manager) {
        ......
    }
};

// Execute the task.
executor.execute(task, true, 2);

See Also

Author

Authlete, Inc.
Takahiko Kawasaki <taka@authlete.com>

Contributors

Authlete, Inc.
Hideki Ikeda <hide@authlete.com>