FreyjaJdbcTemplate特性一:HQL

freyja2大特点:hql+cache

 

freyja可以无缝替换掉hibernate,才怪。

 

freyja主要功能是为了实现对jdbc操作的封装而不是替换hibernate,但是为了替换掉项目中的hibernate,freyja实现了简单的hql语法(而且也实现不了复杂的)

举个例子来看下freyja大概支持哪些hql/sql语法(理论上支持全sql映射)

 

 

select x.n,x.id,x.name,devscore,u.uid,cityId from User u left join ( select * from ( select i.userId as n,i.id,h.cityId from UserInfo i left join Hero h  on h.userId = i.userId ) a) x on x.n = u.uid

这里面有User UserInfo Hero 3个对象
  
select army.name,number from ArmyProduce  where army.name = 'h' and number = 1

select * from ArmyProduce a where a.army.name = 'h' and number = 1
这里面有ArmyProduce 和Army 2个对象

ArmyProduce 和Army 是一对多关系

 @Entity

 

@Table(name = "t_army_produce")
public class ArmyProduce {
	@Id
	@GeneratedValue
	@Column(name = "Id", unique = true, nullable = false)
	private Long id;

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
	@JoinColumn(name = "ARMY_ID")
	private Army army;

	@Column(name = "NUMBER")
	private Integer number;

	@Column(name = "userId")
	private Long userId;

}

 可以看出和hibernate一样支持jpa规范的annotation注解没有什么区别。

但是只目前只支持ManyToOne注解,而且没有延迟加载。(其他的注解如ManyToMany不会去支持。)主键也只支持自动增长,当然其他的一些主键如uuid应该会加进来。

 

Freyja的做法是使用jsqlparser这个工具把hql结构化,然后根据annotation转化为sql。freyja支持/不支持部分写法取决于2点:

 

1、jsqlparser能否识别该写法。2、能否转化为sql。

 

理论上1通过那么2也会通过。这个也是我正在努力的一个方面。

jsqlparser的作者估计把太多脑细胞放在select语法上面了。update和delete的语法只支持非常简单的部分:

 

update table set xx='1',oo='2' where xx='3'
delete from table where xx='3'

 

 大概就这种形式。

freyja改造加上hql语法支持之后变成了:

 

update ArmyProduce set number = 1 where army.name = 'h' and number = 2
delete from ArmyProduce where army.name = 'h' and number = 1

 

 情况还是不宜乐观。

 

 

FreyjaJdbcTemplate特性一:HQL 

 

FreyjaJdbcTemplate特性二:cache

 

FreyjaJdbcTemplate特性三:JdbcTemplate 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值