public class Test1 extends Object implements StandardCBRApplication
The DataBase connector in es/ucm/fdi/gaia/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>es/ucm/fdi/gaia/jcolibri/test/test1/hibernate.cfg.xml</HibernateConfigFile> <DescriptionMappingFile>es/ucm/fdi/gaia/jcolibri/test/test1/TravelDescription.hbm.xml</DescriptionMappingFile> <DescriptionClassName>es.ucm.fdi.gaia.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="es.ucm.fdi.gaia.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
,
jcolibri.connector.DataBaseConnector
Constructor and Description |
---|
Test1() |
Modifier and Type | Method and Description |
---|---|
void |
configure() |
void |
cycle(CBRQuery query) |
static void |
main(String[] args)
Main function
|
void |
postCycle() |
CBRCaseBase |
preCycle() |
public Test1()
public void configure() throws ExecutionException
configure
in interface StandardCBRApplication
ExecutionException
public CBRCaseBase preCycle() throws ExecutionException
preCycle
in interface StandardCBRApplication
ExecutionException
public void cycle(CBRQuery query) throws ExecutionException
cycle
in interface StandardCBRApplication
ExecutionException
public void postCycle() throws ExecutionException
postCycle
in interface StandardCBRApplication
ExecutionException
Copyright © 2018 Group of Artificial Intelligence Applications (GAIA). All rights reserved.