Open main menu

CDOT Wiki β

Changes

NexJ Express Connecting to PostgreSQL

1,114 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}}
[[category: NexJ Express PostgreSQL]][[Category:NexJ_Express_Development]][[category: NexJ Express]] ==Task Summary = ={| border="1" cellpadding="4" cellspacing="2" style="border: 1px solid black;border- Setup collapse:collapse;"|-! Task! Status|- | Install the postgresqlPostgreSQL 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| |} == Task Details ===== Install PostgreSQL ===For testing the connectionDownload: <code>Version 9.0</code> from list of [http://www.enterprisedb.com/products/pgdownload.do#windows PostgreSQL downloads]. === Install PostgreSQL JDBC3 driver ===Download: <code> JDBC3 Postgresql Driver, the 'PostgreSQLAdapterTestVersion 9.0-801 </code> @ http://jdbc.postgresql.java' is being usedorg/download.html * <br/>Install: Copy driver to <code>[[PostgreSQL_Adapter-nexjjdk folder]/jre/lib/test-envext</todo |TODOs]]code> * Files to configure based on === Code: Add PostgreSQL propertiesDriver ===Package: src<code>nexj.core.persistance.sql</code>:: Create <code>PostgreSQLAdapter.java </code> by extending <code>SQLAdapter</ Extends SQLAdapter.java - SQL Persistence adaptercode>:: Create <code>PostgreSQLSchemaManager.java </code> by extending <code>SQLSchemaManager</ Extends SQLSchemaManagercode> :Edit <code>RelationalDatabase.java - class for reading, creating and upgrading the database schema</code>:: systemEdit <code>RelationalDatabaseFragment.dstypejava</code>:: DatabaseToolEdit <code>SQLSchemaManagerFactory.java </code> Package: <code>nexj.core.meta.sys</ This file calles SQLSchemaMangerFactorycode>:Edit <code>system.java and creates the connectiondstypes</code> === SQL Scripts ===Package:<code>nexj.core.persistence.sql.script</code>: RelationalDatabaseCreate * <code>postgresql_setup.java sql</code>* <code>postgresql_drop.sql</ Sets the default properties for the supported driverscode>:: RelationalDatabaseFragment* <code>postgresql_insert.java sql</code>* <code>postgresql_upd_addr.sql</ Sets the custom fragment properties for the supported driverscode>:: Driver type and some other properties in JDBCInfo* <code>postgresql_upd_cont.javasql</code>:: SQLSchemaManagerFactory.java=== UnitTest: testTest Connectivity to database ===Package:: AllTests<code>nexj.core.persistance.javasql</code>:: Create <code>PostgreSQLAdapterTest.java </code> by extending <code>SQLAdapterTest</ Extends SQLAdapterTest.javacode>:: Create <code>PostgreSQLSchemaManagerTest.java </code> by extending <code>SQLSchemaManagerTest</ Extends SQLSchemaManagerTest.javacode> Package:: default.config /<code>nexj</ System resources are being extracted from these 4 XML filescode>:: Create <code>postgresql.connectionconnections</code> using NexJ Studio:: filestorageEdit <code>default.connectionsconfig</code> to use PostgreSQL::filestoragefragmentEdit all <code>*.connections</code> files to use PostgreSQL: Script:: postgresql_setup.sql:: TO be cond'===Configure UnitTests for more than one Database===
* Done<!--== Setup the postgresql-connection ==For testing the connection, the 'AllTests.java' is being used.: Installed the <code> Installer version Version 9.0.1-1</code> from list of [http://www.enterprisedb.com/products/pgdownload.do#windows PostgreSQL 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
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.
=== 2- Create a PostgreSQL database through some scriptsFiles to Configure===: Through the process in postgresql_setup.sql, the database was created, initialized and tested::: A database called 'test is created in PostgreSQL ''NOTE''': <code> CREATE DATABASE test </code>:: To create a <code>user</code> along Changes to these files are involved with <code>password</code>: <code> CREATE USER test WITH PASSWORD 'test'; </code>:: Login to the database 'test1-Port' with username 'test', which should be: <code> psql -U test test </code>:: Create a <code> Schema </code> called 5432, and 'test' inside the database 'test2- Driver package' with particular owner 'test': that should change to <code> CREATE SCHEMA test AUTHORIZATION test;org.postgresql.xa.PGXADataSource </code>:src:: system.dstype: Create a <code>table</code> called 'Mutex' with primary key: <code> CREATE TABLE testDatabaseTool.Mutex(id INT PRIMARY KEY); <java //code>This file calles SQLSchemaMangerFactory.java and creates the connection:: Insert a value into RelationalDatabase.java // Sets the default properties for the primary keysupported drivers: <code> INSERT INTO test: RelationalDatabaseFragment.Mutex(id) VALUES (1); <java //code>=== 3- Create Sets the custom fragment properties for the extended PostgreSQL source files ===supported drivers: PostgreSQLAdapter: Driver type and some other properties in JDBCInfo.java: PostgreSQLSchemaManger: SQLSchemaManagerFactory.java // Sets the connection for the particular adapter type: test:: AllTests.java:: default.config // change to these four files are: adapter=== 4- Create the extended "PostgreSQL test files ==" port="5432":: postgresql.connection : PostgreSQLAdapterTest: filestorage.javaconnections: PostgreSQLSchemaMangerTest:filestoragefragment.javaconnections-->