例如有下列配置
<orm:config id="config" entity-package="com.zfoo.orm.**.entity"> <orm:host database="test" user="" password=""> <orm:address name="server0" url="127.0.0.1:27017"/> </orm:host> <!-- 缓存策略 --> <orm:caches> <orm:cache strategy="ten" size="10" expire-millisecond="600000"/> <orm:cache strategy="hundred" size="100" expire-millisecond="600000"/> <orm:cache strategy="thousand" size="1000" expire-millisecond="600000"/> <orm:cache strategy="threeThousand" size="3000" expire-millisecond="600000"/> <orm:cache strategy="tenThousand" size="10000" expire-millisecond="600000"/> </orm:caches> <!-- 持久化策略 --> <orm:persisters> <orm:persister strategy="cronDefault" type="cron" config="0,30 * * * * ?"/> <orm:persister strategy="cron3s" type="cron" config="0/3 * * * * ?"/> <orm:persister strategy="cron15s" type="cron" config="0/15 * * * * ?"/> <orm:persister strategy="cron30s" type="cron" config="0/30 * * * * ?"/> <orm:persister strategy="cron1m" type="cron" config="0 0/30 * * * ?"/> <orm:persister strategy="time30s" type="time" config="30000"/> </orm:persisters> </orm:config>
有下列注解
@EntityCaches(cacheStrategy = "tenThousand", persister = @Persister("time30s")) public class UserEntity implements IEntity<Long> { }
- database表示操作哪个数据库
- address表示数据库的地址,支持分片的配置
- caches中的strategy表示一个缓存的策略,即将数据库中的数据先读入Orm中的EntityCaches缓存,如hundred这个策略表示,缓存数据库中1000条数据,10分钟过期
- persisters中的strategy表示一个持久化的策略,如3s这个策略表示,将EntityCaches中的缓存数据每3s写入到数据库中一次,即使中途宕机,也只损失3秒的数据
- EntityCaches这个注解表示将会被Orm管理,使用hundred策略,缓存的持久化策略为3s
Ⅳ. 教程
test下中包含了所有增删改查的教程,运行之前请先安装MongoDB
以上就是MongoDB orm框架的注意事项及简单使用的详细内容,更多关于MongoDB orm框架的资料请关注其它相关文章!