Execute sql statement before normal execution with aop

若如初见. 提交于 2019-12-11 12:40:25

问题


I'm trying to create a Multitenant application with spring.

I'm trying to have a different schema for each Tenant on a PostgreSql database.

I first created a TenantAwareDataSource extending org.springframework.jdbc.datasource.AbstractDataSource where basically I manage a Map of org.apache.commons.dbcp.BasicDataSource, configuring setConnectionInitSqls() for each tenant. (The datasource the project had before was org.apache.commons.dbcp.BasicDataSource)

But then discussing it with a friend, we came up with the idea of changing the schema for every statment executed with an aspect (aop), simply adding a set search_path to statement just before normal execution.

This could greatly simplify the problems related to having too many connections to the database (a connection pool for every tenant at any given time).

Has anybody executed additional statements using AOP? Any pitfalls to overcome?

I'm thinking on put back org.apache.commons.dbcp.BasicDataSource and intercept java.sql.Statements.exe*(..)

I'm not very experienced with Spring persistence. Or SQL statement execution interception for that matter (haha). Is it ok?

I found this article but I don't think I need to obtain a reference for each connection. Am I right?

Also found this one. The author is using org.springframework.jdbc.core.JdbcOperations. Not sure it's the case in my Spring Roo generated project.

Thank you all.

来源:https://stackoverflow.com/questions/19301643/execute-sql-statement-before-normal-execution-with-aop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!