花了接近两周的时间了解学习InterSystems的Caché多维数据库,总算有点眉目了,不过我还是对Caché数据库提供的原生态语言Caché ObjectScript 不太愿意使用,我实在觉得使用这个语言来开发确实太别扭,Caché ObjectScript 虽然是一种强大而且易用的面向对象语言,并且有非常灵活的数据结构,但是我确实还是想用Java来实现,现将开发心得总结如下:
1,首先得搭建J2EE开发环境,包括Struts,Spring,Hibernate,方式同一般的J2EE项目。
2,创建NameSpace(Caché 数据库安装完毕)。
3,运行Caché Studio,创建Caché Class Definition。
代码如下:
Class Company.User Extends (%Persistent, %XML.Adaptor) { Property id As %Integer[Required]; Property username As %String(MAXLEN=20)[Required]; Property password As %String(MAXLEN=20)[Required]; }
在Output窗口看到"Successful" ,即可。
4,创建Java实体类:
package com.cache.domain; /** * @author :zhangyi Apr 11, 2009 10:36:25 PM [email protected] */ /* * author:tony.zhang CacheDB IMPORTANT NOTICE! * If you want to use InterSystem CacheDB,you MUST see the follow notice: * 1.Install Cache; * 2.Select "System Manage Portal" to create a new namespace; * 3.Select "Studio" and change the namespace when you at second step to created it; * 4.Create a new "Cache Class Definition"; * 5.Create some new property,this property will be persisted on your disk,this is datatable column; * 6.Debug it,if you see "Successful Complete",Done! */ public class User { private Integer id; private String username; private String password; /** * */ public User() { super(); } /** * @param username * @param password */ public User(String username, String password) { super(); this.username = username; this.password = password; } ...get/set... }
5,创建对应的映射文件:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.cache.domain"> <!-- author:tony.zhang table="Company.user"<->table="Package.Class" --> <class name="User" table="Company.user"> <id name="id" column="id" unsaved-value="null"> <generator class="native"></generator> </id> <property name="username" column="username"> </property> <property name="password" column="password"> </property> </class> </hibernate-mapping>
6,数据库连接的Properties:
#------------------ #This is jdbc.properties file include Oracle,MySql,Cache Properties #Create by Tony.Zhang Apr.11.2009 #------------------ #Oracle Properties #jdbc.driverClassName=oracle.jdbc.driver.OracleDriver #jdbc.url=jdbc:oracle:thin:@localhost:1521:ORCL #jdbc.username=scott #jdbc.password=tiger #MySql Properties #jdbc.driverClassName=com.mysql.jdbc.Driver #jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8 #jdbc.username=root #jdbc.password=zhangyi #Cache Properties jdbc.driverClassName=com.intersys.jdbc.CacheDriver jdbc.url=jdbc:Cache://localhost:1972/ZHANGYI jdbc.username=_System jdbc.password=SYS
以上是开发Caché的基础部分,剩下的我正在写CRUD的操作,写完了我放代码出来,未完待续。。。