-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Here you can found all that you need to create Model Layer for your Application, a quick and easy solution but powerful.
There isn't any easy solution developed until now that permit to create Data Access Object (DAO) so quickly and without having a degree!
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.
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; }
}
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; }
}
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);
}
}
// Get connection
DBConnection conn = DB.getInstance().getConnection();
ProductDAO<PersonEntity> 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