Skip to content
ADVANT I/O edited this page Aug 14, 2016 · 7 revisions

Here you can found all that you need to create your Data access Layer for your Application so quick and easy but with powerful results.

Why do I need a new ORM?

There isn't any easy solution developed until now that permit to create Data Access Object (DAO) so quickly and without having a degree!

Best Features

Advant ORM permit to create Entity and DAO class to query your database by using main SQL commands provided by the following methods:

  • find()
  • insert()
  • update()
  • delete()

Don't care about SQL code or learning derivated languages.
No need to detach session or manipulate framework status during your database transactions.
In your Enity you can create Joins between tables, there isn't Lazy Loading or other keywords wich are useless, you can decide the behavior programmatically. No XML, all entities are java class with properties, setter and getter.
It is a framework builded around JDBC.

Table classes

Create Table Classes with properties, setters and getters, and extends io.advant.orm.AbstractTable. Use @Column to identify column name of the table.

@Table(name = "product")
public class ProductTable extends AbstractTable {

    @Column(name = "name")
    private String name;

    @Column(name = "brand_id")
    private Long brandId;

    @Column(name = "create_date")
    private Date createDate;

    public String getName() { return name; }

    public void setName(String name) { this.name = name; }

    public Long getBrandId() { return brandId; }

    public void setBrandId(Long brandId) { this.brandId = brandId; }

    public Date getCreateDate() { return createDate; }

    public void setCreateDate(Date createDate) { this.createDate = createDate; }
}

@Table(name = "brand")
public class BrandTable extends AbstractTable {

    @Column(name = "name")
    private String name;

    public String getName() { return name; }

    public void setName(String name) { this.name = name; }
}

Entity Class

Create Entity Class with property, setter and getter, extending Table Class and implementing io.advant.orm.Entity. Use @Relation to construct your join (this example is ONE-TO-ONE) inserting source property id (brandId of ProductTable Class) and destination property id (id of BrandTable Class).

public class ProductEntity extends ProductTable implements Entity {

    @Relation(from = "brandId" , to = "id")
    private BrandEntity brand;

    public BrandEntity getBrand() { return brand; }

    public void setBrand(BrandEntity brand) { this.brand = brand; }

}

DAO Class

Create interface and implementation class for Product DAO class extending io.advant.orm.AbstractDAO and configure generics with ProductEntity class. Remember to super with connection io.advant.orm.DBConnection already open.

public interface ProductDAO<T> extends DAO<T> {}

public class ProductDAOImpl extends AbstractDAO<ProductEntity> implements ProductDAO<ProductEntity> {
    public ProductDAOImpl(DBConnection connection) {
        super(connection);
    }
}

Configure Properties

Configure connection parameters for Mysql and options for Advant ORM

File: advantorm.properties

db.type=mysql
db.host=localhost
db.port=3306
db.database=advantorm
db.user=root
db.password=
entity.1=com.example.BrandEntity
entity.2=com.example.ProductEntity

Use DAO in your Service Layer

// Get connection
DBConnection conn = DBFactory.getInstance().getConnection();
ProductDAO<ProductEntity> dao = new ProductDAOImpl(conn);

//Create your entity and set values
ProductEntity entity = new ProductEntity();
entity.setName("MyProduct");
entity.setCreateDate(new Date());

// Insert product entity
dao.insert(entity);
Long generatedId = entity.getId();

// Find by Id
dao.find(generatedId);

// Update product entity
entity.setName("NewProduct");
dao.update(entity);

// Delete product entity
dao.delete(entity);

Getting started explains how this all works