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 { 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: