|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjcolibri.test.test1.Test1
public class Test1
Test 1 shows how to use a simple data base connector and perform the KNN retrieval. It uses the travel example with cases that only have description
(without solution or result).
This example uses the DataBase connector that is implemented using the Hibernate library.
That library is a Java Data Objects implementation that automatically manages the persistence of
Java beans in relational data bases.
For an introduction to hibernate see: http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html
The DataBase connector in jcolibri/test/test1/databaseconfig.xml and that xml defines the configuration of Hibernate and
the mapping of the description of our case with the data base. In this example, all the attributes of the description bean are stored in the same table.
<DataBaseConfiguration> <HibernateConfigFile>jcolibri/test/test1/hibernate.cfg.xml</HibernateConfigFile> <DescriptionMappingFile>jcolibri/test/test1/TravelDescription.hbm.xml</DescriptionMappingFile> <DescriptionClassName>jcolibri.test.test1.TravelDescription</DescriptionClassName> </DataBaseConfiguration>
<hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="connection.url">jdbc:hsqldb:hsql://localhost/travel</property> <property name="connection.username">sa</property> <property name="connection.password"></property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.HSQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> </session-factory> </hibernate-configuration>
This test uses the HSQLDB data base server with an example table containing
the data of the case base. Developers can use any other DBMS changing the
hibernate configuration file.
If you use another database change the driver, url and dialect fields.
For example, to use a MySQL server you should use:
<property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/travel</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property>For other configuration settings see hiberante documentation: http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html
<hibernate-mapping default-lazy="false"> <class name="jcolibri.test.test1.TravelDescription" table="Travel"> <id name="caseId" column="caseId"> <generator class="native"/> </id> <property name="HolidayType" column="HolidayType"/> <property name="Price" column="Price"/> <property name="NumberOfPersons" column="NumberOfPersons"/> <property name="Region" column="Region"/> <property name="Transportation" column="Transportation"/> <property name="Duration" column="Duration"/> <property name="Season" column="Season"/> <property name="Accomodation" column="Accommodation"/> <property name="Hotel" column="Hotel"/> </class> </hibernate-mapping>Here we set that TravelDescription is mapped in the Travel table. caseId is the primary key of the table and Hibernate will use a native key generator for new cases (there are different ways to create primary keys, for more information see Hiberante documentation). Each attribute is mapped into a table with the same name. You should notice that here we don't indicate the type of the attributes. Hibernate automatically detects the type and converts from/to the database. Anyway if you want to use an unrecognoized type that hibernate does not understand or create your own one you can do it by implementing the jcolibri.connector.TypeAdaptor interface in your type.
+----------+-------------+-------+-----------------+--------+----------------+----------+--------+---------------+--------------------------+ | caseId | HolidayType | Price | NumberOfPersons | Region | Transportation | Duration | Season | Accommodation | Hotel | +----------+-------------+-------+-----------------+--------+----------------+----------+--------+---------------+--------------------------+ | Journey1 | Bathing | 2498 | 2 | Egypt | Plane | 14 | April | TwoStars | Hotel White House, Egypt | | Journey2 | Bathing | 3066 | 3 | Egypt | Plane | 21 | May | TwoStars | Hotel White House, Egypt | ...The travel.sql file contains the code to create this data base.
TravelDescription
,
DataBaseConnector
Constructor Summary | |
---|---|
Test1()
|
Method Summary | |
---|---|
void |
configure()
Configures the application: case base, connectors, etc. |
void |
cycle(CBRQuery query)
Executes a CBR cycle with the given query. |
static void |
main(java.lang.String[] args)
Main function |
void |
postCycle()
Runs the code to shutdown the application. |
CBRCaseBase |
preCycle()
Runs the precyle where typically cases are read and organized into a case base. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Test1()
Method Detail |
---|
public void configure() throws ExecutionException
StandardCBRApplication
configure
in interface StandardCBRApplication
ExecutionException
public CBRCaseBase preCycle() throws ExecutionException
StandardCBRApplication
preCycle
in interface StandardCBRApplication
ExecutionException
public void cycle(CBRQuery query) throws ExecutionException
StandardCBRApplication
cycle
in interface StandardCBRApplication
ExecutionException
public void postCycle() throws ExecutionException
StandardCBRApplication
postCycle
in interface StandardCBRApplication
ExecutionException
public static void main(java.lang.String[] args)
|
GAIA - Group for Artificial Intelligence Applications http://gaia.fdi.ucm.es |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |