Open main menu

CDOT Wiki β

Changes

NexJ Express Connecting to PostgreSQL

3,750 bytes added, 20:30, 26 January 2014
no edit summary
<big><big> PostgreSQL Adapter for NexJ - Create Test Environment </big></big>{{NexJ_Express IndexAdmon/obsolete}}
* 1- Setup the postgresql-connection[[category: Configure the work/ws/core/bin/nexj/default.configNexJ Express PostgreSQL]][[Category: Configure the work/ws/core/test/nexj/default.configNexJ_Express_Development]][[category: Configure the work/ws/core/bin/nexj/postgresql.connection: Configure the work/ws/core/test/nexj/postgresql.connectionNexJ Express]]
== Task Summary ==
{| border="1" cellpadding="4" cellspacing="2" style="border: 1px solid black;border-collapse:collapse;"
|-
! Task
! Status
|-
| Install the PostgreSQL Server
| DONE
|-
| Install PostgreSQL driver
| DONE
|-
| Add code to connect to server
| DONE
|-
| Create Script for Test database
| DONE
|-
| Test connection to the server
| DONE
|-
| Configure UnitTests for multiple DB's
|
|}
* 2- Add == Task Details ===== Install PostgreSQL database to related java files===Download: <code>Version 9.0</code> from list of [http: SQLSchemaMangerFactory//www.enterprisedb.com/products/pgdownload.do#windows PostgreSQL downloads].java
=== Install PostgreSQL JDBC3 driver ===
Download: <code> JDBC3 Postgresql Driver, Version 9.0-801 </code> @ http://jdbc.postgresql.org/download.html
<br/>Install: Copy driver to <code>[jdk folder]/jre/lib/ext</code>
* 3- Create the extended === Code: Add PostgreSQL source files Driver ===Package: <code>nexj.core.persistance.sql</code>:Create <code>PostgreSQLAdapter.java</code> by extending <code>SQLAdapter</code>: PostgreSQLSchemaMangerCreate <code>PostgreSQLSchemaManager.java</code> by extending <code>SQLSchemaManager</code>
:Edit <code>RelationalDatabase.java</code>
:Edit <code>RelationalDatabaseFragment.java</code>
:Edit <code>SQLSchemaManagerFactory.java</code>
Package: <code>nexj.core.meta.sys</code>:Edit <code>system.dstypes</code> === SQL Scripts ===Package: <code>nexj.core.persistence.sql.script</code>:Create * <code>postgresql_setup.sql</code>* 4<code>postgresql_drop.sql</code>* <code>postgresql_insert.sql</code>* <code>postgresql_upd_addr.sql</code>* <code>postgresql_upd_cont.sql</code> === UnitTest: Test Connectivity to database ===Package: <code>nexj.core.persistance.sql</code>:Create <code>PostgreSQLAdapterTest.java</code> by extending <code>SQLAdapterTest</code>:Create <code>PostgreSQLSchemaManagerTest.java</code> by extending <code>SQLSchemaManagerTest</code> Package: <code>nexj</code>:Create <code>postgresql.connections</code> using NexJ Studio:Edit <code>default.config</code> to use PostgreSQL:Edit all <code>*.connections</code> files to use PostgreSQL ===Configure UnitTests for more than one Database=== <!- Create -== Setup the postgresql-connection ==For testing the connection, the 'AllTests.java' is being used.: Installed the extended <code> Installer version Version 9.0.1-1</code> from list of [http://www.enterprisedb.com/products/pgdownload.do#windows PostgreSQL test downloads].: Installed the <code> JDBC3 Postgresql Driver, Version 9.0-801 </code> @ http://jdbc.postgresql.org/download.html and added it to the libraries in JDK:: The driver class which is being used for NexJ Express Model is: <code> org.postgresql.xa.PGXADataSource </code>:: The driver is loaded from RelationalDatabaseFragment.java and RelationalDatabase.java: Metadata is loaded from the particular driver::<source lang=java> /* MySQLAdapterTest.java */ try { s_metadata = loadMetadata(ADAPTER_NAME); }  /* SQLDataTest.java */ protected static Metadata loadMetadata(String sAdapter) { Properties props = SysUtil.getConfigProperties(); // sets DEFAULT_CONFIG_URL = '/' + NAMESPACE + "/default.config" props = new Properties(props); props.setProperty(XMLMetadataLoader.CONNECTIONS_URL_PROPERTY, "/nexj/" + sAdapter.toLowerCase(Locale.ENGLISH) + ".connections"); // sets the properties to postgresql.connection</source>: After all properties are loaded, it creates the connection through Connection Factory files. ===Files to Configure==='''NOTE''': Changes to these files are involved with '''1-Port''', which should be: 5432, and '''2- Driver package''' that should change to <code> org.postgresql.xa.PGXADataSource </code>: src: PostgreSQLAdapterTest: system.dstype:: DatabaseTool.java // This file calles SQLSchemaMangerFactory.java and creates the connection:: RelationalDatabase.java // Sets the default properties for the supported drivers:: RelationalDatabaseFragment.java // Sets the custom fragment properties for the supported drivers:: Driver type and some other properties in JDBCInfo.java:: SQLSchemaManagerFactory.java // Sets the connection for the particular adapter type: test: PostgreSQLSchemaMangerTest: AllTests.java:: default.config // change to these four files are: adapter="PostgreSQL" port="5432":: postgresql.connection :: filestorage.connections::filestoragefragment.connections-->