From c447d218a1b8ff628571b22cf4e74f2a6fe2e38a Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Wed, 22 Mar 2023 01:46:02 +0000 Subject: [PATCH 1/2] #224 Add Docs for spring application properties (#225) --- java/sqlcommenter-java/README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/java/sqlcommenter-java/README.md b/java/sqlcommenter-java/README.md index d8a4fdd7..7139a6d0 100644 --- a/java/sqlcommenter-java/README.md +++ b/java/sqlcommenter-java/README.md @@ -110,12 +110,35 @@ or alternatively just for a specific method #### Hibernate +##### Hibernate via JPA + If you're using Hibernate via JPA, then you can simply set the `hibernate.session_factory.statement_inspector` configuration property in the `persistence.xml` configuration file: ```xml ``` +##### Hibernate via Spring Application Properties +If you're using Hibernate via Spring application properties(i.e. you have `application.yml` or `application.properties` in your resources folder) +- `application.properties` + +```properties +spring.jpa.properties.hibernate.session_factory.statement_inspector=com.google.cloud.sqlcommenter.schibernate.SCHibernate +``` + +- `application.yml` + +```yml +spring: + jpa: + properties: + hibernate: + session_factory: + statement_inspector: com.google.cloud.sqlcommenter.schibernate.SCHibernate +``` + +##### Hibernate via Spring + If you're using Hibernate via Spring, then you might not use a `persistence.xml` configuration file, in which case, you can set up the `hibernate.session_factory.statement_inspector` configuration property as follows: From 871c1c81e014830c3f5f402a9c63d83823132542 Mon Sep 17 00:00:00 2001 From: duffn <3457341+duffn@users.noreply.github.com> Date: Mon, 22 Jul 2024 09:32:37 -0600 Subject: [PATCH 2/2] fix: Add Go controller comment (#280) --- go/database/sql/connection.go | 4 ++++ go/database/sql/connection_test.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/go/database/sql/connection.go b/go/database/sql/connection.go index 2dbb5f1d..d01d09cb 100644 --- a/go/database/sql/connection.go +++ b/go/database/sql/connection.go @@ -101,6 +101,10 @@ func (conn *sqlCommenterConn) withComment(ctx context.Context, query string) str commentsMap[core.Action] = ctx.Value(core.Action).(string) } + if config.EnableController && (ctx.Value(core.Controller) != nil) { + commentsMap[core.Controller] = ctx.Value(core.Controller).(string) + } + // `driver` information should not be coming from framework. // So, explicitly adding that here. if config.EnableDBDriver { diff --git a/go/database/sql/connection_test.go b/go/database/sql/connection_test.go index 1fcdc9f5..d977c829 100644 --- a/go/database/sql/connection_test.go +++ b/go/database/sql/connection_test.go @@ -147,7 +147,7 @@ func TestWithComment_WithContext(t *testing.T) { }, ), query: "SELECT 1;", - wantQuery: "SELECT 1/*action='any+action',application='app-1',db_driver='database%2Fsql%3Apostgres',framework='custom-golang',route='listData'*/;", + wantQuery: "SELECT 1/*action='any+action',application='app-1',controller='custom-controller',db_driver='database%2Fsql%3Apostgres',framework='custom-golang',route='listData'*/;", }, } for _, tc := range testCases {