Database Descriptors

A database descriptor describes dialects and paramters that are different from database to database, and provides transparency for database access and backup.

To support a database, its XML descriptor must be provided. Its file name is [dbmsType]-descriptor.xml where dbmsType is the type of database, case sensitive. For example, mysql-descriptor.xml, oracle-descriptor.xml, postgresql-descriptor.xml, etc.

Database XML descriptors need to be put under conf/db before running Cmobilecom Installer. They will be available as choices for target database, and will be copied to conf/db under CMOBILECOM.HOME by the installer.

The following is a sample descriptor for mysql database.

<db-descriptor dbmsType="mysql">
	
	<param name="databaseSameAsSchema" value="true"/>
	<param name="userSameAsSchema" value="false"/>
	
	<param name="jdbc.driver" value="com.mysql.jdbc.Driver" />	
	<param name="jdbc.url" 
		value="jdbc:mysql://#{host}:#{port}/#{database}?useUnicode=true&characterEncoding=UTF-8"/>
		
	<dialect name="setCurrentSchema">
		<sql>USE #{schema}</sql>
	</dialect>
	
	<dialect name="createSchema">
		<sql>
		CREATE DATABASE #{schema} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
		GRANT ALL PRIVILEGES ON #{schema}.* TO '#{username}'@'#{userHost}' IDENTIFIED BY '#{password}' WITH GRANT OPTION;
		</sql>
	</dialect>
	
	<dialect name="deleteSchema">
		<sql>
		DROP DATABASE #{schema};
		revoke all privileges on #{schema}.* from '#{username}'@'#{userHost}';
		</sql>
	</dialect>

	<dialect name="exportSchema">
		<command>
			<program>#{dbms.client.home}/bin/mysqldump</program>
			<argument>--host=#{host}</argument>
			<argument>--port=#{port}</argument>
			<argument>--user=root</argument>
			<argument>--password=#{sysAdminPassword}</argument>
			<argument>#{schema}</argument>
			<stdoutFile>#{directory}/#{filename}</stdoutFile>
			<stdoutCharset>UTF-8</stdoutCharset>
		</command>
	</dialect>

	<dialect name="importSchema">
		<sql>USE #{targetSchema}</sql>
		<sql inline="false">#{directory}/#{filename}</sql>
	</dialect>

</db-descriptor>
The following is a sample descriptor for oracle 11g database.

<db-descriptor dbmsType="oracle">
	<param name="databaseSameAsSchema" value="false"/>
	<param name="userSameAsSchema" value="true"/>
	
	<param name="jdbc.driver" value="oracle.jdbc.driver.OracleDriver" /> 		
	<param name="jdbc.url" 
		value="jdbc:oracle:thin:@//#{host}:#{port}/#{database}"/>

	<dialect name="setCurrentSchema">
		<sql>ALTER SESSION SET CURRENT_SCHEMA = #{schema}</sql>
	</dialect>

	<dialect name="createSchema">
		<sql>GRANT CONNECT, RESOURCE TO #{schema} IDENTIFIED BY #{password}</sql>
	</dialect>
	
	<dialect name="deleteSchema">
		<sql>DROP USER #{schema} CASCADE</sql>
	</dialect>

	<dialect name="exportSchema">
		<sql>create or replace directory dmp_dir as '#{directory}'</sql>
		<command>
			<program>#{dbms.client.home}/bin/expdp</program>
			<argument>system/#{sysAdminPassword}@//#{host}:#{port}/#{database}</argument>
			<argument>schema=#{schema}</argument>
			<argument>directory=dmp_dir</argument>
			<argument>dumpfile=#{filename</argument>
			<argument>logfile=dump.log</argument>
		</command>		
	</dialect>

	<dialect name="importSchema">
		<sql>create or replace directory dmp_dir as '#{directory}'</sql>
		<command>
			<program>#{dbms.client.home}/bin/impdp</program>
			<argument>system/#{sysAdminPassword}@//#{host}:#{port}/#{database}</argument>
			<argument>REMAP_SCHEMA=#{srcSchema}:#{targetSchema}</argument>
			<argument>TABLE_EXISTS_ACTION=REPLACE</argument>
			<argument>directory=dmp_dir</argument>
			<argument>dumpfile=#{filename}</argument>
			<argument>logfile=dump.log</argument>
		</command>	
	</dialect>

</db-descriptor>
A database descriptor defines both params and dialects. All the supported variables will be resolved at runtime.

A param element defines a parameter value or some characteristics of a database. For example, driver class, connection url, etc.

A dialect is defined as a sequence of sql(s) and commands. A sql element defines a number of sql statements that will be sent to database server for execution. However, a command defines a program with its arguments and will be executed on local operating system where JVM is running.

To add descriptors for other databases, follow the examples above.