runtimedao


The library for generating your DAO classes at runtime

TUTORIAL

Description

Runtimedao or runtime DAO is a library for generating your DAO classes at runtime. It has already have Log4j, Hibernate, JPA, PostgreSQL, MySQL and other dependencies included.

For example, let TestVO be a VO basic entity class and TestDAO a DAO interface related to TestVO:

TestVO.java ``` package org.runtimedao.sampleproject;

//imports

@Entity public class TestVO {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private int id;
private String login;
private String password;  

//setters and getters  

} ```

TestDAO.java ``` package org.runtimedao.sampleproject;

//imports

@DAOEntity(TestVO.class) public interface TestDAO extends DAO {

@HQL("FROM TestVO t WHERE t.login = ?")
TestVO findByLogin(String login);

@HQL("FROM TestVO t WHERE t.login = ? AND t.password = ?")
TestVO findByLoginAndPassword(String login, String password);

} ```

Then, if you call:

TestDAO testDAO = DAOFactory.getDAO(TestDAO.class)

The TestDAO implementation will be generated and compiled at runtime!

You just need to write the interface of your DAO classes and runtimedao will implement your new methods and those of the following interface:

``` public interface DAO {

T find(Object id);
T find(Object id, Map<String, Object> properties);
void persist(T t);
void remove(T t);
void merge(T t);
void flush();
List<T> findAll();

} ```

How to use runtimedao in a maven based project?

  1. Add in your pom.xml:

``` ... runtimedao https://runtimedao.googlecode.com/svn/maven/repository/ ...

<dependencies>
<dependency>
        <groupId>com.googlecode</groupId>
    <artifactId>runtimedao</artifactId>
    <version>1.0.1</version>
    <scope>compile</scope>
</dependency>
    ...
</dependencies>

... ```

  1. Add a persistence.xml in META-INF directory. Runtimedao uses by default the persistence unit named "runtimeDAO". For example:

``` http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">

```

Also, you can see a maven sample project -> http://code.google.com/p/runtimedao/source/browse/#svn%2Ftrunk%2Fsampleproject

How to use runtimedao in a "normal" project?

  1. Download http://code.google.com/p/runtimedao/source/browse/maven/repository/com/googlecode/runtimedao/1.0.1/runtimedao-1.0.0.jar

  2. Add runtimedao library to the project's classpath

How to build runtimedao

  1. svn checkout http://runtimedao.googlecode.com/svn/trunk/runtimedao runtimedao-read-only

  2. Configure runtimedao/src/test/resources/META-INF/persistence.xml

  3. mvn clean install

Project Information

The project was created on Oct 18, 2011.

Labels:
DAO Runtime Java JPA Hibernate Compiler Database