Skip to content

Improve configuration support for customizing JDBC session SQL statements #1199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BenDol opened this issue Sep 18, 2018 · 8 comments
Closed
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@BenDol
Copy link

BenDol commented Sep 18, 2018

I want to simply override the prepareQueries method in this repository class and add my overriden queries there. For some reason this is private for no obvious reason (perhaps I am missing it).

Would be like to make this method protected

protected void prepareQueries() {
    this.createSessionQuery = getQuery(CREATE_SESSION_QUERY);
    this.createSessionAttributeQuery = getQuery(CREATE_SESSION_ATTRIBUTE_QUERY);
    this.getSessionQuery = getQuery(GET_SESSION_QUERY);
    this.updateSessionQuery = getQuery(UPDATE_SESSION_QUERY);
    this.updateSessionAttributeQuery = getQuery(UPDATE_SESSION_ATTRIBUTE_QUERY);
    this.deleteSessionAttributeQuery = getQuery(DELETE_SESSION_ATTRIBUTE_QUERY);
    this.deleteSessionQuery = getQuery(DELETE_SESSION_QUERY);
    this.listSessionsByPrincipalNameQuery =
            getQuery(LIST_SESSIONS_BY_PRINCIPAL_NAME_QUERY);
    this.deleteSessionsByExpiryTimeQuery =
            getQuery(DELETE_SESSIONS_BY_EXPIRY_TIME_QUERY);
}

Thanks!

@BenDol
Copy link
Author

BenDol commented Sep 18, 2018

In fact it appears there isn't an easy way to serve my own custom JdbcOperationsSessionRepository implementation when I'm using the SessionAutoConfiguration. Would be nice if it allowed us to serve the sessionRepositoy to the JdbcHttpSessionConfiguration configuration.

Thoughts?

@BenDol BenDol changed the title Expose JdbcOperationsSessionRepository#prepareQueries() Expose JdbcOperationsSessionRepository#prepareQueries() & make JdbcOperationsSessionRepository servable Sep 18, 2018
@BenDol BenDol changed the title Expose JdbcOperationsSessionRepository#prepareQueries() & make JdbcOperationsSessionRepository servable Expose JdbcOperationsSessionRepository#prepareQueries() Sep 18, 2018
@vpavic vpavic self-assigned this Sep 20, 2018
@vpavic
Copy link
Contributor

vpavic commented Sep 20, 2018

The JdbcOperationsSessionRepository exposes a number of #set*Query methods that can be used to provide custom SQL queries. Why do you need to override prepareQueries?

Regarding Spring Boot and its SessionAutoConfiguration, the Servlet part is @ConditionalOnMissingBean(SessionRepository.class) which means if you provide a custom SessionRepository implementation as a @Bean, Spring Boot will back-off, which is reasonable.

@vpavic vpavic added for: stack-overflow A question that's better suited to stackoverflow.com status: waiting-for-feedback We need additional information before we can continue labels Sep 20, 2018
@BenDol
Copy link
Author

BenDol commented Sep 21, 2018

Yeah unfortunately I've just had to replicate JdbcSessionConfiguration and JdbcHttpSessionConfiguration and have it load the JdbcOperationsSessionRepository before SessionAutoConfiguration. I have to do this because I still want all the default configurations that spring-session and spring-boot provides, I just wanted to serve my own SessionRepository implementation to be used with the configurations.

@vpavic
Copy link
Contributor

vpavic commented Oct 24, 2018

Yes, Spring Boot's auto-configuration will back-off once you provide a SessionRepository bean. Maybe we can look into providing some hook point in JdbcHttpSessionConfiguration that would allow the users to customize the SQL without manually registering JdbcOperationsSessionRepository bean.

@vpavic vpavic removed the status: waiting-for-feedback We need additional information before we can continue label Oct 24, 2018
@moleksyuk
Copy link

moleksyuk commented Mar 7, 2019

Hi @vpavic
I've got similar problem with defining custom names for SPRING_SESSION & SPRING_SESSION_ATTRIBUTES tables.

I can override just table name for SPRING_SESSION by org.springframework.session.jdbc.JdbcOperationsSessionRepository#setTableName
BUT for I would like to have org.springframework.session.jdbc.JdbcOperationsSessionRepository#setSessionAttributeTableName
because I would like to define tables with the same naming convention as it already exists in my schema (all tables in lower case) but will get:
session - aka SPRING_SESSION
session_ATTRIBUTES - aka SPRING_SESSION_ATTRIBUTES
which look strange 😞

UPDATE: created a new issue #1347

@vpavic
Copy link
Contributor

vpavic commented Mar 12, 2019

Hi @moleksyuk - as your request is a bit different, could you please open a new issue?

@vpavic vpavic added status: waiting-for-triage An issue we've not yet triaged and removed for: stack-overflow A question that's better suited to stackoverflow.com labels Jun 1, 2019
@vpavic vpavic added this to the General Backlog milestone Jun 1, 2019
@vpavic vpavic added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 2, 2019
@vpavic vpavic modified the milestones: General Backlog, 2.2.x Aug 2, 2019
@vpavic vpavic added the in: jdbc label Aug 2, 2019
@vpavic vpavic changed the title Expose JdbcOperationsSessionRepository#prepareQueries() Improve configuration support for customizing JDBC session SQL statements Aug 2, 2019
@vpavic vpavic modified the milestones: 2.2.x, 2.2.0.RC1 Aug 24, 2019
vpavic added a commit to vpavic/spring-session that referenced this issue Aug 28, 2019
@vpavic
Copy link
Contributor

vpavic commented Sep 3, 2019

Instead of going with configuration API that's focused on JdbcOperationsSessionRepository and configuring custom SQL, we've decided to go in a bit more generic direction and provide session repository customizers - see #1499.

That will allow to apply more advanced configuration without have to register the session repository bean manually, and therefore have Spring Boot's auto-configuration back off.

@vpavic vpavic closed this as completed Sep 3, 2019
@vpavic vpavic added status: declined A suggestion or change that we don't feel we should currently apply and removed in: jdbc type: enhancement A general enhancement labels Sep 3, 2019
@vpavic vpavic removed this from the 2.2.0.RC1 milestone Sep 3, 2019
@pmgkrishna
Copy link

pmgkrishna commented Apr 17, 2020

@vpavic can you share any spring document to ovverride a jdbcOperationsSessionRepository with customOperationSessionRepository to provide a custom sql queries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants