Orbeon Forms Postgres DB connection - postgresql

I have tried to save the Orbeon forms in Postgres DB. I created data bases persistence layer but still forms are stored in the default eXist DB. I have created context(Data Base source) in the "Server.xml" from the tomcat7 and I have created "properties-local.xml" file in the Orbeon4.8 (orbeon/src/resources/config/properties-local.xml). My reference is this.
Some one help me how to save the orbeon forms in Postgres DB?

Once the database resource is configured, you can tell Orbeon to use it by adding a like like this to your properties-local.xml:
<property as="xs:string" name="oxf.fr.persistence.provider.*.*.*" value="postgresql"/>
You can see the default configuration for the resource names Orbeon accepts out of the box in properties-form-runner.xml.
Exist will still be used for the example forms. But you can disable it with:
<property as="xs:boolean" name="oxf.fr.persistence.exist.active" value="false"/>
If you need to define a resource with a name other than the default names (e.g. postgresql), you will need to provide more information as shown below (remember to replace all occurances of pg_other_name with your resource name).
<property as="xs:string" name="oxf.fr.persistence.provider.*.*.*" value="pg_other_name"/>
<property as="xs:anyURI" name="oxf.fr.persistence.pg_other_name.uri" value="/fr/service/postgresql"/>
<property as="xs:string" name="oxf.fr.persistence.pg_other_name.datasource" value="pg_other_name"/>
<property as="xs:boolean" name="oxf.fr.persistence.pg_other_name.create-flat-view" value="true"/>
<property as="xs:boolean" name="oxf.fr.persistence.pg_other_name.autosave" value="true"/>
<property as="xs:boolean" name="oxf.fr.persistence.pg_other_name.permissions" value="true"/>
<property as="xs:boolean" name="oxf.fr.persistence.pg_other_name.versioning" value="true"/>

I'm not sure what you mean by "created context in the Server.xml".
In tomcat's server.xml you should have a datasource defined. For example:
<GlobalNamingResources>
<Resource
name="jdbc/postgresql"
auth="Container"
type="javax.sql.DataSource"
initialSize="3"
maxActive="10"
maxIdle="20"
maxWait="30000"
driverClassName="org.postgresql.Driver"
validationQuery="select 1"
testOnBorrow="true"
poolPreparedStatements="true"
username="orbeon"
password="orbeon"
url="jdbc:postgresql://server:5432/database?useUnicode=true&characterEncoding=UTF8&socketTimeout=30&tcpKeepAlive=true"/>
</GlobalNamingResources>
Then in tomcat's context.xml you should have a ResourceLink for the datasource:
<ResourceLink global="jdbc/postgresql" name="jdbc/postgresql" type="javax.sql.DataSource"/>
properties-local.xml should be either in webapps/orbeon/WEB-INF/resources/config or in an external directory you have defined in tomcat's context.xml, for example:
<Parameter name="oxf.resources.priority.0" override="false" value="org.orbeon.oxf.resources.FilesystemResourceManagerFactory"/>
<Parameter name="oxf.resources.priority.0.oxf.resources.filesystem.sandbox-directory" override="false" value="C:/orbeon_resources"/>
In that case the properties-local.xml should be here: C:\orbeon_resources\properties-local.xml. See Storing configurations outside of the Orbeon Forms war file.
Also, make sure you have performed the Orbeon Forms setup. That is general database configuration, not specific to postgresql or any other database implementation. The examples they give are for oracle but you can just replace oracle with postgresql.

Related

StrategySelectionException using HikariCP with hibernate

I am new to hibernate, and I have been tasked with changing the ConnectionProvider from the hibernate default CP to either Hikari (preferred) or C3P0 in a legacy Java application that does not use maven as a repository. The database is PostgreSQL. The hibernate version is hibernate-release-5.2.10.Final. I have added hibernate-hikaricp-5.2.10.Final.jar to the classpath.
I have a pre-existing xml configuration file for hibernate. This has been working for several years, but the project wants to change to a "production ready connection pool". I have added/modified properties for the connection provider as follows:
<property name="hibernate.connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</property>
<property name="hibernate.hikari.minimumIdle">5</property>
<property name="hibernate.hikari.maximumPoolSize">20</property>
<property name="hibernate.hikari.idleTimeout">30000</property>
I am getting the following StrategySelectionException (long stack trace reduced to exceptions/causes ... more information available if necessary).
Exception in thread "DatabaseCache initialize thread" org.hibernate.service.spi.ServiceException: Unable to
create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
...
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.hikaricp.internal.HikariCPConnectionProvider] as strategy [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
I made one other change, after first seeing the exception. I added the following property, but it made no difference.
<property name="hibernate.implicit_naming_strategy">default</property>
The full configuration, with some information provided as variables replaced during build, is:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.implicit_naming_strategy">default</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.provider_class">org.hibernate.hikaricp.internal.HikariCPConnectionProvider</property>
<property name="hibernate.hikari.minimumIdle">5</property>
<property name="hibernate.hikari.maximumPoolSize">20</property>
<property name="hibernate.hikari.idleTimeout">30000</property>
<property name="hibernate.connection.username">${db_user_name}</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">${db_connection_url}</property>
<property name="hibernate.hbm2ddl.auto">none</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.jdbc.time_zone">GMT</property>
<property name="hibernate.generate_statistics">false</property> <!-- This affects performance, use only in development -->
<property name="show_sql">false</property>
</session-factory>
</hibernate-configuration>
Any strategies :D to address this would be welcome. Thanks.

Configuring database connection in Jboss FUSE

One way I know to configure DB in JBOSS FUSE is to use blueprint.xml.
Below configuration in blueprint.xml works
<bean id="gemsDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="${gems_url}" />
<property name="username" value="${gems_username}" />
<property name="password" value="${gems_password}" />
<property name="maxIdle" value="5" />
<property name="minIdle" value="1" />
<property name="initialSize" value="1" />
</bean>
However, Is there any way to configure it in JBOSS container specific configuration file. For example - In JBOSS EAP we can configure it in standalone.xml. On similar lines can we configure it in JBOSS FUSE?
Jboss Fuse provides the integration with various data sources. You need to configure them bundle wise like you have used. But no such configuration is there on container level.
You can define a Datasource in a bundle and export it. In other bundles you import and use it like a service.
Prerequisites
Install these features
features:install jdbc
features:install jndi
Datasource bundle
Drop an XML file inside deploy folder with following content:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="dataSource" class="org.postgresql.jdbc3.Jdbc3SimpleDataSource">
<property name="url" value="jdbc:postgresql://localhost:5432/databasename"/>
<property name="user" value="username"/>
<property name="password" value="xxx"/>
</bean>
<service interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/yourdatabasename_ds"/>
</service-properties>
</service>
</blueprint>
This will export a service with javax.sql.DataSource interface and a JNDI name
Use Datasource service
When a bundle needs the datasource, ask OSGi to inject it.
<blueprint>
<reference id="yourDatabaseDs"
interface="javax.sql.DataSource"
availability="mandatory"
filter="(osgi.jndi.service.name=jdbc/yourdatabasename_ds)"/>
</blueprint>
The right Datasource is retrieved using the JNDI name you provided.
Using availability="mandatory" you can force your bundle to wait for the Datasource to become available. The bundle won't start without this reference.
You need the correct JDBC drivers for the database you are using.
Other goodies
You have a lot of commands in JBoss Fuse console to interact with the database now, like jdbc:datasources that will list all available datasources. With jdbc:query you can run any SQL against your DB (good for debugging issues and testing the connection)

What kind of method is used at this statement? <property .. value = "# .. #" />

I'm taking the ownership of a Java application which works with JBoss, and I found that the Persistence.xml file have the following statments..
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.username" value="#USER#"/>
<property name="hibernate.connection.password" value="#PASSWORD#"/>..
USER and PASSWORD are declared in properties file, however the values bounded with At signs is not familiar for me. I've not seen this before, what kind of method is being used here?
If I am not mistaken this is the maven genapp plugin...
The filter itself is used copying the files defined by maven.genapp.repackage and maven.genapp.filter and will replace any occurrence of #PARAM# in the files with the value of maven.genapp.template..
At least that's where I've seen this kind of constructs before.

Illogical Results from Cucumer/Arquillian Test with H2

I am having an issue where I am attempting to create a Cucumber/Arquillian test for a new service that performs a batch update with JPQL. Everything seems to work correctly, except my #Then code validating the change.
I am setting up my test data in my feature file and it gets added to the H2 database that is created in memory for each test. When the batch update runs it reports back the expected update count based on that data. But when I retrieve one of the objects that should have been updated, the data on that object appears to be unchanged.
Please note: When I execute the service call in my application against our Oracle database it works correctly and the table is updated as expected. The problem seems to be with caching on the H2 in memory database.
My datasource that gets deployed to JBoss by Arquillian is:
<datasource enabled="true"
jndi-name="jdbc/arquillian"
pool-name="ArquillianEmbeddedH2Pool">
<connection-url>
jdbc:h2:mem:arquillian;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS TEST_DB
</connection-url>
<driver>h2</driver>
</datasource>
My Cucumber test defines #PersistenceContext(unitName = "localH2-testDB")
My persistence.xml contains:
<persistence-unit name="localH2-testDB">
<jta-data-source>jdbc/arquillian</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.cache.use_second_level_cache" value="false"/>
<property name="hibernate.cache.use_query_cache" value="false"/>
</properties>
</persistence-unit>
I don't know what other settings for the H2 database I can change to try and eliminate any caching.
It turns out the problem is inherent to how batch updates are handled in JPA. They do NOT update the persistence cache as one might expect. So the tables were updated correctly, but when the object was re-queried, it didn't have the updates. This is why my test was failing (everything was inside the same transaction) and my deployed code worked (separate transactions performing the update and re-querying the data).

Best ways to deal with properties values in XML file in Spring, Maven and Eclipses

I am working on a Spring WebFlow project which has a lot of property values in XML files, as any Spring programmer knows. I have database user names, password, URLs, etc.
We are using Eclipse with Spring WebFlow and Maven. We are trying to have an SA do the builds but the SA does not want to go into the XML files to change the values, but on the other hand, we don't know the production values. How do we work with this?
Most SA are more willing and confident to deal with .properties file rather than .xml.
Spring provide PropertyPlaceholderConfigurer to let you define everything into one or several .properties file and substitute the placeholder in applicationContext.xml.
Create a app.properties under src/main/resources/ folder:
... ...
# Dadabase connection settings:
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/app_db
jdbc.username=app_admin
jdbc.password=password
... ...
And use PropertyPlaceholderConfigurer in applicationContext.xml like so:
... ...
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>app.properties</value>
</property>
</bean>
... ...
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
Check out Spring PropertyPlaceholderConfigurer Example for more details.
In addition, from application deployment perspective, we usually package app in some executable format and the .properties files are usually packed inside the executable war or ear file. A simple solution is to configure your PropertyPlaceholderConfigurer bean to resolve properties from multiple location in a pre-defined order, so in the deployment environment, you can use a fixed location or environment variable to specify the properties file, also note that in order to simplify the deploy/configure task for SA, we usually use a single external .properties file define all runtime configuration, like so:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- Default location inside war file -->
<value>classpath:app.properties</value>
<!-- Environment specific location, a fixed path on server -->
<value>file:///opt/my-app/conf/app.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
Hope this helps.
Another simple way is Spring Expression Language (SpEL)
for example
<property name="url" value="#{ systemProperties['jdbc.url'] }" />
Documentation
spring documentations
Also you can define a propertyConfigurer programmatically in configuration class:
#Configuration
#PropertySource("classpath:application.properties")
public class PropertiesConfiguration {
#Bean
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(Environment env) {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setEnvironment(env);
return configurer;
}
}