I am trying to connect to AS400 using spring but I am having no luck.
I was wondering is it possible to set the default schema in spring using the class AS400JDBCConnectionPoolDataSource?
here is the spring configuration I am using
<bean id="DataSource" class="com.ibm.as400.access.AS400JDBCConnectionPoolDataSource">
<property name="serverName"><value>tradingdev.url.com</value></property>
<property name="user"><value>user</value></property>
<property name="password"><value>password</value></property>
<property name="dataTruncation"><value>false</value></property>
<property name="naming"><value>sql</value></property>
<property name="errors"><value>full</value></property>
<property name="trace"><value>false</value></property>
</bean>
Thanks
Damien
It is not a Spring issue, but here's how to specify the default schema:
You must set the libraries property to the default library (libraires can be see as schemas in as400 terminology). This works in 2 ways with as400, depending on how the naming property is set. If naming is set to 'sql' (as in your config), the libraries value only takes one value and is considered as the default schema. If you set the naming property to 'system', then you can specify a comma separated library list: tables and other objects names are resolved in the order specified in the list.
Related
Spring JDBC: while using JdbcTemplate how to set username and password for every user ?, Currently I am Configuring datasource object as a spring bean (Spring config.xml file ) and able to login with sinlge username and password , also used properties file and placeholder for the same
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/apu"></property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean>
What are the ways to set username value and password value for every user who logsin ?
This is my first Spring application hence not able to find right approach ..
Generally, in a web application, each user do not use its own identity to access the database. The common pattern is to have one single database user for the application, and let the application manage the permission of its own users.
As M.Deinum said, this pattern allows the application to use a connection pool, where database connections are recycled across different requests which dramatically reduces the database load (establishment of the connection is expensive)
If you look at (almost) all the spring examples an tutorial, they consitently use that approach with one single database user for the whole web application.
If you really need that each user uses it own database identity you must use a UserCredentialsDataSourceAdapter as suggested by M. Deinum, with no database pool.
We are using Spring to do JNDI look-up for our data access requirements. We are making calls to multiple stored procedures (in Sybase). I wanted a way to control the auto-commit property of the transactions while calling these stored procs. I was able to achieve it with BasicDataSource (property name="defaultAutoCommit").
But I got stuck when we moved to doing JNDI look-up (from Weblogic).
<jee:jndi-lookup jndi-name="WL_data_source" id="dataSource" />
<bean id="procedureHandlerBean" class="myclass">
<property name="procDataSource" ref="dataSource"/>
</bean>
After researching for a few days, it appears to me that I can use JtaTransactionManager. However, I am not sure if I can use the transaction manager to configure auto-commit on a per procedure call basis (due to different chained/unchained mode requirements of different procs). Is there a clean way to achieve this? Thanks
I'm currently trying to configure hibernate search via spring across 3 machines for the purpose of using a JMS distributed index. Due to the way we deploy our software I have to use the same configuration across all three machines but I need a way to set one of them to be the JMS Master.
Currently hibernate is being configured via Spring using the following bean declaration:
<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
id="productSessionFactory">
<property name="dataSource">
<ref local="productDataSource"/>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="entityInterceptor" ref="builderInterceptor"/>
<property name="eventListeners">
<map key-type="java.lang.String" value-type="java.lang.Object">
<entry key="save" value-ref="saveEventListener"/>
</map>
</property>
</bean>
On one of the three machines I need to set the property hibernate.search.default.directory_provider to filesystem-master and on the other two I need to set it to filesystem-slave.
I have the ability to set flags on the individual machines to identify which machine should be the master but due to all the configuration being XML I dont have any ability to add logic to set the parameters correctly.
Is there an way to set this parameter programmatically while leaving the rest of the configuration alone?
Thanks!
A programmatic way is generally possible, but I am not sure exactly how you do that in Spring. Instead of putting your properties into a config file you would have to build the properties dynamically (or at least partly dynamically) and pass it to AnnotationSessionFactoryBean. If I am not mistaken there are hooks in the Spring SPI which should allow you to do that, eg BeanDefinitionRegistryPostProcessor.
The other approach would be to write your own DirectoryProvider. Have a look at org.hibernate.search.store.impl.FSMasterDirectoryProvider and org.hibernate.search.store.impl.FSSlaveDirectoryProvider and write a provider which can act as slave or master depending on the flag you can read on the machine.
I would like to deploy multiple independent copies of a particular web-app on the same tomcat server under different context paths. Each web-app will need different configuration settings (database name, password, etc), but I would like to keep the wars exactly identical.
My plan was to have the app figure out its context path on startup, then read a specific .properties file outside of tomcat identified by the context path. For example, if a war was deployed to {tomcat path}/webapps/pineapple, then I would want to read /config/pineapple.properties
I've been trying to find a way to inject an instance of ServletContext via spring (3), but all the advice I've seen so far use the deprecated ServletContextFactoryBean.
Is there a better way to get the context path injected or better way to load external files based on the context path?
With the help of ServletContextAttributeFactoryBean and Spring EL, you can reference ServletContext init parameters (<context-param> in web.xml) like that:
#{contextAttributes.myKey}
This allows you to use PropertyPlaceHolderConfigurer and load property files from arbitrary, user-defined locations:
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="#{contextParameters.APP_HOME}/conf/app.properties"/>
</bean>
The corresponding definition of the ServletContext init parameter in Tomcat's context.xml:
<Parameter name="APP_HOME" value="file:/test" override="false"/>
Or in your app's web.xml:
<context-param>
<param-name>APP_HOME</param-name>
<param-value>file:/test</param-value>
</context-param>
This should be the solution.
<bean name="envConfig" class="EnvironmentConfiguration">
<property name="locations">
<list>
<value>file:///#{servletContext.contextPath}.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
Extend Propertyplaceholderconfigurer to use DB to pick up the values. Example here
Load the actual values of the settings (database name, password etc) to the db as part of seed data
When your web-app's app ctx is being initialized, the properties are resolved from the DB
This is the approach we have been following and works great. If you can switch to Spring 3.1 then it has support for Environment Profiles which may be useful for you.
I'm developing a Spring MVC application using ibatis for the database interaction layer. I'd like to be able to set the name of the database via a properties file in my classpath (or via the spring xml configuration) so I can change the database on the fly for a certain application and can be changed by setting the parameter and redeploying the application.
What I'm looking for is being able to set the database name on an existing database. Lets say I have a system called DB1 with databases: user, user_qa, and user_dev. I'd like to be able to parameterize the SQLs so that instead of doing:
SELECT * FROM user.Logins
I'd do
SELECT * FROM $database.user$.Logins
So I can change the database.user property and redeploy the application instead of rewriting a ton of SQL statements each time I changed the name of the databases.
Pretty simple to do in Spring. Say you have a basic conf file [database.properties]:
jdbc.username = user
jdbc.host = mydbserver.com
Then in your Spring config xml file :
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:database.properties</value>
</property>
</bean>
Now where you want those variables substitute the name in the config file:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="host"><value>${jdbc.host}</value></property>
<property name="username"><value>${jdbc.username}</value></property>
</bean>