Configuring 2 database in mybatis + springs - database

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.

Related

Graph API to get all AAD Properties

Is there a Graph API which can be used to get a list of all properties which AAD supports. I dont need these properties to be user specific. All I need is the name of the properties (ex - firstname, lastname, phoneNo etc).I dont need to hard code these properties in my code I want to know if there is any API to get all the properties name. I only have tenant related data like tenant Id.
The closest thing that you might be looking for is probably the EDM metadata available here: https://graph.microsoft.com/v1.0/$metadata.
It's in XML, but if you parse it and find the EntityType element with Name="user" attribute, you can see what properties it has:
<EntityType Name="user" BaseType="graph.directoryObject" OpenType="true">
<Property Name="accountEnabled" Type="Edm.Boolean"/>
<Property Name="ageGroup" Type="Edm.String"/>
<Property Name="assignedLicenses" Type="Collection(graph.assignedLicense)" Nullable="false"/>
<Property Name="assignedPlans" Type="Collection(graph.assignedPlan)" Nullable="false"/>
<Property Name="businessPhones" Type="Collection(Edm.String)" Nullable="false"/>
<Property Name="city" Type="Edm.String"/>
<Property Name="companyName" Type="Edm.String"/>
<Property Name="consentProvidedForMinor" Type="Edm.String"/>
<Property Name="country" Type="Edm.String"/>
<Property Name="creationType" Type="Edm.String"/>
<Property Name="department" Type="Edm.String"/>
<Property Name="displayName" Type="Edm.String"/>
<!-- Lot of other properties... -->
</EntityType>
The OpenAPI documents are also available in GitHub: https://github.com/microsoftgraph/microsoft-graph-openapi.
They aren't available through a URL like the EDM metadata, but seems that is future plan:
Our plans are to expose the OpenAPI descriptions for Microsoft Graph as part of the service itself

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

Cant save SQL output to a File in Apache Camel

I been trying this camel-sql example to fetch some rows from the back-end oracle.
Datasource definition:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#localhost:port:sid"/>
<property name="username" value="username"/>
<property name="password" value="password"/>
</bean>
Routes Definition:
<route id="QueryTable">
<from uri="timer:foo?period=5s"/>
<to uri="sql:{{sql.selectOrder}}"/>
<to uri="file:target/data/?fileName=data.txt"/>
</route>
It seems to fetch the row properly, but, does not create the file and reports the following exceptions. Any help would be highly appreciated.
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:198)
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:105)
... 16 more
http://camel.apache.org/sql-component.html
For select operations, the result is an instance of List<Map<String, Object>> type, as returned by the JdbcTemplate.queryForList() method.
You received List<Map<String, Object>> as result of the query. If you like to save this results to file, you have to split list by records (use splitter), convert one record to string (maybe you can use some sort of template, or just join to string fields values) and save (append) this string to file.
Thanks for the kind help. Here is what I used to save the resultSet to a file.
<from uri="timer:foo?repeatCount=1" />
<to uri="sql:{{sql.selectOrder}}"/>
<marshal>
<csv delimiter="|" />
</marshal>
<to uri="file://target/test.csv?fileName=data.txt" />
And of course, pom.xml has to have the following dependency added.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-csv</artifactId>
</dependency>

How to use SQL Server 2008 R2 as persistent storage for ActiveMQ 5.9

My IT infrastructure requires persistence based on a SQL Server 2008 R2 database.
I'm trying to configure SQL Server persistence for ActiveMQ 5.9 on windows, but can't figure out a correct configuration schema with or without journalling.
The default configuration uses kahadb, and it works:
<persistenceAdapter>
<kahaDB directory="${activemq.data}/kahadb" />
</persistenceAdapter>
I'm using this documentation a reference to configure SQL Server persistence:
http://activemq.apache.org/sqlserver.html
<persistenceAdapter>
<journaledJDBC journalLogFiles="5" dataDirectory="../activemq-data" dataSource="#mssql-ds">
<adapter><imageBasedJDBCAdaptor/></adapter>
</journaledJDBC>
</persistenceAdapter>
<bean id="mssql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="url" value="jdbc:sqlserver://HOST:PORT;databaseName=DBNAME;user=USER;password=PASSWORD"/>
<property name="username" value="USER"/>
<property name="password" value="PASSWORD"/>
</bean>
This is the error in xml parser I get:
ERROR | Failed to load: class path resource [activemq.xml], reason: Line 88 in XML document from class path resource [activemq.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 88; columnNumber: 95; cvc-complex-type.2.4.a: Invalid content was found starting with element 'journaledJDBC'. One of '{"http://activemq.apache.org/schema/core":jdbcPersistenceAdapter, "http://activemq.apache.org/schema/core":journalPersistenceAdapter, "http://activemq.apache.org/schema/core":kahaDB, "http://activemq.apache.org/schema/core":levelDB, "http://activemq.apache.org/schema/core":mKahaDB, "http://activemq.apache.org/schema/core":memoryPersistenceAdapter, "http://activemq.apache.org/schema/core":replicatedLevelDB, WC[##other:"http://activemq.apache.org/schema/core"]}' is expected.
Please help me to figure out the configuration schema for SQL Server persistence, or provide a documentation link specific to version ActiveMQ 5.9
this is what I use for oracle. Maybe it's just a matter of changing the jdbc information from the datasource (as any other datasource)
(sorry, no SQL Server here to test)
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" producerFlowControl="true">
<pendingMessageLimitStrategy>
<constantPendingMessageLimitStrategy limit="1000" />
</pendingMessageLimitStrategy>
</policyEntry>
<policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb">
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#oracle-ds" />
</persistenceAdapter>
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="128 mb" />
</memoryUsage>
<storeUsage>
<storeUsage limit="100 gb" />
</storeUsage>
<tempUsage>
<tempUsage limit="50 gb" />
</tempUsage>
</systemUsage>
</systemUsage>
<transportConnectors>
<transportConnector name="tcp" uri="tcp://0.0.0.0:61616" />
</transportConnectors>
</broker>
<bean id="oracle-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#localhost:1521:XE" />
<property name="username" value="xxx" />
<property name="password" value="xxx" />
<property name="poolPreparedStatements" value="true" />
<property name="maxActive " value="30" />
</bean>
</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.

Resources