nhibernate configuration multiple databases - database

i have this configuration
var config = new Configuration().Configure(path);
config.AddAssembly(Assembly.GetCallingAssembly());
_factory = config.BuildSessionFactory();
and nhibernate.cfg.xml file
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="ServiceCenter.DataAccess">
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Data Source=.\SQLEXPRESS;Initial Catalog=111;User Id=111;Password=111;
</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
</session-factory>
</hibernate-configuration>
I want to have 2 connection strings. I try to add second connection string and second
session-factory in config file, but it was not correct.

There's a good extension for this called NHibernate-X-Factories. Have a look at this answer: Configure NHibernate hibernate.cfg.xml file to have more connection strings

There is a good material available here here

Related

MDB not persisting data in sql server

I have MDB configured to receive incoming message and persist it via a SLSB using JPA (eclipseLink). The database inserts work for one off message but in load conditions (3 or 4 messages per second), Data is not persisted in DB. I can see sql Insert queries in the log but no data in DB.
Persistence File:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<!-- <persistence-unit name="mainPU" transaction-type="JTA"> -->
<persistence-unit name="mainPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>ecpcPool</jta-data-source>
<class>com.fc.ECP.domain.Address</class>
<class>com.fc.ECP.domain.Customer</class>
<class>com.fc.ECP.domain.DocumentationSignature</class>
<class>com.fc.ECP.domain.EcpSystem</class>
<class>com.fc.ECP.domain.EcpTransaction</class>
<class>com.fc.ECP.domain.EcpWkflw</class>
<class>com.fc.ECP.domain.EidVerify</class>
<class>com.fc.ECP.domain.EsignDetail</class>
<class>com.fc.ECP.domain.Finpln</class>
<class>com.fc.ECP.domain.FinplnDocumentation</class>
<class>com.fc.ECP.domain.ThirdPartyCrdntl</class>
<class>com.fc.ECP.domain.ThirdPartyDocumentation</class>
<class>com.fc.ECP.domain.TransactionType</class>
<class>com.fc.ECP.domain.Advice</class>
<class>com.fc.ECP.domain.Advcln</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="eclipselink.target-server" value="WebLogic_10"
/>
<property name="javax.persistence.jtaDataSource"
value="ecpcPool" />
<!-- <property name="javax.persistence.jtaDataSource"
value="jdbc/MicrosoftSQLServer"/> -->
<!-- <property name="javax.persistence.jtaDataSource"
value="ecp_prx_ds"/> -->
<property name="eclipselink.target-database"
value="org.eclipse.persistence.platform.database.SQLServerPlatform" />
<property name="eclipselink.session.customizer"
value="com.fc.adr.jpa.JPASessionCustomizer" />
<property name="com.fc.adr.jpa.schema" value="$(mainPU.schema)"
/>
<property name="com.fc.adr.jpa.schema.sequences"
value="$(mainPU.schema.sequences)" />
<property name="eclipselink.logging.logger"
value="DefaultLogger" />
<property name="eclipselink.logging.level.sql" value="FINE" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.parameters" value="true" />
<property name="eclipselink.persistence-context.flush-mode"
value="commit" />
</properties>
</persistence-unit>
</persistence>
Switch to EJB2 style config for MDB.
Underlying Cause:
The EJB3 style MDB ‘s methods are wrapped by CDI injection.
One of the wrapper classes in the stack trace is: com.oracle.pitchfork.intercept.MethodInvocationInvocationContext
which is in a spring framework module jar in weblogic
MethodInvocationInvocationContext looks for a WebServiceContext in the JNDI tree at “java:comp/WebServiceContext”
Having a jax-ws service puts a WebServiceContext at “java:comp/WebServiceContext”
If the WebServiceContext is present, then MethodInvocationInvocationContext tries to access its values for the MessageDrivenContext
The spec requires WebServiceContext to throw an IllegalStateException if it is accessed outside of a web service call

Configuring 2 database in mybatis + springs

I have an existing setup of mybatis + springs for working with Oracle DB. I have a set of java mapper interfaces, a set of corresponding mapper xmls (each having reference to their corresponding java mapper). I need to setup support for MSSQL also, but finding it hard to do that. I have created a separate set of xmls (specific to queries of MSSQL) in com/mycomp/mob/db/mappers/mssql.
Below is the extract of my applicationConext.xml (Here DBDataSource is an internal class which reads a config files to get all DB details).
<bean name="dataSource" class="com.mycomp.mob.core.db.DBDataSource">
<constructor-arg index="0" name="dbAlias" value="mob" />
<constructor-arg index="1" name="cfgSection" value="primary" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mycomp.mob.db.mappers.oracle" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.mycomp.mob.db.mappers.oracle" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
Below is part of mybatis-config.xml (here ${} params are replaced using the earlier DBDatasource)
<configuration>
<typeAliases>
<package name="com.mycomp.mob.db.model" />
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/mycomp/mob/db/mappers/oracle/tenant.xml" />
<mapper resource="com/mycomp/mob/db/mappers/oracle/functionenty.xml" />
</mappers>
</configuration>
com.mycomp.mob.db.model contains POJO for tenant and functionentry.
Usage is as below :
ITenantMapper mappper = sqlSessionFactory.openSession().getMapper(ItenantMapper.class)
Tenant t = mapper.getTenant();
Now at a time only one DB (which is configured as primary in DB config file) will be used. So how to make sure that XML corresponding to that particular DB is invoked by the java mapper interface.
Also need to know can I configure same java mapper class name inside the mapper xmls of mssql ?
Is the flow used correct or I need to change the flow for supporting multiple databases.
Create two datasources and two SessionFactories in spring one for Oracle another for MSSQL.

Rename Liquibase changelog tables

I'm using Liquibase (v 3.0.7) together with Spring (v 4.0.0):
<!-- Liquibase configuration -->
<bean id = "liquibase" class = "liquibase.integration.spring.SpringLiquibase">
<property name = "dataSource" ref = "dataSource" />
<property name = "changeLog" value = "classpath:database/changelog.xml" />
</bean>
Once I've deployed my Spring application, Liquibase will create two tables: databasechangelog and databasechangeloglock. Is there a way to rename those two tables?
You can use system properties to override the default table names.
Or you can use small workaround to setup this names in spring configuration, check this answer for Java configuration - https://stackoverflow.com/a/50644347 or you can use this for xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="liquibaseSystemPropsSetter"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" value="#{#systemProperties}"/>
<property name="targetMethod" value="putAll"/>
<property name="arguments">
<util:properties>
<prop key="liquibase.databaseChangeLogTableName">${application.liquibase.change.log.table.name}</prop>
<prop key="liquibase.databaseChangeLogLockTableName">${application.liquibase.change.log.lock.table.name}
</prop>
</util:properties>
</property>
</bean>
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase"
depends-on="liquibaseSystemPropsSetter"
p:dataSource-ref="localDataSource"
p:changeLog="classpath:${application.liquibase.change.log.path}"
p:shouldRun="${application.liquibase.should.run}"/>
</beans>

wso2 esb to download/get a local file

I have some static files (some are HTML, some are images and some are pure data files - like .csv or .xls etc) that I want to share through the ESB. I can make that happen if I run a separate HTTP server that will receive the request for these through ESB. Instead, I like to handle it in ESB itself. Based on the incoming request URL (say HTTP GET request - http://myesb.com:8280/getstatus.html ), I like to pull these static files from the local server's folders.
I tried the VFS method and it looks like has built in "refresh" mechanism that I don't want. I want to "GET" these data only when the clients are requesting for it.
In short, I like to have a simple mapping done like this:
http://myesb.com:8280/getstatus.html will fetch the contents of /var/myapp/status/appstatus.html file.
Update
I did the following sequence - don't know how to make it work :(
<sequence xmlns="http://ws.apache.org/ns/synapse" name="app1status">
<in>
<log level="custom">
<property name="Reached app1status page - in" value="app1 Status"/>
<property name="transport.vfs.ContentType" value="text/html"/>
<property xmlns:ns="http://org.apache.synapse/xsd" name="TRPURL:" expression="get-property('From')"/>
</log>
<property name="transport.vfs.FileURI" value="vfs:file:///opt/platform/traffic/app1status1.html" scope="transport" type="STRING"/>
<property name="HTTP_METHOD" value="GET"/>
<property name="ClientApiNonBlocking" action="remove" scope="axis2"/>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true" scope="default" type="STRING"/>
</in>
<out>
<log level="custom">
<property name="::::::Out:::::Reached app1status" value=" From OUT"/>
<property name="messageType" value="text/html"/>
<property name="ContentType" value="text/html"/>
</log>
<send/>
</out>
</sequence>
Note the following in the <in> mediator:
<property name="transport.vfs.FileURI" value="vfs:file:///opt/platform/traffic/app1status1.html" scope="transport" type="STRING"/>
My intent is to get the content of the file appstatus1.html retrieved and send back as the response. But I am not able to get the contents retrieved and added to the "RESPONSE"
Let me know how it can be done.
Thanks for your time.
Define a RESTAPI and based on GET/PUT pull or post data to your server.

Google App Engine & JDO: Transaction is not written to the datastore

We are using GAE with JDO2.3 and have this code:
public void submit_job (HttpSession session, BlobKey blobKey) throws Exception {
// START TRANSACTION
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
tx.begin();
// GET JOB AND MEMBER FROM DATASTORE
Key jobKey = (Key)session.getAttribute("jobkey");
String userName = session.getAttribute("username").toString();
Job job = pm.getObjectById(Job.class, jobKey);
Member m = pm.getObjectById(Member.class, username);
// STORE JOB INFORMATION IN DATASTORE
Date now = new Date();
job.caricature = blobKey;
job.whenSubmitted = now;
job.whenFinished = now;
pm.makePersistent(job);
pm.flush();
log.warning("submit_job: updating job " + job.key);
// UPDATE MEMBER INFORMATION
m.numSubmittedJobs++;
pm.makePersistent(m);
pm.flush();
log.warning("submit_job: updating user " + username);
// COMPLETE TRANSACTION
tx.commit();
pm.close();
log.warning("transaction completed? " + !tx.isActive());
}
The symptoms:
no exception is thrown, everything runs fine
at the end, the transaction is properly completed ("transaction completed? true")
following queries can read the updated data from the Member and Job objects
BUT
the information does not show up in the datastore manager
after restarting the instance, the JDO objects have their old values. ALL CHANGES ARE LOST.
Here is our jdoconfig.xml:
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
<property name="datanucleus.appengine.singletonPMFForName" value="true"/>
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
</persistence-manager-factory>
</jdoconfig>
and the persistence.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
</properties>
</persistence-unit>
</persistence>
Any help is appreciated, we already put a lot of effort into this topic, but are unable to solve it yet.
Thanks!
So you're setting public fields of a persistable class, and somehow expect the persistence mechanism to know about this. As per the JDO spec, you should use setters, or annotate the class doing the setting as PersistenceAware.
And look at the log too, since it tells you what is happening

Resources