昨天说了我的这个大轮子的大致情况,就是尽量保持简单,而配置最多的可能就是持久层和Action的配置,我的框架会完全取消这两个的配置,先说说持久层的情况。
- 类名和表名直接关联,关系是类名前带 t_
- 类的成员和表字段直接关联,名称完全一致,全部的表都需要一个名字为ID的主键,类型为long,由系统自动在插入的时候产生
- 表关联根据类之间的关联决定,如果两个类对对方都是直接引用,就是一对一,如果一个是直接引用,例外一个是集合,则是一对多,如果两边都是集合,就是多对多,对于集合的成员,其成员名是类名加s。多对多的表名是t_加两个类名,中间用_分隔,字段名就是类名加_id,如果是一对多,则外键名就是类名加_id
- 类型现在是自动匹配,也就是数据库的类型和类中的对应字段的类型是匹配的
- 主键的值在系统初始化的时候会从数据库表中读取最大值,然后缓存在系统中,每次加一
- 缓存的大小根据系统启动时数据库对应表的记录数决定,记录数小于一千的缓存100%,一千到一万的缓存50%,一万以上的缓存10%,十万以上缓存1%
- 类名可以分布在多个包中,配置文件配置都有那些包可以存放这些持久化对应的类,类名不可重复
根据这个规则,我完全取消了持久层的配置,对于新项目,这个规则的要求并不高,符合绝大部分的需要。至于查询,目前还没有完全想好,但是我考虑的是大部分的简单情况,只提供一个简单的对象表达式语法,复杂的查询还是使用SQL。
具体的例子:
数据库:
create table t_sampleprimary(id BIGINT PRIMARY KEY ,name VARCHAR(10),account BIGINT,birthday DATE,married BOOLEAN,age INT,income DOUBLE,saving BIGINT,city INT,working BOOLEAN,outgo DOUBLE)
create table t_samplechild(id BIGINT PRIMARY KEY ,name VARCHAR(10),sampleprimary_id BIGINT)
create table t_samplemany(id BIGINT PRIMARY KEY ,name VARCHAR(10))
create table t_samplemany_sampleprimary(sampleprimary_id BIGINT ,samplemany_id BIGINT)
类:
package com.jiehoo.model;
import java.util.Collection;
import java.util.Date;
import com.jiehoo.persistence.BasePersistencableBean;
public class SamplePrimary extends BasePersistencableBean {
private String name;
private Long account;
private Date birthday;
private Boolean married;
private Integer age;
private Double income;
private long saving;
private int city;
private boolean working;
private double outgo;
private Collection sampleChilds;
private Collection sampleManys;
/**
* @return the age
*/
public Integer getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(Integer age) {
this.age = age;
}
/**
* @return the birthday
*/
public Date getBirthday() {
return birthday;
}
/**
* @param birthday the birthday to set
*/
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
/**
* @return the city
*/
public int getCity() {
return city;
}
/**
* @param city the city to set
*/
public void setCity(int city) {
this.city = city;
}
/**
* @return the count
*/
public Long getAccount() {
return account;
}
/**
* @param count the count to set
*/
public void setAccount(Long count) {
this.account = count;
}
/**
* @return the income
*/
public Double getIncome() {
return income;
}
/**
* @param income the income to set
*/
public void setIncome(Double income) {
this.income = income;
}
/**
* @return the married
*/
public Boolean getMarried() {
return married;
}
/**
* @param married the married to set
*/
public void setMarried(Boolean married) {
this.married = married;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the outgo
*/
public double getOutgo() {
return outgo;
}
/**
* @param outgo the outgo to set
*/
public void setOutgo(double outgo) {
this.outgo = outgo;
}
/**
* @return the saving
*/
public long getSaving() {
return saving;
}
/**
* @param saving the saving to set
*/
public void setSaving(long saving) {
this.saving = saving;
}
/**
* @return the working
*/
public boolean isWorking() {
return working;
}
/**
* @param working the working to set
*/
public void setWorking(boolean working) {
this.working = working;
}
/**
* @return the sampleChilds
*/
public Collection getSampleChilds() {
return sampleChilds;
}
/**
* @param sampleChilds the sampleChilds to set
*/
public void setSampleChilds(Collection sampleChilds) {
this.sampleChilds = sampleChilds;
}
/**
* @return the sampleManys
*/
public Collection getSampleManys() {
return sampleManys;
}
/**
* @param sampleManys the sampleManys to set
*/
public void setSampleManys(Collection sampleManys) {
this.sampleManys = sampleManys;
}
}
package com.jiehoo.model;
import com.jiehoo.persistence.BasePersistencableBean;
public class SampleChild extends BasePersistencableBean {
private String name;
private SamplePrimary samplePrimary;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the samplePrimary
*/
public SamplePrimary getSamplePrimary() {
return samplePrimary;
}
/**
* @param samplePrimary the samplePrimary to set
*/
public void setSamplePrimary(SamplePrimary samplePrimary) {
this.samplePrimary = samplePrimary;
}
}
package com.jiehoo.model;
import java.util.Collection;
import com.jiehoo.persistence.BasePersistencableBean;
public class SampleMany extends BasePersistencableBean {
private String name;
private Collection samplePrimarys;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the samplePrimarys
*/
public Collection getSamplePrimarys() {
return samplePrimarys;
}
/**
* @param samplePrimarys the samplePrimarys to set
*/
public void setSamplePrimarys(Collection samplePrimarys) {
this.samplePrimarys = samplePrimarys;
}
}
发表评论