Runtime tools : Service components : Smart channel services : Data management of smart channel : Smart channel DAO API
  
Smart channel DAO API
The UDTT smart channel uses JPA as the data implementation.
This graphic is described in the surrounding text.
You can use the UDTT smart channel DAO API to operate the data in the table. DAO API supports add, update, delete, and find operation. The following steps introduce how to use DAO API:
This graphic is described in the surrounding text.
1 Specify the file bttsmartchannel.jar in your class path. This JAR file is located at ${btt_root}/lib/ bttsmartchannel.jar.
2 Specify the file com.ibm.ws.jpa.thinclient_7.0.0.jar standalone Java archive (JAR) in your class path. This standalone JAR file is available from the client and server installation images. The location of this file on the client install image is ${app_client_root}/runtimes/com.ibm.ws.jpa.thinclient_7.0.0.jar. The location of this file on the server install image is ${app_server_root}/runtimes/com.ibm.ws.jpa.thinclient_7.0.0.jar.
3 Specify the database connection driver jar in your class path. For DB2 v9 or v9.5 or v9.7, the driver JAR files are db2jcc.jar and db2jcc_license_cisuz.jar; For Oracle 11, the driver JAR file is ojdbc14.jar; For SQL Server 2005, the driver JAR file is sqljdbc.jar.
4 Create database, and then run the DDL files accordingly to the database type to generate or update the tables. The DDL files are available from the file bttsmartchannel.jar. For DB2, the DDL file is dataCollector_DB2.DDL; For Oracle, the DDL file is dataCollector_ORACLE.DDL; For SQL Server, the DDL file is dataCollector_SQLSERVER.DDL.
5 In the persistence.xml, specify your database configuration options. For DB2, specify as following configuration:
<property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.DB2Driver" />
<property name="openjpa.ConnectionURL" value="jdbc:db2://SERVER_NAME:50000/DB_NAME" />
<property name="openjpa.ConnectionUserName" value="USER_NAME" />
<property name="openjpa.ConnectionPassword" value="USER_PASSWORD" />
</properties>
For Oracle, specify as following configuration:
<property name="openjpa.ConnectionDriverName" value="oracle.jdbc.driver.OracleDriver" />
<property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:SERVER_NAME:1521:DB_NAME" />
<property name="openjpa.ConnectionUserName" value="USER_NAME" />
<property name="openjpa.ConnectionPassword" value="USER_PASSWORD" />
</properties>
For SQL Server, specify as following configuration:
<property name="openjpa.ConnectionDriverName" value=" com.microsoft.sqlserver.jdbc.SQLServerDriver " />
<property name="openjpa.ConnectionURL" value=" jdbc:sqlserver://SERVER_NAME:1433;DatabaseName=DB_NAME/>
<property name="openjpa.ConnectionUserName" value="USER_NAME" />
<property name="openjpa.ConnectionPassword" value="USER_PASSWORD" />
</properties>
6 Use the UDTT smart DAO API to access data (Take “VISIT_LOG” for the example).
Create the smart DAO instance:
static SmartDataCollectionDAO smartDao=new SmartDataCollectionDAOJPAImpl();
Create the table bean instance:
SmartVisitLog visit=new SmartVisitLog();
Set the properties of the bean:
visit.setUserId("lyl");
visit.setSmartChannel(channel);
visit.setLogonTime(DateUtil.getTimeStamp());
visit.setIpAddress("127.0.0.1");
visit.setVisitId(smartDao.getVisitId(visit.getUserId(), visit.getLogonTime().toString(), channel.getChannelId()));
visit.setBrowser("/aaa/bb");
Operate the database:
try{
smartDao.addSmartVisit(visit);//add the record
smartDao.updateSmartVisit(visit);//update the record
smartDao.deleteSmartVisit(visit);//delete the record
}catch(Exception e){
e.printStackTrace();
}
Go up to
Data management of smart channel