|
|
Configure a database and a Lucene index
The default configuration of the Petals Master application uses an H2 database, in non-persistent mode (memory mode). That means that when the servlet container is stopped, all the data are deleted (because they were not persisted).
You may want to change this configuration : use H2 database but in file mode (to persist data), or change the H2 database for a MySQL database for example. We will see how to do that.
Petals Master uses a Lucene index to store information about stored entities to provide advanced search capabilities. The default configuration stores the index in memory. So, if the servlet container is stopped, the index is lost. This default setting must only be used with a non persistant storage (H2 in memory mode). This configuration must be modified if you use a persistant storage like H2 in file mode or MySQL. We will see below, how to configure a file system directory for index purpose.
Petals Master is packaged as a war. To change the database configuration, you have to unzip the war archive. Go into the
${petals-master-root}/WEB-INF/classes directory and open the dragon.properties file.
The default dragon.properties file is (NB : here, we have disable the MySQL configuration and enable the H2 configuration, Indexation is set in memory mode) :
############
### Datasource properties
############
## MySQL Datasource
# jdbc.driverClassName = com.mysql.jdbc.Driver
# jdbc.url = jdbc:mysql://localhost:3306/dragon
# jdbc.username = anonymous
# jdbc.password =
# jdbc.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
# jdbc.hibernate.hbm2ddl.auto = update
# jdbc.hibernate.show_sql = false
## In Memory H2 Datasource
jdbc.driverClassName = org.h2.Driver
jdbc.url = jdbc:h2:mem:dragon
jdbc.username = sa
jdbc.password = sa
jdbc.hibernate.dialect = org.hibernate.dialect.H2Dialect
jdbc.hibernate.hbm2ddl.auto = update
jdbc.hibernate.show_sql = false
## In Memory HSQL Datasource
#jdbc.driverClassName = org.hsqldb.jdbcDriver
#jdbc.url = jdbc:hsqldb:mem:dragon
#jdbc.username = sa
#jdbc.password =
#jdbc.hibernate.dialect = org.hibernate.dialect.HSQLDialect
#jdbc.hibernate.hbm2ddl.auto = update
#jdbc.hibernate.show_sql = false
#jdbc.url =jdbc:hsqldb:file:c:/hsqldb/dragon
###########
### Indexation properties (Compass/Lucene)
###########
## Index path
compass.index.url = ram://compass
#compass.index.url = file:///c:/compass
# compass.index.url = file:///home/compass
## Full default analyser
#compass.engine.analyzer.default.type = snowball
#compass.engine.analyzer.default.name = English
compass.engine.analyzer.default.type = standard
compass.engine.analyzer.default.name = English
##########
### Log
##########
#log.root.path = C:/Projets/SOA4All
##########
### Repository
##########
## A Database repository configuration. All binary files are stored as DB Blobs
repo.type = database
repo.root = null
## A Filesystem repository configuration. All binary files are stored in the filesystem
#repo.type = filesystem
#repo.root = ./test-repository
The H2 Datasource (in memory mode) is the one used by default. You also have a MySQL configuration which is disabled by default.
Let's have a look at the available parameters (these parameters values are to adapt according to the used database) :
• jdbc.driverClassName : this is the JDBC driver which enables the connection between the Java application and the database. A list of available JDBC drivers is available at JDBC Data Access API.
• jdbc.url : this is the URL of the database.
• jdbc.username : this is the username of the account used to access to the database.
• jdbc.password : this is the password of the account used to access to the database.
• jdbc.dialect : this is the Hibernate dialect allowing the translation of SQL information to the targeted database.
Available Hibernate dialects are :
• H2 : org.hibernate.dialect.H2Dialect
• MySQL : org.hibernate.dialect.MySQLDialect
• MySQL 5 with InnoDB : org.hibernate.dialect.MySQL5InnoDBDialect
• MySQL with InnoDB : org.hibernate.dialect.MySQLInnoDBDialect
• MySQL with MyISAM : org.hibernate.dialect.MySQLMyISAMDialect
• HSQLDB : org.hibernate.dialect.HSQLDialect
• jdbc.hbm2ddl.auto : this parameter defines if the application creates a new database from scratch (create) or only update an existing database (update). Update mode also create a database if it doesn't exist. Except for an H2 in memory mode, it is recommended to set the value at update.
Let's have a look at the available parameter for the indexation :
• compass.index.url : the index URL, "ram://path" for an in memory index, "file://path" for a file system persisted index.
• compass.engine.analyser.default.type : type of analyser used to tokenize indexed information. Petals master comes with core analyzers (Which are part of the lucene-core jar). They are: standard, simple, whitespace, snowball, and stop.
• standard : tokenize information with the following rules. Splits words at punctuation characters, removing punctuation. However, a dot that's not followed by whitespace is considered part of a token, splits words at hyphens, unless there's a number in the token, in which case the whole token is interpreted as a product number and is not split, recognizes email addresses and internet hostnames as one token.Then lowercase tokens and remove english stop words (the, a, an ...). It is the recommended and most tested analyser.
• simple : tokenize information by dividing text at non-letters. That's to say, it defines tokens as maximal strings of adjacent letters, as defined by java.lang.Character.isLetter() predicate. Note: this does a decent job for most European languages, but does a terrible job for some Asian languages, where words are not separated by spaces.Then lowercase tokens.
• whitespaces : tokenize information by dividing text at whitespace.
• snowball : same as standard analyser but stems words using a Snowball-generated stemmer.
• stop : same as simple analyser but remove english stop words (the, a, an ...).
• compass.engine.analyser.default.name : An additional setting that must be set when using the snowball analyzer.
The settings can have the following values: Danish, Dutch, English, Finnish, French, German, German2, Italian, Kp, Lovins, Norwegian, Porter, Portuguese, Russian, Spanish, and Swedish.
Other parameters (not visible in the previous screenshot) :
• configuration.reload.delay : this property specify the delay between 2 consecutives reload of the Petals Master configuration. Must not be modified.
• root.domain : used to generate UDDI keys. By default the root domain is "dragon.org". You could specify your own root domain. For exemple : "mycompany.com". See Chapter 9, Adding custom Category/Identifier systems for Organizations/Services/Endpoints
|