Database configuration with WildFly - postgresql

I intend to configure postgresql in my app, but I don't want to manage access to my db through WildFly. Is it possible to avoid this approach and to chose another way but with jndi?

If you want to connect a postgresql database without abstraction layer such as wildFly, you can use simply jdbc (https://jdbc.postgresql.org/about/about.html) :
PostgreSQL JDBC Driver (PgJDBC for short) allows Java programs to
connect to a PostgreSQL database using standard, database independent
Java code. Is an open source JDBC driver written in Pure Java (Type
4), and communicates in the PostgreSQL native network protocol.
If you prefer a lightweight ORM (Object Relational Mapping), I would advise activejdbc (http://javalite.io/activejdbc).

Here you can find the configuration of Wildfly Wildfly datasource configuration . The datasource can be access with jndi. You have to replace the example-jdbc-driver with postgres driver.
Bellow is my example of configuration of datasource for IBM-informix
<datasource jndi-name="java:jboss/datasources/mvpdb" pool-name="mvpdbpool">
<connection-url>jdbc:informix-sqli://mars.bza-intern.de:30020/demomvp:informixserver=tcpmars;DB_LOCALE=de_DE.8859-1;IFX_LOCK_MODE_WAIT=10;</connection-url>
<driver>informix</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>3</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>abcd</user-name>
<password>efgh</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
The datasource can be access ( Spring context ):
with Java Configuration
#Bean(name = "mvpds", autowire = Autowire.BY_NAME)
public DataSource Mvpds() {
logger.info("Mvpds-bean");
final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
dsLookup.setResourceRef(true);
DataSource ds = dsLookup.getDataSource("java:jboss/datasources/mvpdb");
return ds;
}
or XML definition
<bean id="mvpds" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>java:jboss/datasources/mvpdb</value></property>
</bean>

The question was not correct because of lack of knowledge. The promblem is that no way to configure db without WildFly but with jndi. Jndi is an instrument WildFly uses to find a datasourse:)

Related

How to enable failover for a postgresql jdbc data source

I have a data source defined in a Liberty application server for postgresql
<dataSource jdbcDriverRef="PostgreSQLDriver" ...>
<properties password="..." user="admin" serverName="server" portNumber="2020" databaseName="dbname" ssl="false"
</dataSource>
I see that I can enable failover on a jdbc connection by specifying a url like:
jdbc:postgresql://host1:port,host2:port,host3:port/dbname
Is there any way that this failover url can be provided to a application server datasource?
Yes, you can specify any key/value pair on the <properties> element and Liberty will supply it to the vendor data source class. In this case, the property would be URL="jdbc:postgresql://host1:port,host2:port,host3:port/dbname"
Also, note that in more recent versions of Liberty, there is a properties.postgresql which is specific to Postgres and better documents the available settings for it.
Here is an example,
<dataSource jdbcDriverRef="PostgreSQLDriver" ...>
<properties.postgresql password="..." user="admin" URL="jdbc:postgresql://host1:port,host2:port,host3:port/dbname" ssl="false"
</dataSource>

How to configure Read Only Datasource in Jboss teiid

I have configured a Redshift Datasource in Jboss teiid. I want to know how to make my Datasource Read Only. I know how make Read Only resources on VDB level using Dataroles (Ref:- https://github.com/teiid/teiid-quickstarts/blob/master/vdb-dataroles/src/vdb/portfolio-vdb.xml). But this would allow to create new VDBs which are not Read Only which is a vulnerability in my case. I want to do this in Datasource configuration level in domain.xml. Is there any guidance on how to do this.
I am not using teiid Designer and I configure Datasources editing the domain.xml file. I add the fallowing Datasource under the Datasources sub element in the domain.xml file
<datasource jndi-name="java:jboss/datasources/redshiftDS" pool-name="redshiftDS" enabled="true" use-java-context="true">
<connection-url>jdbc:redshift://***********.com:5439/schema</connection-url>
<driver>redshift</driver>
<security>
<user-name>${user_name}</user-name>
<password>${pw}</password>
</security>
<pool>
<!--min-pool-size>
10
</min-pool-size-->
<max-pool-size>
5
</max-pool-size>
</pool>
</datasource>
Is there any way I can configure the Datasource to be read only here. For an example adding something like
<access-permission>
read-only
</access-permission>
The simplest alternative from a Teiid perspective is to add a data role for any authenticated for all schemas that you don't users to have write access to:
<data-role name="read-only" any-authenticated="true" allow-create-temporary-tables="true">
<description>read only access</description>
<permission>
<resource-name>schema name</resource-name>
<allow-read>true</allow-read>
<allow-execute>true</allow-execute>
</permission>
</data-role>
There was a flag on translators to set them as immutable - but support for that was removed.
Mark all your tables as non updatable. If you are using designer there is property on table or columns or you can do same using DDL too.

Issue enabling jpa and jdbc in Websphere Liberty

I am following these exercises for learning Liberty.
I am having an issue in he Lab 3 - Module 2.2 Liberty and JPA (DB2) .
After setting all the JDBC and Data Source details, i restart the server and i do not see the two lines that mention the dataSource and jdbd driver.
[AUDIT] J2CA8004I : The dataSource DB2Connection is avilable as jdbc/DB2Connection.
[AUDIT] J2CA8000I : The jdbcDriver my JDBCDriver is available.
How can i know if the jpa and jdb features ae correctly set?
This is the server.xml
<!-- Enable features -->
<featureManager onError="WARN">
<feature>jsp-2.2</feature>
<feature>jpa-2.0</feature>
<feature>jdbc-4.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443" />
<jdbcDriver id="myJDBCDriver">
<library name="DB2Lib">
<fileset dir="C:\wlp\db2jdbc" includes="db2jcc4.jar, db2jcc_license_cu.jar"></fileset>
</library>
</jdbcDriver>
<dataSource jndiName="jdbc/DB2Connection" id="DB2Connection"
jdbcDriverRef="myJDBCDriver">
<properties.db2.jcc databaseName="SAMPLE" serverName="igacloud" password="{xor}FhgeOz1tPj08" user="db2admin"></properties.db2.jcc>
</dataSource>
Unlike Classic WebSphere, which has a "test connection" capability in its admin console (datasource panel), there is no equivalent means with WebSphere Liberty yet. Have you tried testing the connection with a simple "Hello World" JPA application?
The CWWKF0012I message is simply confirming what features have been enabled - some features depend on other features and automatically enables them, which is why you see more features than defined in your server.xml.

How to integrate the WSO2 Data Services 3.0 with Oracle 10g

We use Windows Server 8 with Oracle 10g (R 10.2.0.2).
We believe that the Oracle JDBC Jar is correct, we tested some possibilities.
The problem now when we tested the connection is: "provided data source type not supported".
Anybody have any suggestion?
Thanks so much!
I believe there must be an issue with your datasource configuration defined in master-datasources.xml or any other *-datasources.xml you are using in your environment. Please double check whether the following line is defined properly in your datasource configuration. All the RDBMS databases should be configured having the definition type as "RDBMS".
<definition type="RDBMS">
A complete sample datasource configuration for your requirement is depicted below.
<datasource>
<name>testds</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/testds</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:oracle:thin:#localhost:1521:XE</url>
<username>test</username>
<password>test</password>
<driverClassName>oracle.jdbc.OracleDriver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1 FROM DUAL</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
Hope this helps.
Regards,
Prabath

TopLink with JPA taking more connections

In my application we are using Toplink with Jpa.
Here the problem is we are using stored procedures in this application, we are taking the connection using Jndi connection for Stored Procedure calling, and we are using EntityManger for remaining queries. But here if we launching the application it is taking two connections from connection pool. After the application launching I am calling the Stored Procedure(sp)
one sp I am taking one connection but in websphere connection pool it is creating two connections?
can U plese help me how to overcome this problem.....
I won't using JTA, to get the JDBC connection I am using
EntityManager em = getJpaTemplate().getEntityManagerFactory().createEntityManager();
this way I am getting the JDBC Connection...and I configured the persitence.xml file following code...
<properties>
<property name="toplink.logging.level" value="OFF"/>
<property name="toplink.cache.type.default" value="NONE"/>
<property name="com.thoughtinc.runtime.persistence.sql.syntax" value="db2" />
</properties>
So, please kindly look into this and tell me any if I am doing any wrong here.
Are you using JTA or non-JTA? Are you releasing the connection back to the pool after using it?
Depending on your configuration (include your persistence.xml), if you have a non-JTA login configured TopLink may use this for non-transactional read queries. This is configurable in your persistence.xml.
To get the JDBC Connection from a TopLink (EclipseLink) EntityManager use em.unwrap(Connection.class)