This is an automated email from the ASF dual-hosted git repository.
soulasuna pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 734191b0617 Add encrypt-spring-boot-jpa-example for encrypt-example
(#19141)
734191b0617 is described below
commit 734191b06174a665d115b1da573786b775d4bfa8
Author: RunQi Zhao <[email protected]>
AuthorDate: Thu Jul 14 20:11:20 2022 +0800
Add encrypt-spring-boot-jpa-example for encrypt-example (#19141)
* Add encrypt-spring-boot-jpa-example for encrypt-example
* fix ci
* fix ci
* fix ci
---
.../{ => encrypt-spring-boot-jpa-example}/pom.xml | 33 +++++++++++------
.../boot/jpa/EncryptSpringBootJpaExample.java | 41 ++++++++++++++++++++++
.../application-encrypt-databases.properties | 37 +++++++++++++++++++
.../src/main/resources/application.properties | 22 ++++++++++++
.../src/main/resources/logback.xml} | 37 +++++++++----------
.../single-feature-example/encrypt-example/pom.xml | 1 +
6 files changed, 140 insertions(+), 31 deletions(-)
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/pom.xml
similarity index 59%
copy from
examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
copy to
examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/pom.xml
index 890ed84848f..e961ae17bf8 100644
---
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/pom.xml
@@ -22,18 +22,29 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere.example</groupId>
- <artifactId>single-feature-example</artifactId>
+ <artifactId>encrypt-example</artifactId>
<version>${revision}</version>
</parent>
- <artifactId>encrypt-example</artifactId>
+ <artifactId>encrypt-spring-boot-jpa-example</artifactId>
<name>${project.artifactId}</name>
-
- <packaging>pom</packaging>
-
- <modules>
- <module>encrypt-raw-jdbc-example</module>
- <module>encrypt-spring-boot-mybatis-example</module>
- <module>encrypt-spring-namespace-mybatis-example</module>
- <module>encrypt-spring-namespace-jpa-example</module>
- </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere.example</groupId>
+ <artifactId>example-spring-jpa</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ </dependency>
+ </dependencies>
</project>
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/boot/jpa/EncryptSpringBootJpaExample.java
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/boot/jpa/EncryptSpringBootJpaExample.java
new file mode 100644
index 00000000000..15ff30d319e
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/java/org/apache/shardingsphere/example/encrypt/spring/boot/jpa/EncryptSpringBootJpaExample.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.encrypt.spring.boot.jpa;
+
+import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
+import org.apache.shardingsphere.example.core.api.service.ExampleService;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import
org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.ComponentScan;
+
+import java.sql.SQLException;
+
+@ComponentScan("org.apache.shardingsphere.example.core.jpa")
+@EntityScan(basePackages = "org.apache.shardingsphere.example.core.jpa.entity")
+@SpringBootApplication(exclude = JtaAutoConfiguration.class)
+public class EncryptSpringBootJpaExample {
+
+ public static void main(String[] args) throws SQLException {
+ try (ConfigurableApplicationContext applicationContext =
SpringApplication.run(EncryptSpringBootJpaExample.class, args)) {
+
ExampleExecuteTemplate.run(applicationContext.getBean(ExampleService.class));
+ }
+ }
+}
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/application-encrypt-databases.properties
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/application-encrypt-databases.properties
new file mode 100644
index 00000000000..e03ba151d58
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/application-encrypt-databases.properties
@@ -0,0 +1,37 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+spring.shardingsphere.datasource.names=ds
+
+spring.shardingsphere.datasource.ds.type=com.zaxxer.hikari.HikariDataSource
+spring.shardingsphere.datasource.ds.driver-class-name=com.mysql.jdbc.Driver
+spring.shardingsphere.datasource.ds.jdbc-url=jdbc:mysql://localhost:3306/demo_ds?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
+spring.shardingsphere.datasource.ds.username=root
+spring.shardingsphere.datasource.ds.password=
+
+spring.shardingsphere.rules.encrypt.encryptors.name-encryptor.type=AES
+spring.shardingsphere.rules.encrypt.encryptors.name-encryptor.props.aes-key-value=123456abc
+spring.shardingsphere.rules.encrypt.encryptors.pwd-encryptor.type=AES
+spring.shardingsphere.rules.encrypt.encryptors.pwd-encryptor.props.aes-key-value=123456abc
+
+spring.shardingsphere.rules.encrypt.tables.t_user.columns.username.cipher-column=username
+spring.shardingsphere.rules.encrypt.tables.t_user.columns.username.encryptor-name=name-encryptor
+spring.shardingsphere.rules.encrypt.tables.t_user.columns.pwd.cipher-column=pwd
+spring.shardingsphere.rules.encrypt.tables.t_user.columns.pwd.encryptor-name=pwd-encryptor
+
+spring.shardingsphere.props.query-with-cipher-column=true
+spring.shardingsphere.props.sql-show=true
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/application.properties
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/application.properties
new file mode 100644
index 00000000000..c1d415a8b0d
--- /dev/null
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/application.properties
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
+spring.jpa.properties.hibernate.show_sql=false
+
+spring.profiles.active=encrypt-databases
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/logback.xml
similarity index 50%
copy from
examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
copy to
examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/logback.xml
index 890ed84848f..8dd6239a654 100644
---
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/encrypt-spring-boot-jpa-example/src/main/resources/logback.xml
@@ -16,24 +16,21 @@
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.shardingsphere.example</groupId>
- <artifactId>single-feature-example</artifactId>
- <version>${revision}</version>
- </parent>
- <artifactId>encrypt-example</artifactId>
- <name>${project.artifactId}</name>
+<configuration>
+ <property name="log.context.name" value="encrypt-spring-boot-jpa-example"
/>
+ <property name="log.charset" value="UTF-8" />
+ <property name="log.pattern" value="[%-5level] %date --%thread-- [%logger]
%msg %n" />
+ <contextName>${log.context.name}</contextName>
- <packaging>pom</packaging>
-
- <modules>
- <module>encrypt-raw-jdbc-example</module>
- <module>encrypt-spring-boot-mybatis-example</module>
- <module>encrypt-spring-namespace-mybatis-example</module>
- <module>encrypt-spring-namespace-jpa-example</module>
- </modules>
-</project>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder charset="${log.charset}">
+ <pattern>${log.pattern}</pattern>
+ </encoder>
+ </appender>
+ <logger name="org.springframework" level="WARN" />
+ <logger name="com.zaxxer.hikari" level="WARN" />
+ <root>
+ <level value="INFO" />
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
diff --git
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
index 890ed84848f..9752ceecd78 100644
---
a/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
+++
b/examples/shardingsphere-jdbc-example/single-feature-example/encrypt-example/pom.xml
@@ -33,6 +33,7 @@
<modules>
<module>encrypt-raw-jdbc-example</module>
<module>encrypt-spring-boot-mybatis-example</module>
+ <module>encrypt-spring-boot-jpa-example</module>
<module>encrypt-spring-namespace-mybatis-example</module>
<module>encrypt-spring-namespace-jpa-example</module>
</modules>