on 07-25-2014 7:04 AM
Hi,
We need to get connection instance in our java code. We use MS SQL as a database. And we want to execute own query without FlexibleSearch.
Now we create connection like this:
Connection con = DriverManager.getConnection(Config.getParameter("db.url"), Config.getParameter("db.username"), Config.getParameter("db.password"));
But we want to use connection from Hybris Platform which Hybris use in FlexibleSearch. How we can do it?
Thanks.
try Registry.getCurrentTenant().getDataSource().getConnection()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Wire to you spring bean a jdbcTemplate : but really do this under only the most extreme circumstance. You will be bypassing platform caching functionality etc.
<property name="jdbcTemplate">
<bean class="org.springframework.jdbc.core.JdbcTemplate" scope="tenant">
<property name="dataSource" ref="dataSource" />
</bean>
</property>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Firstly, are you sure you really need to do this? What's the use case? This can go horribly wrong if you don't understand the issues 1. you're by passing the cache so you could be creating performance issues 2. if you're update items then the cache will probably have state entries 3. You have to take care of the joins to all the related tables yourself, it's not easy to understand the internal tables and columns that are used behind the scenes by FlexibleSearch
If you really need to do this then look at the DefaultStockDao for an example. A JdbcTemplate is wired in with a hybris datasource object e.g.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could lookup dataSource bean and from there borrow a connection. Make sure to return it to the pool after that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.