diff --git a/.gitignore b/.gitignore index 9243c63..ad808e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,27 @@ -.gradle -/build/ -!gradle/wrapper/gradle-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr -/out/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ \ No newline at end of file +.gradle +/build/ +!gradle/wrapper/gradle-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/target/ diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..cf8a6b1 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/default/ diff --git a/bin/main/.gitignore b/bin/main/.gitignore new file mode 100644 index 0000000..4c740c4 --- /dev/null +++ b/bin/main/.gitignore @@ -0,0 +1,6 @@ +/application.properties +/cassandra.properties +/couchdb.xml +/ehcache.xml +/log4j2.xml +/xy/ diff --git a/bin/main/application.properties b/bin/main/application.properties index 79c7f91..9f67005 100644 --- a/bin/main/application.properties +++ b/bin/main/application.properties @@ -1,101 +1,101 @@ -server.port=9092 -debug=true -spring.devtools.restart.exclude=static/** - -#spring.datasource.url=jdbc:mysql://localhost:3306/boot?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true -#spring.datasource.username=root -#spring.datasource.password=mysql -#spring.datasource.driver-class-name=com.mysql.jdbc.Driver - -# MONGODB -spring.data.mongodb.host=127.0.0.1 -spring.data.mongodb.port=27017 -spring.data.mongodb.database=test - -#Cassandra -#spring.data.cassandra.keyspace-name=mydb -#spring.data.cassandra.contact-points=localhost -#spring.data.cassandra.port=9042 - -#Solr -spring.data.solr.host=http://localhost:8983/solr - -#Couchbase -#spring.couchbase.bootstrap-hosts=127.0.0.1 -#spring.couchbase.bucket.name=mydb -#spring.couchbase.bucket.password=123456 -#spring.data.couchbase.auto-index=true - -# Redis -# Redis\u6570\u636e\u5e93\u7d22\u5f15\uff08\u9ed8\u8ba4\u4e3a0\uff09 -spring.redis.database=0 -spring.redis.host=127.0.0.1 -spring.redis.port=6379 -#spring.redis.password=123 -# \u8fde\u63a5\u6c60\u6700\u5927\u8fde\u63a5\u6570\uff08\u4f7f\u7528\u8d1f\u503c\u8868\u793a\u6ca1\u6709\u9650\u5236\uff09 -spring.redis.pool.max-active=60 -# \u8fde\u63a5\u6c60\u4e2d\u7684\u6700\u5927\u7a7a\u95f2\u8fde\u63a5 -spring.redis.pool.max-idle=30 -# \u8fde\u63a5\u6c60\u6700\u5927\u963b\u585e\u7b49\u5f85\u65f6\u95f4\uff08\u4f7f\u7528\u8d1f\u503c\u8868\u793a\u6ca1\u6709\u9650\u5236\uff09 -spring.redis.pool.max-wait=-1 -# \u8fde\u63a5\u6c60\u4e2d\u7684\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5 -spring.redis.pool.min-idle=0 - -#redisson\u914d\u7f6e -#redis\u94fe\u63a5\u5730\u5740 -spring.redisson.address=redis://127.0.0.1:6379 -#\u5f53\u524d\u5904\u7406\u6838\u6570\u91cf * 2 -spring.redisson.thread=4 -#\u6307\u5b9a\u7f16\u89e3\u7801 -spring.redisson.codec=org.redisson.codec.JsonJacksonCodec -#\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\u6570,\u9ed8\u8ba4\u503c:10,\u6700\u5c0f\u4fdd\u6301\u8fde\u63a5\u6570\uff08\u957f\u8fde\u63a5\uff09 -spring.redisson.connectionMinimumIdleSize=12 -#\u8fde\u63a5\u7a7a\u95f2\u8d85\u65f6\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2 \u9ed8\u8ba410000;\u5f53\u524d\u8fde\u63a5\u6c60\u91cc\u7684\u8fde\u63a5\u6570\u91cf\u8d85\u8fc7\u4e86\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\u6570\uff0c -#\u800c\u8fde\u63a5\u7a7a\u95f2\u65f6\u95f4\u8d85\u8fc7\u4e86\u8be5\u6570\u503c\uff0c\u8fd9\u4e9b\u8fde\u63a5\u5c06\u4f1a\u81ea\u52a8\u88ab\u5173\u95ed\uff0c\u5e76\u4ece\u8fde\u63a5\u6c60\u91cc\u53bb\u6389 -spring.redisson.idleConnectionTimeout=10000 -#ping\u8282\u70b9\u8d85\u65f6,\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba41000 -spring.redisson.pingTimeout=1000 -#\u8fde\u63a5\u7b49\u5f85\u8d85\u65f6,\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba410000 -spring.redisson.connectTimeout=10000 -#\u547d\u4ee4\u7b49\u5f85\u8d85\u65f6,\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba43000\uff1b\u7b49\u5f85\u8282\u70b9\u56de\u590d\u547d\u4ee4\u7684\u65f6\u95f4\u3002\u8be5\u65f6\u95f4\u4ece\u547d\u4ee4\u53d1\u9001\u6210\u529f\u65f6\u5f00\u59cb\u8ba1\u65f6 -spring.redisson.timeout=3000 -#\u547d\u4ee4\u5931\u8d25\u91cd\u8bd5\u6b21\u6570\uff0c\u9ed8\u8ba4\u503c:3 -spring.redisson.retryAttempts=2 -#\u547d\u4ee4\u91cd\u8bd5\u53d1\u9001\u65f6\u95f4\u95f4\u9694\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba4\u503c:1500 -spring.redisson.retryInterval=1500 -#\u91cd\u65b0\u8fde\u63a5\u65f6\u95f4\u95f4\u9694\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba4\u503c\uff1a3000;\u8fde\u63a5\u65ad\u5f00\u65f6\uff0c\u7b49\u5f85\u4e0e\u5176\u91cd\u65b0\u5efa\u7acb\u8fde\u63a5\u7684\u65f6\u95f4\u95f4\u9694 -spring.redisson.reconnectionTimeout=3000 -#\u6267\u884c\u5931\u8d25\u6700\u5927\u6b21\u6570, \u9ed8\u8ba4\u503c\uff1a3\uff1b\u5931\u8d25\u540e\u76f4\u5230 reconnectionTimeout\u8d85\u65f6\u4ee5\u540e\u518d\u6b21\u5c1d\u8bd5\u3002 -spring.redisson.failedAttempts=2 -#\u8eab\u4efd\u9a8c\u8bc1\u5bc6\u7801 -#spring.redisson.password= -#\u5355\u4e2a\u8fde\u63a5\u6700\u5927\u8ba2\u9605\u6570\u91cf\uff0c\u9ed8\u8ba4\u503c\uff1a5 -spring.redisson.subscriptionsPerConnection=5 -#\u5ba2\u6237\u7aef\u540d\u79f0 -#spring.redisson.clientName= -#\u53d1\u5e03\u548c\u8ba2\u9605\u8fde\u63a5\u7684\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\u6570\uff0c\u9ed8\u8ba4\u503c\uff1a1\uff1bRedisson\u5185\u90e8\u7ecf\u5e38\u901a\u8fc7\u53d1\u5e03\u548c\u8ba2\u9605\u6765\u5b9e\u73b0\u8bb8\u591a\u529f\u80fd\u3002 -#\u957f\u671f\u4fdd\u6301\u4e00\u5b9a\u6570\u91cf\u7684\u53d1\u5e03\u8ba2\u9605\u8fde\u63a5\u662f\u5fc5\u987b\u7684 -spring.redisson.subscriptionConnectionMinimumIdleSize=1 -#\u53d1\u5e03\u548c\u8ba2\u9605\u8fde\u63a5\u6c60\u5927\u5c0f\uff0c\u9ed8\u8ba4\u503c\uff1a50 -spring.redisson.subscriptionConnectionPoolSize=50 -#\u8fde\u63a5\u6c60\u6700\u5927\u5bb9\u91cf\u3002\u9ed8\u8ba4\u503c\uff1a64\uff1b\u8fde\u63a5\u6c60\u7684\u8fde\u63a5\u6570\u91cf\u81ea\u52a8\u5f39\u6027\u4f38\u7f29 -spring.redisson.connectionPoolSize=64 -#\u6570\u636e\u5e93\u7f16\u53f7\uff0c\u9ed8\u8ba4\u503c\uff1a0 -spring.redisson.database=0 -#\u662f\u5426\u542f\u7528DNS\u76d1\u6d4b\uff0c\u9ed8\u8ba4\u503c\uff1afalse -spring.redisson.dnsMonitoring=false -#DNS\u76d1\u6d4b\u65f6\u95f4\u95f4\u9694\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2\uff0c\u9ed8\u8ba4\u503c\uff1a5000 -spring.redisson.dnsMonitoringInterval=5000 - - -# elasticsearch -#\u8282\u70b9\u540d\u5b57\uff0c\u9ed8\u8ba4elasticsearch -spring.data.elasticsearch.cluster-name=elasticsearch -# \u8282\u70b9\u5730\u5740\uff0c\u591a\u4e2a\u8282\u70b9\u7528\u9017\u53f7\u9694\u5f00 -spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300 -#spring.data.elasticsearch.local=false -spring.data.elasticsearch.repositories.enable=true - -# ehcache -spring.cache.type=ehcache +server.port=9092 +debug=true +spring.devtools.restart.exclude=static/** + +#spring.datasource.url=jdbc:mysql://localhost:3306/boot?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true +#spring.datasource.username=root +#spring.datasource.password=mysql +#spring.datasource.driver-class-name=com.mysql.jdbc.Driver + +# MONGODB +spring.data.mongodb.host=127.0.0.1 +spring.data.mongodb.port=27017 +spring.data.mongodb.database=test + +#Cassandra +#spring.data.cassandra.keyspace-name=mydb +#spring.data.cassandra.contact-points=localhost +#spring.data.cassandra.port=9042 + +#Solr +spring.data.solr.host=http://localhost:8983/solr + +#Couchbase +#spring.couchbase.bootstrap-hosts=127.0.0.1 +#spring.couchbase.bucket.name=mydb +#spring.couchbase.bucket.password=123456 +#spring.data.couchbase.auto-index=true + +# Redis +# Redis\u6570\u636e\u5e93\u7d22\u5f15\uff08\u9ed8\u8ba4\u4e3a0\uff09 +spring.redis.database=0 +spring.redis.host=127.0.0.1 +spring.redis.port=6379 +#spring.redis.password=123 +# \u8fde\u63a5\u6c60\u6700\u5927\u8fde\u63a5\u6570\uff08\u4f7f\u7528\u8d1f\u503c\u8868\u793a\u6ca1\u6709\u9650\u5236\uff09 +spring.redis.pool.max-active=60 +# \u8fde\u63a5\u6c60\u4e2d\u7684\u6700\u5927\u7a7a\u95f2\u8fde\u63a5 +spring.redis.pool.max-idle=30 +# \u8fde\u63a5\u6c60\u6700\u5927\u963b\u585e\u7b49\u5f85\u65f6\u95f4\uff08\u4f7f\u7528\u8d1f\u503c\u8868\u793a\u6ca1\u6709\u9650\u5236\uff09 +spring.redis.pool.max-wait=-1 +# \u8fde\u63a5\u6c60\u4e2d\u7684\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5 +spring.redis.pool.min-idle=0 + +#redisson\u914d\u7f6e +#redis\u94fe\u63a5\u5730\u5740 +spring.redisson.address=redis://127.0.0.1:6379 +#\u5f53\u524d\u5904\u7406\u6838\u6570\u91cf * 2 +spring.redisson.thread=4 +#\u6307\u5b9a\u7f16\u89e3\u7801 +spring.redisson.codec=org.redisson.codec.JsonJacksonCodec +#\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\u6570,\u9ed8\u8ba4\u503c:10,\u6700\u5c0f\u4fdd\u6301\u8fde\u63a5\u6570\uff08\u957f\u8fde\u63a5\uff09 +spring.redisson.connectionMinimumIdleSize=12 +#\u8fde\u63a5\u7a7a\u95f2\u8d85\u65f6\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2 \u9ed8\u8ba410000;\u5f53\u524d\u8fde\u63a5\u6c60\u91cc\u7684\u8fde\u63a5\u6570\u91cf\u8d85\u8fc7\u4e86\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\u6570\uff0c +#\u800c\u8fde\u63a5\u7a7a\u95f2\u65f6\u95f4\u8d85\u8fc7\u4e86\u8be5\u6570\u503c\uff0c\u8fd9\u4e9b\u8fde\u63a5\u5c06\u4f1a\u81ea\u52a8\u88ab\u5173\u95ed\uff0c\u5e76\u4ece\u8fde\u63a5\u6c60\u91cc\u53bb\u6389 +spring.redisson.idleConnectionTimeout=10000 +#ping\u8282\u70b9\u8d85\u65f6,\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba41000 +spring.redisson.pingTimeout=1000 +#\u8fde\u63a5\u7b49\u5f85\u8d85\u65f6,\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba410000 +spring.redisson.connectTimeout=10000 +#\u547d\u4ee4\u7b49\u5f85\u8d85\u65f6,\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba43000\uff1b\u7b49\u5f85\u8282\u70b9\u56de\u590d\u547d\u4ee4\u7684\u65f6\u95f4\u3002\u8be5\u65f6\u95f4\u4ece\u547d\u4ee4\u53d1\u9001\u6210\u529f\u65f6\u5f00\u59cb\u8ba1\u65f6 +spring.redisson.timeout=3000 +#\u547d\u4ee4\u5931\u8d25\u91cd\u8bd5\u6b21\u6570\uff0c\u9ed8\u8ba4\u503c:3 +spring.redisson.retryAttempts=2 +#\u547d\u4ee4\u91cd\u8bd5\u53d1\u9001\u65f6\u95f4\u95f4\u9694\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba4\u503c:1500 +spring.redisson.retryInterval=1500 +#\u91cd\u65b0\u8fde\u63a5\u65f6\u95f4\u95f4\u9694\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2,\u9ed8\u8ba4\u503c\uff1a3000;\u8fde\u63a5\u65ad\u5f00\u65f6\uff0c\u7b49\u5f85\u4e0e\u5176\u91cd\u65b0\u5efa\u7acb\u8fde\u63a5\u7684\u65f6\u95f4\u95f4\u9694 +spring.redisson.reconnectionTimeout=3000 +#\u6267\u884c\u5931\u8d25\u6700\u5927\u6b21\u6570, \u9ed8\u8ba4\u503c\uff1a3\uff1b\u5931\u8d25\u540e\u76f4\u5230 reconnectionTimeout\u8d85\u65f6\u4ee5\u540e\u518d\u6b21\u5c1d\u8bd5\u3002 +spring.redisson.failedAttempts=2 +#\u8eab\u4efd\u9a8c\u8bc1\u5bc6\u7801 +#spring.redisson.password= +#\u5355\u4e2a\u8fde\u63a5\u6700\u5927\u8ba2\u9605\u6570\u91cf\uff0c\u9ed8\u8ba4\u503c\uff1a5 +spring.redisson.subscriptionsPerConnection=5 +#\u5ba2\u6237\u7aef\u540d\u79f0 +#spring.redisson.clientName= +#\u53d1\u5e03\u548c\u8ba2\u9605\u8fde\u63a5\u7684\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\u6570\uff0c\u9ed8\u8ba4\u503c\uff1a1\uff1bRedisson\u5185\u90e8\u7ecf\u5e38\u901a\u8fc7\u53d1\u5e03\u548c\u8ba2\u9605\u6765\u5b9e\u73b0\u8bb8\u591a\u529f\u80fd\u3002 +#\u957f\u671f\u4fdd\u6301\u4e00\u5b9a\u6570\u91cf\u7684\u53d1\u5e03\u8ba2\u9605\u8fde\u63a5\u662f\u5fc5\u987b\u7684 +spring.redisson.subscriptionConnectionMinimumIdleSize=1 +#\u53d1\u5e03\u548c\u8ba2\u9605\u8fde\u63a5\u6c60\u5927\u5c0f\uff0c\u9ed8\u8ba4\u503c\uff1a50 +spring.redisson.subscriptionConnectionPoolSize=50 +#\u8fde\u63a5\u6c60\u6700\u5927\u5bb9\u91cf\u3002\u9ed8\u8ba4\u503c\uff1a64\uff1b\u8fde\u63a5\u6c60\u7684\u8fde\u63a5\u6570\u91cf\u81ea\u52a8\u5f39\u6027\u4f38\u7f29 +spring.redisson.connectionPoolSize=64 +#\u6570\u636e\u5e93\u7f16\u53f7\uff0c\u9ed8\u8ba4\u503c\uff1a0 +spring.redisson.database=0 +#\u662f\u5426\u542f\u7528DNS\u76d1\u6d4b\uff0c\u9ed8\u8ba4\u503c\uff1afalse +spring.redisson.dnsMonitoring=false +#DNS\u76d1\u6d4b\u65f6\u95f4\u95f4\u9694\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2\uff0c\u9ed8\u8ba4\u503c\uff1a5000 +spring.redisson.dnsMonitoringInterval=5000 + + +# elasticsearch +#\u8282\u70b9\u540d\u5b57\uff0c\u9ed8\u8ba4elasticsearch +spring.data.elasticsearch.cluster-name=elasticsearch +# \u8282\u70b9\u5730\u5740\uff0c\u591a\u4e2a\u8282\u70b9\u7528\u9017\u53f7\u9694\u5f00 +spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300 +#spring.data.elasticsearch.local=false +spring.data.elasticsearch.repositories.enable=true + +# ehcache +spring.cache.type=ehcache spring.cache.ehcache.config=classpath:ehcache.xml \ No newline at end of file diff --git a/bin/main/cassandra.properties b/bin/main/cassandra.properties index 6b39d8e..0034e8a 100644 --- a/bin/main/cassandra.properties +++ b/bin/main/cassandra.properties @@ -1,3 +1,3 @@ -cassandra.contactpoints=127.0.0.1 -cassandra.port=9042 +cassandra.contactpoints=127.0.0.1 +cassandra.port=9042 cassandra.keyspace=mydb \ No newline at end of file diff --git a/bin/main/couchdb.xml b/bin/main/couchdb.xml index e7d752b..df39966 100644 --- a/bin/main/couchdb.xml +++ b/bin/main/couchdb.xml @@ -1,10 +1,10 @@ - - - - - + + + + + \ No newline at end of file diff --git a/bin/main/ehcache.xml b/bin/main/ehcache.xml index c645ed7..9a17794 100644 --- a/bin/main/ehcache.xml +++ b/bin/main/ehcache.xml @@ -1,55 +1,55 @@ - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/bin/main/log4j2.xml b/bin/main/log4j2.xml index 00314e0..a4ee0a0 100644 --- a/bin/main/log4j2.xml +++ b/bin/main/log4j2.xml @@ -1,61 +1,61 @@ - - - - - /tmp/logs - /tmp/logs/7z - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + /tmp/logs + /tmp/logs/7z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/main/xy/SpringBoot2NoSQL/SpringBoot2NoSqlApplication.class b/bin/main/xy/SpringBoot2NoSQL/SpringBoot2NoSqlApplication.class deleted file mode 100644 index 55a0c8b..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/SpringBoot2NoSqlApplication.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/config/CassandraConfig.class b/bin/main/xy/SpringBoot2NoSQL/config/CassandraConfig.class deleted file mode 100644 index a428516..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/config/CassandraConfig.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/config/RedissonConfig.class b/bin/main/xy/SpringBoot2NoSQL/config/RedissonConfig.class deleted file mode 100644 index caf069a..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/config/RedissonConfig.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Cassandra/CassandraController.class b/bin/main/xy/SpringBoot2NoSQL/controller/Cassandra/CassandraController.class deleted file mode 100644 index 6517bc8..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Cassandra/CassandraController.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Ehcache/EhcacheDataController.class b/bin/main/xy/SpringBoot2NoSQL/controller/Ehcache/EhcacheDataController.class deleted file mode 100644 index 9f12bb4..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Ehcache/EhcacheDataController.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESDataController.class b/bin/main/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESDataController.class deleted file mode 100644 index e17d887..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESDataController.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESSearchController.class b/bin/main/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESSearchController.class deleted file mode 100644 index 64b297e..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESSearchController.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Mongo/MongoDataController.class b/bin/main/xy/SpringBoot2NoSQL/controller/Mongo/MongoDataController.class deleted file mode 100644 index a7838b1..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Mongo/MongoDataController.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedisDataController.class b/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedisDataController.class deleted file mode 100644 index 0c79dc0..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedisDataController.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$1.class b/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$1.class deleted file mode 100644 index 48bfbb7..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$1.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$2.class b/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$2.class deleted file mode 100644 index 31b6d52..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$2.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$3.class b/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$3.class deleted file mode 100644 index a0763cf..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$3.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$4.class b/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$4.class deleted file mode 100644 index 8239148..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController$4.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController.class b/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController.class deleted file mode 100644 index 7d40a2f..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Redis/RedissonController.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/controller/Solr/SolrController.class b/bin/main/xy/SpringBoot2NoSQL/controller/Solr/SolrController.class deleted file mode 100644 index 3b52997..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/controller/Solr/SolrController.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/exception/CreateIndexFailedException.class b/bin/main/xy/SpringBoot2NoSQL/exception/CreateIndexFailedException.class deleted file mode 100644 index e7495eb..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/exception/CreateIndexFailedException.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/exception/GetMappingFailedException.class b/bin/main/xy/SpringBoot2NoSQL/exception/GetMappingFailedException.class deleted file mode 100644 index c7bcf4b..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/exception/GetMappingFailedException.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/exception/IndicesExistsFailedException.class b/bin/main/xy/SpringBoot2NoSQL/exception/IndicesExistsFailedException.class deleted file mode 100644 index e0204f4..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/exception/IndicesExistsFailedException.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/exception/PutMappingFailedException.class b/bin/main/xy/SpringBoot2NoSQL/exception/PutMappingFailedException.class deleted file mode 100644 index de6de66..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/exception/PutMappingFailedException.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/model/Cassandra/Customer.class b/bin/main/xy/SpringBoot2NoSQL/model/Cassandra/Customer.class deleted file mode 100644 index 67b56fa..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/model/Cassandra/Customer.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/model/ElasticSearch/Product.class b/bin/main/xy/SpringBoot2NoSQL/model/ElasticSearch/Product.class deleted file mode 100644 index 200ae1d..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/model/ElasticSearch/Product.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Department.class b/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Department.class deleted file mode 100644 index a19a20c..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Department.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Location.class b/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Location.class deleted file mode 100644 index bca1b0b..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Location.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Person.class b/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Person.class deleted file mode 100644 index 693cf9c..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/model/Mongo/Person.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/model/Redis/User.class b/bin/main/xy/SpringBoot2NoSQL/model/Redis/User.class deleted file mode 100644 index 2e25419..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/model/Redis/User.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/model/Solr/Customer.class b/bin/main/xy/SpringBoot2NoSQL/model/Solr/Customer.class deleted file mode 100644 index dfc695f..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/model/Solr/Customer.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/model/User.class b/bin/main/xy/SpringBoot2NoSQL/model/User.class deleted file mode 100644 index ab078e8..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/model/User.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/repository/Cassandra/CustomerRepository.class b/bin/main/xy/SpringBoot2NoSQL/repository/Cassandra/CustomerRepository.class deleted file mode 100644 index 9a2f9d2..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/repository/Cassandra/CustomerRepository.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/repository/ElasticSearch/SampleProductRepository.class b/bin/main/xy/SpringBoot2NoSQL/repository/ElasticSearch/SampleProductRepository.class deleted file mode 100644 index e7804c2..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/repository/ElasticSearch/SampleProductRepository.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/repository/Mongo/DepartmentRepository.class b/bin/main/xy/SpringBoot2NoSQL/repository/Mongo/DepartmentRepository.class deleted file mode 100644 index a712f76..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/repository/Mongo/DepartmentRepository.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/repository/Mongo/PersonRepository.class b/bin/main/xy/SpringBoot2NoSQL/repository/Mongo/PersonRepository.class deleted file mode 100644 index 3a7e037..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/repository/Mongo/PersonRepository.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/repository/Redis/ObjectRepository.class b/bin/main/xy/SpringBoot2NoSQL/repository/Redis/ObjectRepository.class deleted file mode 100644 index 8537515..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/repository/Redis/ObjectRepository.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/repository/Redis/StringStringRepository.class b/bin/main/xy/SpringBoot2NoSQL/repository/Redis/StringStringRepository.class deleted file mode 100644 index 19266cf..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/repository/Redis/StringStringRepository.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/repository/Redis/UserRepository.class b/bin/main/xy/SpringBoot2NoSQL/repository/Redis/UserRepository.class deleted file mode 100644 index f63522d..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/repository/Redis/UserRepository.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/repository/Solr/SolrCustomerRepository.class b/bin/main/xy/SpringBoot2NoSQL/repository/Solr/SolrCustomerRepository.class deleted file mode 100644 index 0b8efdb..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/repository/Solr/SolrCustomerRepository.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/service/Ehcache/UserService.class b/bin/main/xy/SpringBoot2NoSQL/service/Ehcache/UserService.class deleted file mode 100644 index dc86cdd..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/service/Ehcache/UserService.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/utils/ESSearchUtil.class b/bin/main/xy/SpringBoot2NoSQL/utils/ESSearchUtil.class deleted file mode 100644 index 687e35f..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/utils/ESSearchUtil.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/utils/IElasticSearchMapping.class b/bin/main/xy/SpringBoot2NoSQL/utils/IElasticSearchMapping.class deleted file mode 100644 index 8e31fd3..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/utils/IElasticSearchMapping.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/utils/RandomUtil.class b/bin/main/xy/SpringBoot2NoSQL/utils/RandomUtil.class deleted file mode 100644 index 526b58d..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/utils/RandomUtil.class and /dev/null differ diff --git a/bin/main/xy/SpringBoot2NoSQL/utils/RedissonUtil.class b/bin/main/xy/SpringBoot2NoSQL/utils/RedissonUtil.class deleted file mode 100644 index 1fd9a17..0000000 Binary files a/bin/main/xy/SpringBoot2NoSQL/utils/RedissonUtil.class and /dev/null differ diff --git a/bin/test/.gitignore b/bin/test/.gitignore new file mode 100644 index 0000000..a1451dd --- /dev/null +++ b/bin/test/.gitignore @@ -0,0 +1 @@ +/xy/ diff --git a/myCache.ehcache/.ehcache-diskstore.lock b/myCache.ehcache/.ehcache-diskstore.lock new file mode 100644 index 0000000..e69de29 diff --git a/myCache.ehcache/users.index b/myCache.ehcache/users.index deleted file mode 100644 index 711006c..0000000 Binary files a/myCache.ehcache/users.index and /dev/null differ diff --git a/src/main/java/xy/SpringBoot2NoSQL/SpringBoot2NoSqlApplication.java b/src/main/java/xy/spring2nosql/SpringBoot2NoSqlApplication.java similarity index 100% rename from src/main/java/xy/SpringBoot2NoSQL/SpringBoot2NoSqlApplication.java rename to src/main/java/xy/spring2nosql/SpringBoot2NoSqlApplication.java diff --git a/src/main/java/xy/SpringBoot2NoSQL/config/CassandraConfig.java b/src/main/java/xy/spring2nosql/config/CassandraConfig.java similarity index 92% rename from src/main/java/xy/SpringBoot2NoSQL/config/CassandraConfig.java rename to src/main/java/xy/spring2nosql/config/CassandraConfig.java index 78f601b..4be817f 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/config/CassandraConfig.java +++ b/src/main/java/xy/spring2nosql/config/CassandraConfig.java @@ -1,45 +1,45 @@ -package xy.SpringBoot2NoSQL.config; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.data.cassandra.config.AbstractCassandraConfiguration; -import org.springframework.data.cassandra.config.CassandraClusterFactoryBean; -import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext; -import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; -import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; - -@Configuration -@PropertySource(value = { "classpath:cassandra.properties" }) -@EnableCassandraRepositories(basePackages = "xy.SpringBoot2NoSQL.repository.Cassandra") -public class CassandraConfig extends AbstractCassandraConfiguration { - private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class); - - @Autowired - private Environment environment; - - @Override - protected String getKeyspaceName() { - return environment.getProperty("cassandra.keyspace"); - } - - @Override - @Bean - public CassandraClusterFactoryBean cluster() { - final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); - cluster.setContactPoints(environment.getProperty("cassandra.contactpoints")); - cluster.setPort(Integer.parseInt(environment.getProperty("cassandra.port"))); - LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "]."); - return cluster; - } - - @Override - @Bean - public CassandraMappingContext cassandraMapping() throws ClassNotFoundException { - return new BasicCassandraMappingContext(); - } +package xy.spring2nosql.config; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.data.cassandra.config.AbstractCassandraConfiguration; +import org.springframework.data.cassandra.config.CassandraClusterFactoryBean; +import org.springframework.data.cassandra.core.mapping.BasicCassandraMappingContext; +import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; +import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; + +@Configuration +@PropertySource(value = { "classpath:cassandra.properties" }) +@EnableCassandraRepositories(basePackages = "xy.spring2nosql.repository.Cassandra") +public class CassandraConfig extends AbstractCassandraConfiguration { + private static final Log LOGGER = LogFactory.getLog(CassandraConfig.class); + + @Autowired + private Environment environment; + + @Override + protected String getKeyspaceName() { + return environment.getProperty("cassandra.keyspace"); + } + + @Override + @Bean + public CassandraClusterFactoryBean cluster() { + final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean(); + cluster.setContactPoints(environment.getProperty("cassandra.contactpoints")); + cluster.setPort(Integer.parseInt(environment.getProperty("cassandra.port"))); + LOGGER.info("Cluster created with contact points [" + environment.getProperty("cassandra.contactpoints") + "] " + "& port [" + Integer.parseInt(environment.getProperty("cassandra.port")) + "]."); + return cluster; + } + + @Override + @Bean + public CassandraMappingContext cassandraMapping() throws ClassNotFoundException { + return new BasicCassandraMappingContext(); + } } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/config/RedissonConfig.java b/src/main/java/xy/spring2nosql/config/RedissonConfig.java similarity index 96% rename from src/main/java/xy/SpringBoot2NoSQL/config/RedissonConfig.java rename to src/main/java/xy/spring2nosql/config/RedissonConfig.java index 63ea866..77bafe2 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/config/RedissonConfig.java +++ b/src/main/java/xy/spring2nosql/config/RedissonConfig.java @@ -1,263 +1,263 @@ -package xy.SpringBoot2NoSQL.config; - -import org.redisson.Redisson; -import org.redisson.api.RedissonClient; -import org.redisson.client.codec.Codec; -import org.redisson.config.Config; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.ClassUtils; - -import io.netty.channel.nio.NioEventLoopGroup; - -/** - * redisson 客户端配置,而不是使用spring data redis - * 这里配置连接的模式是单机模式,如想配置集群模式和哨兵模式,请参考官方wiki - * https://github.com/redisson/redisson/wiki/ - */ -@ConfigurationProperties(prefix = "spring.redisson") -@Configuration -public class RedissonConfig{ - - private String address; - private int connectionMinimumIdleSize = 10; - private int idleConnectionTimeout=10000; - private int pingTimeout=1000; - private int connectTimeout=10000; - private int timeout=3000; - private int retryAttempts=3; - private int retryInterval=1500; - private int reconnectionTimeout=3000; - private int failedAttempts=3; - private String password = null; - private int subscriptionsPerConnection=5; - private String clientName=null; - private int subscriptionConnectionMinimumIdleSize = 1; - private int subscriptionConnectionPoolSize = 50; - private int connectionPoolSize = 64; - private int database = 0; - private boolean dnsMonitoring = false; - private int dnsMonitoringInterval = 5000; - - private int thread; //当前处理核数量 * 2 - - private String codec="org.redisson.codec.JsonJacksonCodec"; - - @Bean(destroyMethod = "shutdown") - @ConditionalOnProperty(name="spring.redisson.address") - RedissonClient redisson() throws Exception { - Config config = new Config(); - config.useSingleServer().setAddress(address) - .setConnectionMinimumIdleSize(connectionMinimumIdleSize) - .setConnectionPoolSize(connectionPoolSize) - .setDatabase(database) - .setDnsMonitoringInterval(dnsMonitoringInterval) - .setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize) - .setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize) - .setSubscriptionsPerConnection(subscriptionsPerConnection) - .setClientName(clientName) - .setRetryAttempts(retryAttempts) - .setRetryInterval(retryInterval) - .setTimeout(timeout) - .setConnectTimeout(connectTimeout) - .setIdleConnectionTimeout(idleConnectionTimeout) - .setPingTimeout(pingTimeout) - .setPassword(password); - Codec codec=(Codec)ClassUtils.forName(getCodec(),ClassUtils.getDefaultClassLoader()).newInstance(); - config.setCodec(codec); - config.setThreads(thread); - config.setEventLoopGroup(new NioEventLoopGroup()); - return Redisson.create(config); - } - - /** - * 哨兵模式自动装配 - * @return - */ -// @Bean -// @ConditionalOnProperty(name="redisson.master-name") -// RedissonClient redissonSentinel() { -// Config config = new Config(); -// SentinelServersConfig serverConfig = config.useSentinelServers().addSentinelAddress(redssionProperties.getSentinelAddresses()) -// .setMasterName(redssionProperties.getMasterName()) -// .setTimeout(redssionProperties.getTimeout()) -// .setMasterConnectionPoolSize(redssionProperties.getMasterConnectionPoolSize()) -// .setSlaveConnectionPoolSize(redssionProperties.getSlaveConnectionPoolSize()); -// -// if(StringUtils.isNotBlank(redssionProperties.getPassword())) { -// serverConfig.setPassword(redssionProperties.getPassword()); -// } -// return Redisson.create(config); -// } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public int getConnectionMinimumIdleSize() { - return connectionMinimumIdleSize; - } - - public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) { - this.connectionMinimumIdleSize = connectionMinimumIdleSize; - } - - public int getIdleConnectionTimeout() { - return idleConnectionTimeout; - } - - public void setIdleConnectionTimeout(int idleConnectionTimeout) { - this.idleConnectionTimeout = idleConnectionTimeout; - } - - public int getPingTimeout() { - return pingTimeout; - } - - public void setPingTimeout(int pingTimeout) { - this.pingTimeout = pingTimeout; - } - - public int getConnectTimeout() { - return connectTimeout; - } - - public void setConnectTimeout(int connectTimeout) { - this.connectTimeout = connectTimeout; - } - - public int getTimeout() { - return timeout; - } - - public void setTimeout(int timeout) { - this.timeout = timeout; - } - - public int getRetryAttempts() { - return retryAttempts; - } - - public void setRetryAttempts(int retryAttempts) { - this.retryAttempts = retryAttempts; - } - - public int getRetryInterval() { - return retryInterval; - } - - public void setRetryInterval(int retryInterval) { - this.retryInterval = retryInterval; - } - - public int getReconnectionTimeout() { - return reconnectionTimeout; - } - - public void setReconnectionTimeout(int reconnectionTimeout) { - this.reconnectionTimeout = reconnectionTimeout; - } - - public int getFailedAttempts() { - return failedAttempts; - } - - public void setFailedAttempts(int failedAttempts) { - this.failedAttempts = failedAttempts; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public int getSubscriptionsPerConnection() { - return subscriptionsPerConnection; - } - - public void setSubscriptionsPerConnection(int subscriptionsPerConnection) { - this.subscriptionsPerConnection = subscriptionsPerConnection; - } - - public String getClientName() { - return clientName; - } - - public void setClientName(String clientName) { - this.clientName = clientName; - } - - public int getSubscriptionConnectionMinimumIdleSize() { - return subscriptionConnectionMinimumIdleSize; - } - - public void setSubscriptionConnectionMinimumIdleSize(int subscriptionConnectionMinimumIdleSize) { - this.subscriptionConnectionMinimumIdleSize = subscriptionConnectionMinimumIdleSize; - } - - public int getSubscriptionConnectionPoolSize() { - return subscriptionConnectionPoolSize; - } - - public void setSubscriptionConnectionPoolSize(int subscriptionConnectionPoolSize) { - this.subscriptionConnectionPoolSize = subscriptionConnectionPoolSize; - } - - public int getConnectionPoolSize() { - return connectionPoolSize; - } - - public void setConnectionPoolSize(int connectionPoolSize) { - this.connectionPoolSize = connectionPoolSize; - } - - public int getDatabase() { - return database; - } - - public void setDatabase(int database) { - this.database = database; - } - - public boolean isDnsMonitoring() { - return dnsMonitoring; - } - - public void setDnsMonitoring(boolean dnsMonitoring) { - this.dnsMonitoring = dnsMonitoring; - } - - public int getDnsMonitoringInterval() { - return dnsMonitoringInterval; - } - - public void setDnsMonitoringInterval(int dnsMonitoringInterval) { - this.dnsMonitoringInterval = dnsMonitoringInterval; - } - - public int getThread() { - return thread; - } - - public void setThread(int thread) { - this.thread = thread; - } - - public String getCodec() { - return codec; - } - - public void setCodec(String codec) { - this.codec = codec; - } - -} +package xy.spring2nosql.config; + +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.client.codec.Codec; +import org.redisson.config.Config; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.ClassUtils; + +import io.netty.channel.nio.NioEventLoopGroup; + +/** + * redisson 客户端配置,而不是使用spring data redis + * 这里配置连接的模式是单机模式,如想配置集群模式和哨兵模式,请参考官方wiki + * https://github.com/redisson/redisson/wiki/ + */ +@ConfigurationProperties(prefix = "spring.redisson") +@Configuration +public class RedissonConfig{ + + private String address; + private int connectionMinimumIdleSize = 10; + private int idleConnectionTimeout=10000; + private int pingTimeout=1000; + private int connectTimeout=10000; + private int timeout=3000; + private int retryAttempts=3; + private int retryInterval=1500; + private int reconnectionTimeout=3000; + private int failedAttempts=3; + private String password = null; + private int subscriptionsPerConnection=5; + private String clientName=null; + private int subscriptionConnectionMinimumIdleSize = 1; + private int subscriptionConnectionPoolSize = 50; + private int connectionPoolSize = 64; + private int database = 0; + private boolean dnsMonitoring = false; + private int dnsMonitoringInterval = 5000; + + private int thread; //当前处理核数量 * 2 + + private String codec="org.redisson.codec.JsonJacksonCodec"; + + @Bean(destroyMethod = "shutdown") + @ConditionalOnProperty(name="spring.redisson.address") + RedissonClient redisson() throws Exception { + Config config = new Config(); + config.useSingleServer().setAddress(address) + .setConnectionMinimumIdleSize(connectionMinimumIdleSize) + .setConnectionPoolSize(connectionPoolSize) + .setDatabase(database) + .setDnsMonitoringInterval(dnsMonitoringInterval) + .setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize) + .setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize) + .setSubscriptionsPerConnection(subscriptionsPerConnection) + .setClientName(clientName) + .setRetryAttempts(retryAttempts) + .setRetryInterval(retryInterval) + .setTimeout(timeout) + .setConnectTimeout(connectTimeout) + .setIdleConnectionTimeout(idleConnectionTimeout) + .setPingTimeout(pingTimeout) + .setPassword(password); + Codec codec=(Codec)ClassUtils.forName(getCodec(),ClassUtils.getDefaultClassLoader()).newInstance(); + config.setCodec(codec); + config.setThreads(thread); + config.setEventLoopGroup(new NioEventLoopGroup()); + return Redisson.create(config); + } + + /** + * 哨兵模式自动装配 + * @return + */ +// @Bean +// @ConditionalOnProperty(name="redisson.master-name") +// RedissonClient redissonSentinel() { +// Config config = new Config(); +// SentinelServersConfig serverConfig = config.useSentinelServers().addSentinelAddress(redssionProperties.getSentinelAddresses()) +// .setMasterName(redssionProperties.getMasterName()) +// .setTimeout(redssionProperties.getTimeout()) +// .setMasterConnectionPoolSize(redssionProperties.getMasterConnectionPoolSize()) +// .setSlaveConnectionPoolSize(redssionProperties.getSlaveConnectionPoolSize()); +// +// if(StringUtils.isNotBlank(redssionProperties.getPassword())) { +// serverConfig.setPassword(redssionProperties.getPassword()); +// } +// return Redisson.create(config); +// } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public int getConnectionMinimumIdleSize() { + return connectionMinimumIdleSize; + } + + public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) { + this.connectionMinimumIdleSize = connectionMinimumIdleSize; + } + + public int getIdleConnectionTimeout() { + return idleConnectionTimeout; + } + + public void setIdleConnectionTimeout(int idleConnectionTimeout) { + this.idleConnectionTimeout = idleConnectionTimeout; + } + + public int getPingTimeout() { + return pingTimeout; + } + + public void setPingTimeout(int pingTimeout) { + this.pingTimeout = pingTimeout; + } + + public int getConnectTimeout() { + return connectTimeout; + } + + public void setConnectTimeout(int connectTimeout) { + this.connectTimeout = connectTimeout; + } + + public int getTimeout() { + return timeout; + } + + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + public int getRetryAttempts() { + return retryAttempts; + } + + public void setRetryAttempts(int retryAttempts) { + this.retryAttempts = retryAttempts; + } + + public int getRetryInterval() { + return retryInterval; + } + + public void setRetryInterval(int retryInterval) { + this.retryInterval = retryInterval; + } + + public int getReconnectionTimeout() { + return reconnectionTimeout; + } + + public void setReconnectionTimeout(int reconnectionTimeout) { + this.reconnectionTimeout = reconnectionTimeout; + } + + public int getFailedAttempts() { + return failedAttempts; + } + + public void setFailedAttempts(int failedAttempts) { + this.failedAttempts = failedAttempts; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public int getSubscriptionsPerConnection() { + return subscriptionsPerConnection; + } + + public void setSubscriptionsPerConnection(int subscriptionsPerConnection) { + this.subscriptionsPerConnection = subscriptionsPerConnection; + } + + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + public int getSubscriptionConnectionMinimumIdleSize() { + return subscriptionConnectionMinimumIdleSize; + } + + public void setSubscriptionConnectionMinimumIdleSize(int subscriptionConnectionMinimumIdleSize) { + this.subscriptionConnectionMinimumIdleSize = subscriptionConnectionMinimumIdleSize; + } + + public int getSubscriptionConnectionPoolSize() { + return subscriptionConnectionPoolSize; + } + + public void setSubscriptionConnectionPoolSize(int subscriptionConnectionPoolSize) { + this.subscriptionConnectionPoolSize = subscriptionConnectionPoolSize; + } + + public int getConnectionPoolSize() { + return connectionPoolSize; + } + + public void setConnectionPoolSize(int connectionPoolSize) { + this.connectionPoolSize = connectionPoolSize; + } + + public int getDatabase() { + return database; + } + + public void setDatabase(int database) { + this.database = database; + } + + public boolean isDnsMonitoring() { + return dnsMonitoring; + } + + public void setDnsMonitoring(boolean dnsMonitoring) { + this.dnsMonitoring = dnsMonitoring; + } + + public int getDnsMonitoringInterval() { + return dnsMonitoringInterval; + } + + public void setDnsMonitoringInterval(int dnsMonitoringInterval) { + this.dnsMonitoringInterval = dnsMonitoringInterval; + } + + public int getThread() { + return thread; + } + + public void setThread(int thread) { + this.thread = thread; + } + + public String getCodec() { + return codec; + } + + public void setCodec(String codec) { + this.codec = codec; + } + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/Cassandra/CassandraController.java b/src/main/java/xy/spring2nosql/controller/Cassandra/CassandraController.java similarity index 89% rename from src/main/java/xy/SpringBoot2NoSQL/controller/Cassandra/CassandraController.java rename to src/main/java/xy/spring2nosql/controller/Cassandra/CassandraController.java index 848d389..0b7c7f7 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/Cassandra/CassandraController.java +++ b/src/main/java/xy/spring2nosql/controller/Cassandra/CassandraController.java @@ -1,76 +1,76 @@ -package xy.SpringBoot2NoSQL.controller.Cassandra; - -import java.util.List; -import java.util.Optional; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import xy.SpringBoot2NoSQL.model.Cassandra.Customer; -import xy.SpringBoot2NoSQL.repository.Cassandra.CustomerRepository; - - - -@RestController -@RequestMapping("/cassandra") -public class CassandraController { - - Logger logger = LogManager.getLogger(getClass()); - - @Autowired - CustomerRepository customerRepository; - - @RequestMapping("/add") - public String add(){ - customerRepository.deleteAll(); - - Customer cust_1 = new Customer("Test1", "Test1", "Test1", 20); - Customer cust_2 = new Customer("Test2", "Test2", "Test2", 25); - Customer cust_3 = new Customer("Test3", "Test3", "Test3", 30); - Customer cust_4 = new Customer("Test4", "Test4", "Test4", 35); - Customer cust_5 = new Customer("Test5", "Test5", "Test5", 40); - Customer cust_6 = new Customer("Test6", "Test6", "Test6", 45); - - customerRepository.save(cust_1); - customerRepository.save(cust_2); - customerRepository.save(cust_3); - customerRepository.save(cust_4); - customerRepository.save(cust_5); - customerRepository.save(cust_6); - - return "ok"; - } - - - @RequestMapping("/all") - public Iterable getAll(){ - - return customerRepository.findAll(); - } - - @RequestMapping("/getByID/{id}") - public Optional getByID(@PathVariable("id") String id){ - - return customerRepository.findById(id); - } - - @RequestMapping("/getByName/{name}") - public List getByName(@PathVariable("name") String name){ - - return customerRepository.findByLastname(name); - - } - - @RequestMapping("/getByAge/{age}") - public List getByAge(@PathVariable("age") String age){ - - return customerRepository.findByAgeGreaterThan(Integer.valueOf(age)); - - } - - -} +package xy.spring2nosql.controller.Cassandra; + +import java.util.List; +import java.util.Optional; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import xy.spring2nosql.model.Cassandra.Customer; +import xy.spring2nosql.repository.Cassandra.CustomerRepository; + + + +@RestController +@RequestMapping("/cassandra") +public class CassandraController { + + Logger logger = LogManager.getLogger(getClass()); + + @Autowired + CustomerRepository customerRepository; + + @RequestMapping("/add") + public String add(){ + customerRepository.deleteAll(); + + Customer cust_1 = new Customer("Test1", "Test1", "Test1", 20); + Customer cust_2 = new Customer("Test2", "Test2", "Test2", 25); + Customer cust_3 = new Customer("Test3", "Test3", "Test3", 30); + Customer cust_4 = new Customer("Test4", "Test4", "Test4", 35); + Customer cust_5 = new Customer("Test5", "Test5", "Test5", 40); + Customer cust_6 = new Customer("Test6", "Test6", "Test6", 45); + + customerRepository.save(cust_1); + customerRepository.save(cust_2); + customerRepository.save(cust_3); + customerRepository.save(cust_4); + customerRepository.save(cust_5); + customerRepository.save(cust_6); + + return "ok"; + } + + + @RequestMapping("/all") + public Iterable getAll(){ + + return customerRepository.findAll(); + } + + @RequestMapping("/getByID/{id}") + public Optional getByID(@PathVariable("id") String id){ + + return customerRepository.findById(id); + } + + @RequestMapping("/getByName/{name}") + public List getByName(@PathVariable("name") String name){ + + return customerRepository.findByLastname(name); + + } + + @RequestMapping("/getByAge/{age}") + public List getByAge(@PathVariable("age") String age){ + + return customerRepository.findByAgeGreaterThan(Integer.valueOf(age)); + + } + + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/Couchbase/CouchbaseController.java b/src/main/java/xy/spring2nosql/controller/Couchbase/CouchbaseController.java similarity index 86% rename from src/main/java/xy/SpringBoot2NoSQL/controller/Couchbase/CouchbaseController.java rename to src/main/java/xy/spring2nosql/controller/Couchbase/CouchbaseController.java index 676c2b9..e484e4d 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/Couchbase/CouchbaseController.java +++ b/src/main/java/xy/spring2nosql/controller/Couchbase/CouchbaseController.java @@ -1,53 +1,53 @@ -//package xy.SpringBoot2NoSQL.controller.Couchbase; -// -//import java.util.Arrays; -//import java.util.List; -//import java.util.Optional; -// -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.web.bind.annotation.PathVariable; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RestController; -// -//import xy.SpringBoot2NoSQL.model.Couchbase.Customer; -//import xy.SpringBoot2NoSQL.repository.Couchbase.CouchbaseCustomerRepository; -// -//@RestController -//@RequestMapping("/couchbase") -//public class CouchbaseController { -// -// @Autowired -// CouchbaseCustomerRepository couchbaseCustomerRepository; -// -// @RequestMapping("/add") -// public String add(){ -// -// couchbaseCustomerRepository.deleteAll(); -// couchbaseCustomerRepository.saveAll(Arrays.asList(new Customer("01", "Jack", "Smith"), -// new Customer("02", "Adam", "Johnson"), -// new Customer("03", "Kim", "Smith"), -// new Customer("04", "David", "Williams"), -// new Customer("05", "Peter", "Davis"))); -// -// return "ok"; -// } -// -// @RequestMapping("/all") -// public Iterable getAll(){ -// -// return couchbaseCustomerRepository.findAll(); -// } -// -// @RequestMapping("/getByID/{id}") -// public Optional getByID(@PathVariable("id") String id){ -// -// return couchbaseCustomerRepository.findById(id); -// } -// -// @RequestMapping("/findByLastName/{name}") -// public List findByLastName(@PathVariable("name") String name){ -// -// return couchbaseCustomerRepository.findByLastName(name); -// } -// -//} +//package xy.spring2nosql.controller.Couchbase; +// +//import java.util.Arrays; +//import java.util.List; +//import java.util.Optional; +// +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.web.bind.annotation.PathVariable; +//import org.springframework.web.bind.annotation.RequestMapping; +//import org.springframework.web.bind.annotation.RestController; +// +//import xy.spring2nosql.model.Couchbase.Customer; +//import xy.spring2nosql.repository.Couchbase.CouchbaseCustomerRepository; +// +//@RestController +//@RequestMapping("/couchbase") +//public class CouchbaseController { +// +// @Autowired +// CouchbaseCustomerRepository couchbaseCustomerRepository; +// +// @RequestMapping("/add") +// public String add(){ +// +// couchbaseCustomerRepository.deleteAll(); +// couchbaseCustomerRepository.saveAll(Arrays.asList(new Customer("01", "Jack", "Smith"), +// new Customer("02", "Adam", "Johnson"), +// new Customer("03", "Kim", "Smith"), +// new Customer("04", "David", "Williams"), +// new Customer("05", "Peter", "Davis"))); +// +// return "ok"; +// } +// +// @RequestMapping("/all") +// public Iterable getAll(){ +// +// return couchbaseCustomerRepository.findAll(); +// } +// +// @RequestMapping("/getByID/{id}") +// public Optional getByID(@PathVariable("id") String id){ +// +// return couchbaseCustomerRepository.findById(id); +// } +// +// @RequestMapping("/findByLastName/{name}") +// public List findByLastName(@PathVariable("name") String name){ +// +// return couchbaseCustomerRepository.findByLastName(name); +// } +// +//} diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/Ehcache/EhcacheDataController.java b/src/main/java/xy/spring2nosql/controller/Ehcache/EhcacheDataController.java similarity index 88% rename from src/main/java/xy/SpringBoot2NoSQL/controller/Ehcache/EhcacheDataController.java rename to src/main/java/xy/spring2nosql/controller/Ehcache/EhcacheDataController.java index 43544bb..32acb79 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/Ehcache/EhcacheDataController.java +++ b/src/main/java/xy/spring2nosql/controller/Ehcache/EhcacheDataController.java @@ -1,64 +1,64 @@ -package xy.SpringBoot2NoSQL.controller.Ehcache; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import net.sf.ehcache.CacheManager; -import xy.SpringBoot2NoSQL.model.User; -import xy.SpringBoot2NoSQL.service.Ehcache.UserService; - -@RestController -@RequestMapping("/ehcache") -public class EhcacheDataController { - - Logger logger = LogManager.getLogger(getClass()); - - @Autowired - UserService userService; - - @Autowired - private CacheManager cacheManager; - - /** - * 创建100个测试用户 - * @return - */ - @RequestMapping("/users") - public List getUsers(){ - - logger.info("using cache manager: " + cacheManager.getClass().getName()); - - userService.clearCache(); - - //新建对象 - List users = new ArrayList(); - for (int i=0;i<100;i++){ - users.add(userService.getUser("test"+i)); - } - - for (int i=0;i<100;i++){ - //测试获取对象是否是经过缓存 - userService.getUser("test"+i); - } - - return users; - } - - /** - * 获取测试用户,看看是否经过缓存 - * @return - */ - @RequestMapping("/user/{name}") - public User getUser(@PathVariable("name") String name){ - return userService.getUser(name); - - } - -} +package xy.spring2nosql.controller.Ehcache; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import net.sf.ehcache.CacheManager; +import xy.spring2nosql.model.User; +import xy.spring2nosql.service.Ehcache.UserService; + +@RestController +@RequestMapping("/ehcache") +public class EhcacheDataController { + + Logger logger = LogManager.getLogger(getClass()); + + @Autowired + UserService userService; + + @Autowired + private CacheManager cacheManager; + + /** + * 创建100个测试用户 + * @return + */ + @RequestMapping("/users") + public List getUsers(){ + + logger.info("using cache manager: " + cacheManager.getClass().getName()); + + userService.clearCache(); + + //新建对象 + List users = new ArrayList(); + for (int i=0;i<100;i++){ + users.add(userService.getUser("test"+i)); + } + + for (int i=0;i<100;i++){ + //测试获取对象是否是经过缓存 + userService.getUser("test"+i); + } + + return users; + } + + /** + * 获取测试用户,看看是否经过缓存 + * @return + */ + @RequestMapping("/user/{name}") + public User getUser(@PathVariable("name") String name){ + return userService.getUser(name); + + } + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESDataController.java b/src/main/java/xy/spring2nosql/controller/ElasticSearch/ESDataController.java similarity index 94% rename from src/main/java/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESDataController.java rename to src/main/java/xy/spring2nosql/controller/ElasticSearch/ESDataController.java index 5a71565..9c468c2 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESDataController.java +++ b/src/main/java/xy/spring2nosql/controller/ElasticSearch/ESDataController.java @@ -1,186 +1,186 @@ -package xy.SpringBoot2NoSQL.controller.ElasticSearch; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.elasticsearch.action.ActionFuture; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.client.Client; -import org.elasticsearch.cluster.health.ClusterHealthStatus; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.elasticsearch.core.ElasticsearchOperations; -import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; -import org.springframework.data.elasticsearch.core.query.DeleteQuery; -import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; -import org.springframework.data.elasticsearch.core.query.SearchQuery; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import xy.SpringBoot2NoSQL.model.ElasticSearch.Product; -import xy.SpringBoot2NoSQL.repository.ElasticSearch.SampleProductRepository; - -@RestController -@RequestMapping("/es") -public class ESDataController { - - @Autowired - private ElasticsearchOperations elasticsearchOperations; - - @Autowired - SampleProductRepository sampleProductRepository; - - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; - - //服务情况查询 - @GetMapping("details") - public ResponseEntity> getElasticInformation() { - - Client client = elasticsearchOperations.getClient(); - Map asMap = client.settings().getAsMap(); - return ResponseEntity.ok(asMap); - } - - //健康检查 - @GetMapping("checkHealth") - public String checkHealth() { - - return getHealth(); - } - - @GetMapping("insertProduct") - public Product insert() { - Product product = new Product("1", "测试产品1", "测试产品111111.", true); - return sampleProductRepository.save(product); - } - - @GetMapping("insertProductMore") - public String insertProductMore() { - - List productList = new ArrayList(); - - for (int i = 0; i < 100; i++) { - Product product = new Product(String.valueOf(i), "测试产品" + i, "测试产品描述.", true); - productList.add(product); - } - - // 只需要执行一次批量 - sampleProductRepository.saveAll(productList); - - return "success"; - } - - @GetMapping("insertProduct2/{id}/{name}") - public Product insert2(@PathVariable String name, @PathVariable String id) { - Product product = new Product(id, name, name + "产品描述.", true); - return sampleProductRepository.save(product); - } - - @GetMapping("findByNameProducts/{name}") - public List findByNameProducts(@PathVariable String name) { - List list = sampleProductRepository.findByName(name); - return list; - } - - @GetMapping("findByNameAndIdProducts/{name}/{id}") - public List findByNameAndIdProducts(@PathVariable String name, @PathVariable String id) { - List list = sampleProductRepository.findByNameAndId(name, id); - return list; - } - - @GetMapping("findByNameProductsPage/{name}/{page}/{size}") - public List findByNameProductsPage(@PathVariable String name, @PathVariable int page, - @PathVariable int size) { - List list = sampleProductRepository.findByName(name, PageRequest.of(page, size)); - return list; - } - - @GetMapping("count") - public long CountAllElementsInIndex() { - - long count = sampleProductRepository.count(); - return count; - } - - @GetMapping("searchQueries/{id}/{name}/{page}/{size}") - public Page SearchQueries(@PathVariable String name, @PathVariable String id, @PathVariable int page, - @PathVariable int size) { - - BoolQueryBuilder bqb = QueryBuilders.boolQuery(); - bqb.must(QueryBuilders.termQuery("name", name)); - //bqb.must(QueryBuilders.rangeQuery("id").gt(id));// 大于 - - SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(bqb).withPageable(PageRequest.of(page, size)) - .build(); - - Page products = sampleProductRepository.search(searchQuery); - return products; - } - - //根据id删除 - public boolean deleteById(String id) { - try { - elasticsearchTemplate.delete(getEntityClass(), id); - return true; - } catch (Exception e) { - return false; - } - } - - //根据条件删除 - public boolean deleteByQuery(Map filedContentMap) { - try { - DeleteQuery dq = new DeleteQuery(); - - BoolQueryBuilder query=QueryBuilders. boolQuery(); - if(filedContentMap!=null) - for (String key : filedContentMap.keySet()) {//字段查询 - query.must(QueryBuilders.matchQuery(key,filedContentMap.get(key))); - } - dq.setQuery(query); - elasticsearchTemplate.delete(dq, getEntityClass()); - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } - - - - //健康检查 - public String getHealth() { - try { - Client client = elasticsearchOperations.getClient(); - ActionFuture health = client.admin() - .cluster().health(new ClusterHealthRequest()); - ClusterHealthStatus status = health.actionGet().getStatus(); - if (status.value() == ClusterHealthStatus.RED.value()) { - return "red"; - } - if (status.value() == ClusterHealthStatus.GREEN.value()) { - return "green"; - } - if (status.value() == ClusterHealthStatus.YELLOW.value()) { - return "yellow"; - } - return "unknow"; - } catch (Exception e) { - - return "unknow"; - } - } - - private Class getEntityClass() { - - return Product.class; - } -} +package xy.spring2nosql.controller.ElasticSearch; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.elasticsearch.action.ActionFuture; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.elasticsearch.core.ElasticsearchOperations; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.core.query.DeleteQuery; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; +import org.springframework.data.elasticsearch.core.query.SearchQuery; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import xy.spring2nosql.model.ElasticSearch.Product; +import xy.spring2nosql.repository.ElasticSearch.SampleProductRepository; + +@RestController +@RequestMapping("/es") +public class ESDataController { + + @Autowired + private ElasticsearchOperations elasticsearchOperations; + + @Autowired + SampleProductRepository sampleProductRepository; + + @Autowired + private ElasticsearchTemplate elasticsearchTemplate; + + //服务情况查询 + @GetMapping("details") + public ResponseEntity> getElasticInformation() { + + Client client = elasticsearchOperations.getClient(); + Map asMap = client.settings().getAsMap(); + return ResponseEntity.ok(asMap); + } + + //健康检查 + @GetMapping("checkHealth") + public String checkHealth() { + + return getHealth(); + } + + @GetMapping("insertProduct") + public Product insert() { + Product product = new Product("1", "测试产品1", "测试产品111111.", true); + return sampleProductRepository.save(product); + } + + @GetMapping("insertProductMore") + public String insertProductMore() { + + List productList = new ArrayList(); + + for (int i = 0; i < 100; i++) { + Product product = new Product(String.valueOf(i), "测试产品" + i, "测试产品描述.", true); + productList.add(product); + } + + // 只需要执行一次批量 + sampleProductRepository.saveAll(productList); + + return "success"; + } + + @GetMapping("insertProduct2/{id}/{name}") + public Product insert2(@PathVariable String name, @PathVariable String id) { + Product product = new Product(id, name, name + "产品描述.", true); + return sampleProductRepository.save(product); + } + + @GetMapping("findByNameProducts/{name}") + public List findByNameProducts(@PathVariable String name) { + List list = sampleProductRepository.findByName(name); + return list; + } + + @GetMapping("findByNameAndIdProducts/{name}/{id}") + public List findByNameAndIdProducts(@PathVariable String name, @PathVariable String id) { + List list = sampleProductRepository.findByNameAndId(name, id); + return list; + } + + @GetMapping("findByNameProductsPage/{name}/{page}/{size}") + public List findByNameProductsPage(@PathVariable String name, @PathVariable int page, + @PathVariable int size) { + List list = sampleProductRepository.findByName(name, PageRequest.of(page, size)); + return list; + } + + @GetMapping("count") + public long CountAllElementsInIndex() { + + long count = sampleProductRepository.count(); + return count; + } + + @GetMapping("searchQueries/{id}/{name}/{page}/{size}") + public Page SearchQueries(@PathVariable String name, @PathVariable String id, @PathVariable int page, + @PathVariable int size) { + + BoolQueryBuilder bqb = QueryBuilders.boolQuery(); + bqb.must(QueryBuilders.termQuery("name", name)); + //bqb.must(QueryBuilders.rangeQuery("id").gt(id));// 大于 + + SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(bqb).withPageable(PageRequest.of(page, size)) + .build(); + + Page products = sampleProductRepository.search(searchQuery); + return products; + } + + //根据id删除 + public boolean deleteById(String id) { + try { + elasticsearchTemplate.delete(getEntityClass(), id); + return true; + } catch (Exception e) { + return false; + } + } + + //根据条件删除 + public boolean deleteByQuery(Map filedContentMap) { + try { + DeleteQuery dq = new DeleteQuery(); + + BoolQueryBuilder query=QueryBuilders. boolQuery(); + if(filedContentMap!=null) + for (String key : filedContentMap.keySet()) {//字段查询 + query.must(QueryBuilders.matchQuery(key,filedContentMap.get(key))); + } + dq.setQuery(query); + elasticsearchTemplate.delete(dq, getEntityClass()); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + + + //健康检查 + public String getHealth() { + try { + Client client = elasticsearchOperations.getClient(); + ActionFuture health = client.admin() + .cluster().health(new ClusterHealthRequest()); + ClusterHealthStatus status = health.actionGet().getStatus(); + if (status.value() == ClusterHealthStatus.RED.value()) { + return "red"; + } + if (status.value() == ClusterHealthStatus.GREEN.value()) { + return "green"; + } + if (status.value() == ClusterHealthStatus.YELLOW.value()) { + return "yellow"; + } + return "unknow"; + } catch (Exception e) { + + return "unknow"; + } + } + + private Class getEntityClass() { + + return Product.class; + } +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESSearchController.java b/src/main/java/xy/spring2nosql/controller/ElasticSearch/ESSearchController.java similarity index 88% rename from src/main/java/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESSearchController.java rename to src/main/java/xy/spring2nosql/controller/ElasticSearch/ESSearchController.java index 2e6eaeb..a761ad6 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/ElasticSearch/ESSearchController.java +++ b/src/main/java/xy/spring2nosql/controller/ElasticSearch/ESSearchController.java @@ -1,67 +1,67 @@ -package xy.SpringBoot2NoSQL.controller.ElasticSearch; - -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import xy.SpringBoot2NoSQL.model.ElasticSearch.Product; -import xy.SpringBoot2NoSQL.repository.ElasticSearch.SampleProductRepository; -import xy.SpringBoot2NoSQL.utils.ESSearchUtil; - -@RestController -@RequestMapping("/essearch") -public class ESSearchController { - - @Autowired - SampleProductRepository sampleProductRepository; - - @GetMapping("search") - public Page search() { - - return sampleProductRepository.search(getBoolQuery(), PageRequest.of(0, 5)); - } - - @GetMapping("searchAll/{page}") - public Page searchAll(@PathVariable int page) { - - return sampleProductRepository.search(ESSearchUtil.matchAllQuery(), PageRequest.of(page, 5)); - } - - @GetMapping("searchProduct/{key}/{value}/{searchtype}") - public Page searchProduct(@PathVariable String key,@PathVariable String value, @PathVariable String searchtype) { - Page products = null; - - if (searchtype.equals("matchQuery")) { - products = sampleProductRepository.search(ESSearchUtil.matchQuery(key, value), PageRequest.of(0, 5)); - } - - if (searchtype.equals("matchPhraseQuery")) { - products = sampleProductRepository.search(ESSearchUtil.matchPhraseQuery(key, value), PageRequest.of(0, 5)); - } - - if (searchtype.equals("fuzzyQuery")) { - products = sampleProductRepository.search(ESSearchUtil.fuzzyQuery(key, value), PageRequest.of(0, 5)); - } - - if (searchtype.equals("termsQuery")) { - products = sampleProductRepository.search(ESSearchUtil.termsQuery(key, value), PageRequest.of(0, 5)); - } - - return products; - } - - public QueryBuilder getBoolQuery() { - - return QueryBuilders.boolQuery() - .must(QueryBuilders.matchPhraseQuery("name", "测试产品1")) - //.mustNot(QueryBuilders.termQuery("enabled", true)); - .must(QueryBuilders.matchPhraseQuery("enabled", true)); - } - -} +package xy.spring2nosql.controller.ElasticSearch; + +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import xy.spring2nosql.model.ElasticSearch.Product; +import xy.spring2nosql.repository.ElasticSearch.SampleProductRepository; +import xy.spring2nosql.utils.ESSearchUtil; + +@RestController +@RequestMapping("/essearch") +public class ESSearchController { + + @Autowired + SampleProductRepository sampleProductRepository; + + @GetMapping("search") + public Page search() { + + return sampleProductRepository.search(getBoolQuery(), PageRequest.of(0, 5)); + } + + @GetMapping("searchAll/{page}") + public Page searchAll(@PathVariable int page) { + + return sampleProductRepository.search(ESSearchUtil.matchAllQuery(), PageRequest.of(page, 5)); + } + + @GetMapping("searchProduct/{key}/{value}/{searchtype}") + public Page searchProduct(@PathVariable String key,@PathVariable String value, @PathVariable String searchtype) { + Page products = null; + + if (searchtype.equals("matchQuery")) { + products = sampleProductRepository.search(ESSearchUtil.matchQuery(key, value), PageRequest.of(0, 5)); + } + + if (searchtype.equals("matchPhraseQuery")) { + products = sampleProductRepository.search(ESSearchUtil.matchPhraseQuery(key, value), PageRequest.of(0, 5)); + } + + if (searchtype.equals("fuzzyQuery")) { + products = sampleProductRepository.search(ESSearchUtil.fuzzyQuery(key, value), PageRequest.of(0, 5)); + } + + if (searchtype.equals("termsQuery")) { + products = sampleProductRepository.search(ESSearchUtil.termsQuery(key, value), PageRequest.of(0, 5)); + } + + return products; + } + + public QueryBuilder getBoolQuery() { + + return QueryBuilders.boolQuery() + .must(QueryBuilders.matchPhraseQuery("name", "测试产品1")) + //.mustNot(QueryBuilders.termQuery("enabled", true)); + .must(QueryBuilders.matchPhraseQuery("enabled", true)); + } + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/Mongo/MongoDataController.java b/src/main/java/xy/spring2nosql/controller/Mongo/MongoDataController.java similarity index 89% rename from src/main/java/xy/SpringBoot2NoSQL/controller/Mongo/MongoDataController.java rename to src/main/java/xy/spring2nosql/controller/Mongo/MongoDataController.java index e9e9c4e..6bf22a5 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/Mongo/MongoDataController.java +++ b/src/main/java/xy/spring2nosql/controller/Mongo/MongoDataController.java @@ -1,110 +1,110 @@ -package xy.SpringBoot2NoSQL.controller.Mongo; - - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import xy.SpringBoot2NoSQL.model.Mongo.Department; -import xy.SpringBoot2NoSQL.model.Mongo.Location; -import xy.SpringBoot2NoSQL.model.Mongo.Person; -import xy.SpringBoot2NoSQL.repository.Mongo.DepartmentRepository; -import xy.SpringBoot2NoSQL.repository.Mongo.PersonRepository; - -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Optional; - -@RestController -@RequestMapping("/mongo") -public class MongoDataController { - - @Autowired - PersonRepository personRepository; - @Autowired - DepartmentRepository departmentRepository; - - @RequestMapping("/persons/{name}") - public Person getPerson(@PathVariable("name") String name){ - return personRepository.findByName(name); - } - - @GetMapping("findAll") - public List getUserList() { - List userInfoList = personRepository.findAll(); - return userInfoList; - } - - @GetMapping("query1") - public Person q1(String name){ - return personRepository.findByName(name); - } - - @GetMapping("query2") - public List q2(Integer age){ - return personRepository.withQueryFindByAge(age); - } - - @GetMapping("delete") - public String delete(String id) { - personRepository.deleteById(id); - return "success"; - } - - @DeleteMapping("/colleagues/{name}") - public ResponseEntity deleteColleague(@PathVariable String name){ - Person person = personRepository.findByName(name); - if(person!=null) { - personRepository.delete(person); - return new ResponseEntity<>(HttpStatus.ACCEPTED); - } - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); - } - - @GetMapping("insert") - public Person insert(Long id, String username, String password) { - Person user = new Person("test2",22); - return personRepository.insert(user); - } - - //要先执行添加部门的操作 - @RequestMapping("saveDepartment") - public Department saveDepartment(){ - Department d = new Department("abc001","研发部"); - return departmentRepository.save(d); - } - - //执行这个之前要先执行”saveDepartment“,因为需要一个部门的引用 - @RequestMapping("save") - public Person save(){ - Person p = new Person("王昕",32); - Collection locations = new LinkedHashSet(); - Location loc1 = new Location("上海","2009"); - Location loc2 = new Location("广州","2011"); - locations.add(loc1); - locations.add(loc2); - - p.setLocations(locations); - - Department d = departmentRepository.findByName("研发部"); - p.setDepartment(d); - - return personRepository.save(p); - } - - - @PostMapping("/formsave") - public ResponseEntity addColleague(@RequestBody Person person){ - personRepository.save(person); - return new ResponseEntity<>(HttpStatus.CREATED); - } - +package xy.spring2nosql.controller.Mongo; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import xy.spring2nosql.model.Mongo.Department; +import xy.spring2nosql.model.Mongo.Location; +import xy.spring2nosql.model.Mongo.Person; +import xy.spring2nosql.repository.Mongo.DepartmentRepository; +import xy.spring2nosql.repository.Mongo.PersonRepository; + +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Optional; + +@RestController +@RequestMapping("/mongo") +public class MongoDataController { + + @Autowired + PersonRepository personRepository; + @Autowired + DepartmentRepository departmentRepository; + + @RequestMapping("/persons/{name}") + public Person getPerson(@PathVariable("name") String name){ + return personRepository.findByName(name); + } + + @GetMapping("findAll") + public List getUserList() { + List userInfoList = personRepository.findAll(); + return userInfoList; + } + + @GetMapping("query1") + public Person q1(String name){ + return personRepository.findByName(name); + } + + @GetMapping("query2") + public List q2(Integer age){ + return personRepository.withQueryFindByAge(age); + } + + @GetMapping("delete") + public String delete(String id) { + personRepository.deleteById(id); + return "success"; + } + + @DeleteMapping("/colleagues/{name}") + public ResponseEntity deleteColleague(@PathVariable String name){ + Person person = personRepository.findByName(name); + if(person!=null) { + personRepository.delete(person); + return new ResponseEntity<>(HttpStatus.ACCEPTED); + } + return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + } + + @GetMapping("insert") + public Person insert(Long id, String username, String password) { + Person user = new Person("test2",22); + return personRepository.insert(user); + } + + //要先执行添加部门的操作 + @RequestMapping("saveDepartment") + public Department saveDepartment(){ + Department d = new Department("abc001","研发部"); + return departmentRepository.save(d); + } + + //执行这个之前要先执行”saveDepartment“,因为需要一个部门的引用 + @RequestMapping("save") + public Person save(){ + Person p = new Person("王昕",32); + Collection locations = new LinkedHashSet(); + Location loc1 = new Location("上海","2009"); + Location loc2 = new Location("广州","2011"); + locations.add(loc1); + locations.add(loc2); + + p.setLocations(locations); + + Department d = departmentRepository.findByName("研发部"); + p.setDepartment(d); + + return personRepository.save(p); + } + + + @PostMapping("/formsave") + public ResponseEntity addColleague(@RequestBody Person person){ + personRepository.save(person); + return new ResponseEntity<>(HttpStatus.CREATED); + } + } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/Redis/RedisDataController.java b/src/main/java/xy/spring2nosql/controller/Redis/RedisDataController.java similarity index 73% rename from src/main/java/xy/SpringBoot2NoSQL/controller/Redis/RedisDataController.java rename to src/main/java/xy/spring2nosql/controller/Redis/RedisDataController.java index 1343cf3..76ec91a 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/Redis/RedisDataController.java +++ b/src/main/java/xy/spring2nosql/controller/Redis/RedisDataController.java @@ -1,34 +1,34 @@ -package xy.SpringBoot2NoSQL.controller.Redis; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import xy.SpringBoot2NoSQL.model.Redis.User; -import xy.SpringBoot2NoSQL.repository.Redis.ObjectRepository; -import xy.SpringBoot2NoSQL.repository.Redis.StringStringRepository; -import xy.SpringBoot2NoSQL.repository.Redis.UserRepository; - -@RestController -@RequestMapping("/redis") -public class RedisDataController { - - @Autowired - ObjectRepository objRepository; - @Autowired - StringStringRepository stringStringRepository; - - @RequestMapping("/add/{name}") - public String getRecognition(@PathVariable("name") String name){ - User user = new User(name,name); - objRepository.save(user); - - return "add success."; - } - - @RequestMapping("/user/{name}") - public User getUser(@PathVariable("name") String name){ - return (User)objRepository.get(name); - - } -} +package xy.spring2nosql.controller.Redis; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import xy.spring2nosql.model.Redis.User; +import xy.spring2nosql.repository.Redis.ObjectRepository; +import xy.spring2nosql.repository.Redis.StringStringRepository; +import xy.spring2nosql.repository.Redis.UserRepository; + +@RestController +@RequestMapping("/redis") +public class RedisDataController { + + @Autowired + ObjectRepository objRepository; + @Autowired + StringStringRepository stringStringRepository; + + @RequestMapping("/add/{name}") + public String getRecognition(@PathVariable("name") String name){ + User user = new User(name,name); + objRepository.save(user); + + return "add success."; + } + + @RequestMapping("/user/{name}") + public User getUser(@PathVariable("name") String name){ + return (User)objRepository.get(name); + + } +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/Redis/RedissonController.java b/src/main/java/xy/spring2nosql/controller/Redis/RedissonController.java similarity index 95% rename from src/main/java/xy/SpringBoot2NoSQL/controller/Redis/RedissonController.java rename to src/main/java/xy/spring2nosql/controller/Redis/RedissonController.java index 110be44..bdae953 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/Redis/RedissonController.java +++ b/src/main/java/xy/spring2nosql/controller/Redis/RedissonController.java @@ -1,329 +1,329 @@ -package xy.SpringBoot2NoSQL.controller.Redis; - -import java.util.concurrent.TimeUnit; - -import org.redisson.Redisson; -import org.redisson.api.BatchOptions; -import org.redisson.api.BatchResult; -import org.redisson.api.LocalCachedMapOptions; -import org.redisson.api.RAtomicDouble; -import org.redisson.api.RBatch; -import org.redisson.api.RBloomFilter; -import org.redisson.api.RBoundedBlockingQueue; -import org.redisson.api.RBucket; -import org.redisson.api.RHyperLogLog; -import org.redisson.api.RLocalCachedMap; -import org.redisson.api.RLongAdder; -import org.redisson.api.RMapCache; -import org.redisson.api.RScoredSortedSet; -import org.redisson.api.RedissonClient; -import org.redisson.api.TransactionOptions; -import org.redisson.api.map.event.EntryCreatedListener; -import org.redisson.api.map.event.EntryEvent; -import org.redisson.api.map.event.EntryExpiredListener; -import org.redisson.api.map.event.EntryRemovedListener; -import org.redisson.api.map.event.EntryUpdatedListener; -import org.redisson.config.Config; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import io.netty.util.concurrent.Future; -import xy.SpringBoot2NoSQL.config.RedissonConfig; -import xy.SpringBoot2NoSQL.model.Redis.User; -import xy.SpringBoot2NoSQL.utils.RedissonUtil; - - -@RestController -@RequestMapping("/redisson") -public class RedissonController { - - // 单Redis节点模式,默认连接地址 127.0.0.1:6379 - RedissonClient redisson = Redisson.create(); - - - /** - * Map 获取 - * @param name - * @param key - * @return - */ - @RequestMapping("/getMap/{name}/{key}") - public String get(@PathVariable("name") String name,@PathVariable("key") String key){ - - String result = (String) redisson.getMap(name).get(key); - - return result; - } - - /** - * 本地缓存(Local Cache)也叫就近缓存(Near Cache)。 - * 这类映射的使用主要用于在特定的场景下,映射缓存(MapCache)上的高度频繁的读取操作, - * 使网络通信都被视为瓶颈的情况。Redisson与Redis通信的同时,还将部分数据保存在本地内存里。这样的设计的好处是它能将读取速度提高最多 45倍 - * @param name - * @param key - * @return - */ - @RequestMapping("/getLocalCachedMap/{name}/{key}") - public String getLocalCachedMap(@PathVariable("name") String name,@PathVariable("key") String key){ - - LocalCachedMapOptions options = LocalCachedMapOptions.defaults() - .evictionPolicy(LocalCachedMapOptions.EvictionPolicy.LFU) - .cacheSize(100) - .syncStrategy(LocalCachedMapOptions.SyncStrategy.UPDATE) //同步缓存 - .timeToLive(10, TimeUnit.SECONDS) - .maxIdle(10, TimeUnit.SECONDS); - - RLocalCachedMap map = redisson.getLocalCachedMap(name,options); - - map.put(key, "测试值"); - - String result = (String)map.get(key); - - return result; - } - - /** - * 元素淘汰功能(Eviction)和事件监听 - * 带有元素淘汰(Eviction)机制的映射类允许针对一个映射中每个元素单独设定 有效时间 和 最长闲置时间 。 - * @param name - * @param key - * @return - */ - @RequestMapping("/getMapCache/{name}/{key}") - public int getMapCache(@PathVariable("name") String name,@PathVariable("key") String key){ - - RMapCache map = redisson.getMapCache(name); - //LRU有界映射设置 - // 将该映射的最大容量限制设定或更改为10 - map.setMaxSize(10); - - map.put(key, 999); - map.put(key+"_TimeTtoLive", 888, 1, TimeUnit.SECONDS);//有效时间1秒 - - int updateListener = map.addListener(new EntryUpdatedListener() { - @Override - public void onUpdated(EntryEvent event) { -// event.getKey(); // 字段名 -// event.getValue(); // 新值 -// event.getOldValue(); // 旧值 - } - }); - - int createListener = map.addListener(new EntryCreatedListener() { - @Override - public void onCreated(EntryEvent event) { -// event.getKey(); // 字段名 -// event.getValue(); // 值 - } - }); - - int expireListener = map.addListener(new EntryExpiredListener() { - @Override - public void onExpired(EntryEvent event) { -// event.getKey(); // 字段名 -// event.getValue(); // 值 - - } - }); - - int removeListener = map.addListener(new EntryRemovedListener() { - @Override - public void onRemoved(EntryEvent event) { -// event.getKey(); // 字段名 -// event.getValue(); // 值 - } - }); - - map.removeListener(updateListener); - map.removeListener(createListener); - map.removeListener(expireListener); - map.removeListener(removeListener); - try { - Thread.sleep(200);//如果改成1000以上,则无法取出映射的值,因为已删除 - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - int result = map.get(key+"_TimeTtoLive"); - return result; - } - - - /** - * 设置分布式对象桶(Object Bucket) - * @param key - * @param name - * @param value - * @return - */ - @RequestMapping("/setObjectBucket/{key}") - public String setObjectBucket(@PathVariable("key") String key){ - - RBucket bucket = redisson.getBucket(key); - bucket.set(new User("wangxin","王昕")); - - return "objectBucket set success."; - } - - @RequestMapping("/getBucket/{key}") - public User getBucket(@PathVariable("key") String key){ - - User user = (User) RedissonUtil.getRBucket(redisson, key).get(); - - return user; - } - - - /** - * 分布式基数估计算法 - * @param key - * @return - */ - @RequestMapping("/hyperLogLog/{key}") - public Long hyperLogLog(@PathVariable("key") String key){ - - RHyperLogLog log = redisson.getHyperLogLog(key); - - log.add(1); - log.add(2); - log.add(3); - - Long count =log.count(); - - return count; - } - - - /** - * 分布式整长型累加器 - * 基于Redis的Redisson分布式整长型累加器采用了与java.util.concurrent.atomic.LongAdder类似的接口。 - * 通过利用客户端内置的LongAdder对象,为分布式环境下递增和递减操作提供了很高得性能。 - * 据统计其性能最高比分布式AtomicLong对象快 12000 倍。完美适用于分布式统计计量场景。 - * @param key - * @return - */ - @RequestMapping("/longAdder/{key}") - public Long longAdder(@PathVariable("key") String key){ - - RLongAdder atomicLong = redisson.getLongAdder(key); - atomicLong.add(12); - atomicLong.increment(); - atomicLong.increment(); - atomicLong.decrement(); - - Long count =atomicLong.sum(); - - return count; - } - - /** - * 分布式原子双精度浮点 - * 分布式原子双精度浮点RAtomicDouble,弥补了Java自身的不足 - * @param key - * @return - */ - @RequestMapping("/atomicDouble/{key}") - public double atomicDouble(@PathVariable("key") String key){ - - RAtomicDouble atomicDouble = redisson.getAtomicDouble(key); - atomicDouble.set(123.11); - atomicDouble.addAndGet(4.25); - - double value = atomicDouble.get(); - - return value; - } - - /** - * 异步批量执行 - * @param key - * @return - */ - @RequestMapping("/batch") - public String batch(){ - - RBatch batch = redisson.createBatch(BatchOptions.defaults()); - //RTransaction RTransaction = redisson.createTransaction(TransactionOptions.defaults()) - batch.getMap("test").fastPutAsync("1", "2"); - batch.getMap("test").fastPutAsync("2", "3"); - batch.getMap("test").putAsync("2", "新的值"); - - // 将写入操作同步到从节点 - // 同步到2个从节点,等待时间为1秒钟 - //batch.syncSlaves(2, 1, TimeUnit.SECONDS); - - BatchResult res = batch.execute(); - - return res.getResponses().toString(); - } - - - - /** - * 计分排序集(ScoredSortedSet) - * @return - */ - @RequestMapping("/scoredSortedSet") - public String ScoredSortedSet(){ - - RScoredSortedSet set = redisson.getScoredSortedSet("scoredSortedSet"); - set.clear(); - - set.add(3.13, new User("Tom","Tom name")); - set.addAsync(0.123, new User("Dog","Dog name")); - - User user = new User("Cat","Cat name"); - set.add(4.67, user); - set.addScore(user, 0.1); //加分 - - int index = set.rank(user); // 获取元素在集合中的位置 - - Double score = set.getScore(user); // 获取元素的评分 - - return "位置:"+index +",分数:"+score; - } - - - /** - * 有界阻塞队列(Bounded Blocking Queue) - * @return - */ - @RequestMapping("/boundedBlockingQueue") - public String BoundedBlockingQueue(){ - - RBoundedBlockingQueue queue = redisson.getBoundedBlockingQueue("anyQueue"); - queue.clear(); - // 如果初始容量(边界)设定成功则返回`真(true)`, - // 如果初始容量(边界)已近存在则返回`假(false)`。 - queue.trySetCapacity(2); - - queue.offer(new User("Tom","Tom name")); - queue.offer(new User("Cat","Cat name")); - //此时容量已满,add方法会直接阻塞 - //queue.add(new User("Cat2","Cat2 name")); - // 此时容量已满,下面代码将会被阻塞,直到有空闲为止。 - try { - queue.put(new User("Dog","Dog name")); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - User obj = queue.peek();//获取队列第一个元素,但并不从队列中删除 - User obj2 = null; - try { - obj2 = queue.poll(3, TimeUnit.SECONDS);//获取队列第一个元素,并删除 - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - User obj3 = queue.poll(); - return obj.getLogin() +","+ obj2.getLogin()+","+ obj3.getLogin(); - } - - - -} +package xy.spring2nosql.controller.Redis; + +import java.util.concurrent.TimeUnit; + +import org.redisson.Redisson; +import org.redisson.api.BatchOptions; +import org.redisson.api.BatchResult; +import org.redisson.api.LocalCachedMapOptions; +import org.redisson.api.RAtomicDouble; +import org.redisson.api.RBatch; +import org.redisson.api.RBloomFilter; +import org.redisson.api.RBoundedBlockingQueue; +import org.redisson.api.RBucket; +import org.redisson.api.RHyperLogLog; +import org.redisson.api.RLocalCachedMap; +import org.redisson.api.RLongAdder; +import org.redisson.api.RMapCache; +import org.redisson.api.RScoredSortedSet; +import org.redisson.api.RedissonClient; +import org.redisson.api.TransactionOptions; +import org.redisson.api.map.event.EntryCreatedListener; +import org.redisson.api.map.event.EntryEvent; +import org.redisson.api.map.event.EntryExpiredListener; +import org.redisson.api.map.event.EntryRemovedListener; +import org.redisson.api.map.event.EntryUpdatedListener; +import org.redisson.config.Config; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import io.netty.util.concurrent.Future; +import xy.spring2nosql.config.RedissonConfig; +import xy.spring2nosql.model.Redis.User; +import xy.spring2nosql.utils.RedissonUtil; + + +@RestController +@RequestMapping("/redisson") +public class RedissonController { + + // 单Redis节点模式,默认连接地址 127.0.0.1:6379 + RedissonClient redisson = Redisson.create(); + + + /** + * Map 获取 + * @param name + * @param key + * @return + */ + @RequestMapping("/getMap/{name}/{key}") + public String get(@PathVariable("name") String name,@PathVariable("key") String key){ + + String result = (String) redisson.getMap(name).get(key); + + return result; + } + + /** + * 本地缓存(Local Cache)也叫就近缓存(Near Cache)。 + * 这类映射的使用主要用于在特定的场景下,映射缓存(MapCache)上的高度频繁的读取操作, + * 使网络通信都被视为瓶颈的情况。Redisson与Redis通信的同时,还将部分数据保存在本地内存里。这样的设计的好处是它能将读取速度提高最多 45倍 + * @param name + * @param key + * @return + */ + @RequestMapping("/getLocalCachedMap/{name}/{key}") + public String getLocalCachedMap(@PathVariable("name") String name,@PathVariable("key") String key){ + + LocalCachedMapOptions options = LocalCachedMapOptions.defaults() + .evictionPolicy(LocalCachedMapOptions.EvictionPolicy.LFU) + .cacheSize(100) + .syncStrategy(LocalCachedMapOptions.SyncStrategy.UPDATE) //同步缓存 + .timeToLive(10, TimeUnit.SECONDS) + .maxIdle(10, TimeUnit.SECONDS); + + RLocalCachedMap map = redisson.getLocalCachedMap(name,options); + + map.put(key, "测试值"); + + String result = (String)map.get(key); + + return result; + } + + /** + * 元素淘汰功能(Eviction)和事件监听 + * 带有元素淘汰(Eviction)机制的映射类允许针对一个映射中每个元素单独设定 有效时间 和 最长闲置时间 。 + * @param name + * @param key + * @return + */ + @RequestMapping("/getMapCache/{name}/{key}") + public int getMapCache(@PathVariable("name") String name,@PathVariable("key") String key){ + + RMapCache map = redisson.getMapCache(name); + //LRU有界映射设置 + // 将该映射的最大容量限制设定或更改为10 + map.setMaxSize(10); + + map.put(key, 999); + map.put(key+"_TimeTtoLive", 888, 1, TimeUnit.SECONDS);//有效时间1秒 + + int updateListener = map.addListener(new EntryUpdatedListener() { + @Override + public void onUpdated(EntryEvent event) { +// event.getKey(); // 字段名 +// event.getValue(); // 新值 +// event.getOldValue(); // 旧值 + } + }); + + int createListener = map.addListener(new EntryCreatedListener() { + @Override + public void onCreated(EntryEvent event) { +// event.getKey(); // 字段名 +// event.getValue(); // 值 + } + }); + + int expireListener = map.addListener(new EntryExpiredListener() { + @Override + public void onExpired(EntryEvent event) { +// event.getKey(); // 字段名 +// event.getValue(); // 值 + + } + }); + + int removeListener = map.addListener(new EntryRemovedListener() { + @Override + public void onRemoved(EntryEvent event) { +// event.getKey(); // 字段名 +// event.getValue(); // 值 + } + }); + + map.removeListener(updateListener); + map.removeListener(createListener); + map.removeListener(expireListener); + map.removeListener(removeListener); + try { + Thread.sleep(200);//如果改成1000以上,则无法取出映射的值,因为已删除 + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + int result = map.get(key+"_TimeTtoLive"); + return result; + } + + + /** + * 设置分布式对象桶(Object Bucket) + * @param key + * @param name + * @param value + * @return + */ + @RequestMapping("/setObjectBucket/{key}") + public String setObjectBucket(@PathVariable("key") String key){ + + RBucket bucket = redisson.getBucket(key); + bucket.set(new User("wangxin","王昕")); + + return "objectBucket set success."; + } + + @RequestMapping("/getBucket/{key}") + public User getBucket(@PathVariable("key") String key){ + + User user = (User) RedissonUtil.getRBucket(redisson, key).get(); + + return user; + } + + + /** + * 分布式基数估计算法 + * @param key + * @return + */ + @RequestMapping("/hyperLogLog/{key}") + public Long hyperLogLog(@PathVariable("key") String key){ + + RHyperLogLog log = redisson.getHyperLogLog(key); + + log.add(1); + log.add(2); + log.add(3); + + Long count =log.count(); + + return count; + } + + + /** + * 分布式整长型累加器 + * 基于Redis的Redisson分布式整长型累加器采用了与java.util.concurrent.atomic.LongAdder类似的接口。 + * 通过利用客户端内置的LongAdder对象,为分布式环境下递增和递减操作提供了很高得性能。 + * 据统计其性能最高比分布式AtomicLong对象快 12000 倍。完美适用于分布式统计计量场景。 + * @param key + * @return + */ + @RequestMapping("/longAdder/{key}") + public Long longAdder(@PathVariable("key") String key){ + + RLongAdder atomicLong = redisson.getLongAdder(key); + atomicLong.add(12); + atomicLong.increment(); + atomicLong.increment(); + atomicLong.decrement(); + + Long count =atomicLong.sum(); + + return count; + } + + /** + * 分布式原子双精度浮点 + * 分布式原子双精度浮点RAtomicDouble,弥补了Java自身的不足 + * @param key + * @return + */ + @RequestMapping("/atomicDouble/{key}") + public double atomicDouble(@PathVariable("key") String key){ + + RAtomicDouble atomicDouble = redisson.getAtomicDouble(key); + atomicDouble.set(123.11); + atomicDouble.addAndGet(4.25); + + double value = atomicDouble.get(); + + return value; + } + + /** + * 异步批量执行 + * @param key + * @return + */ + @RequestMapping("/batch") + public String batch(){ + + RBatch batch = redisson.createBatch(BatchOptions.defaults()); + //RTransaction RTransaction = redisson.createTransaction(TransactionOptions.defaults()) + batch.getMap("test").fastPutAsync("1", "2"); + batch.getMap("test").fastPutAsync("2", "3"); + batch.getMap("test").putAsync("2", "新的值"); + + // 将写入操作同步到从节点 + // 同步到2个从节点,等待时间为1秒钟 + //batch.syncSlaves(2, 1, TimeUnit.SECONDS); + + BatchResult res = batch.execute(); + + return res.getResponses().toString(); + } + + + + /** + * 计分排序集(ScoredSortedSet) + * @return + */ + @RequestMapping("/scoredSortedSet") + public String ScoredSortedSet(){ + + RScoredSortedSet set = redisson.getScoredSortedSet("scoredSortedSet"); + set.clear(); + + set.add(3.13, new User("Tom","Tom name")); + set.addAsync(0.123, new User("Dog","Dog name")); + + User user = new User("Cat","Cat name"); + set.add(4.67, user); + set.addScore(user, 0.1); //加分 + + int index = set.rank(user); // 获取元素在集合中的位置 + + Double score = set.getScore(user); // 获取元素的评分 + + return "位置:"+index +",分数:"+score; + } + + + /** + * 有界阻塞队列(Bounded Blocking Queue) + * @return + */ + @RequestMapping("/boundedBlockingQueue") + public String BoundedBlockingQueue(){ + + RBoundedBlockingQueue queue = redisson.getBoundedBlockingQueue("anyQueue"); + queue.clear(); + // 如果初始容量(边界)设定成功则返回`真(true)`, + // 如果初始容量(边界)已近存在则返回`假(false)`。 + queue.trySetCapacity(2); + + queue.offer(new User("Tom","Tom name")); + queue.offer(new User("Cat","Cat name")); + //此时容量已满,add方法会直接阻塞 + //queue.add(new User("Cat2","Cat2 name")); + // 此时容量已满,下面代码将会被阻塞,直到有空闲为止。 + try { + queue.put(new User("Dog","Dog name")); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + User obj = queue.peek();//获取队列第一个元素,但并不从队列中删除 + User obj2 = null; + try { + obj2 = queue.poll(3, TimeUnit.SECONDS);//获取队列第一个元素,并删除 + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + User obj3 = queue.poll(); + return obj.getLogin() +","+ obj2.getLogin()+","+ obj3.getLogin(); + } + + + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/controller/Solr/SolrController.java b/src/main/java/xy/spring2nosql/controller/Solr/SolrController.java similarity index 86% rename from src/main/java/xy/SpringBoot2NoSQL/controller/Solr/SolrController.java rename to src/main/java/xy/spring2nosql/controller/Solr/SolrController.java index 5366aae..a285508 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/controller/Solr/SolrController.java +++ b/src/main/java/xy/spring2nosql/controller/Solr/SolrController.java @@ -1,51 +1,51 @@ -package xy.SpringBoot2NoSQL.controller.Solr; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import xy.SpringBoot2NoSQL.model.Solr.Customer; -import xy.SpringBoot2NoSQL.repository.Solr.SolrCustomerRepository; - -@RestController -@RequestMapping("/solr") -public class SolrController { - - @Autowired - SolrCustomerRepository customerRepository; - - @RequestMapping("/add") - public String add(){ - - customerRepository.deleteAll(); - customerRepository.saveAll(Arrays.asList(new Customer("1", "Jack", 20), - new Customer("2", "Adam", 24), - new Customer("3", "Kim", 27), - new Customer("4", "David", 30), - new Customer("5", "Peter", 21))); - - return "ok"; - } - - @RequestMapping("/all") - public Iterable getAll(){ - - return customerRepository.findAll(); - } - - @RequestMapping("/getByID/{id}") - public Optional getByID(@PathVariable("id") String id){ - - return customerRepository.findById(id); - } - - @RequestMapping("/findByNameEndsWith/{name}") - public List findByNameEndsWith(@PathVariable("name") String name){ - - return customerRepository.findByNameEndsWith(name); - } -} +package xy.spring2nosql.controller.Solr; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import xy.spring2nosql.model.Solr.Customer; +import xy.spring2nosql.repository.Solr.SolrCustomerRepository; + +@RestController +@RequestMapping("/solr") +public class SolrController { + + @Autowired + SolrCustomerRepository customerRepository; + + @RequestMapping("/add") + public String add(){ + + customerRepository.deleteAll(); + customerRepository.saveAll(Arrays.asList(new Customer("1", "Jack", 20), + new Customer("2", "Adam", 24), + new Customer("3", "Kim", 27), + new Customer("4", "David", 30), + new Customer("5", "Peter", 21))); + + return "ok"; + } + + @RequestMapping("/all") + public Iterable getAll(){ + + return customerRepository.findAll(); + } + + @RequestMapping("/getByID/{id}") + public Optional getByID(@PathVariable("id") String id){ + + return customerRepository.findById(id); + } + + @RequestMapping("/findByNameEndsWith/{name}") + public List findByNameEndsWith(@PathVariable("name") String name){ + + return customerRepository.findByNameEndsWith(name); + } +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/exception/CreateIndexFailedException.java b/src/main/java/xy/spring2nosql/exception/CreateIndexFailedException.java similarity index 84% rename from src/main/java/xy/SpringBoot2NoSQL/exception/CreateIndexFailedException.java rename to src/main/java/xy/spring2nosql/exception/CreateIndexFailedException.java index 8bc5539..52623e5 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/exception/CreateIndexFailedException.java +++ b/src/main/java/xy/spring2nosql/exception/CreateIndexFailedException.java @@ -1,7 +1,7 @@ -package xy.SpringBoot2NoSQL.exception; - -public class CreateIndexFailedException extends RuntimeException { - public CreateIndexFailedException(String indexName, Throwable cause) { - super(String.format("Creating Index '%s' failed", indexName), cause); - } -} +package xy.spring2nosql.exception; + +public class CreateIndexFailedException extends RuntimeException { + public CreateIndexFailedException(String indexName, Throwable cause) { + super(String.format("Creating Index '%s' failed", indexName), cause); + } +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/exception/GetMappingFailedException.java b/src/main/java/xy/spring2nosql/exception/GetMappingFailedException.java similarity index 84% rename from src/main/java/xy/SpringBoot2NoSQL/exception/GetMappingFailedException.java rename to src/main/java/xy/spring2nosql/exception/GetMappingFailedException.java index 1bcfa8d..af8ac81 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/exception/GetMappingFailedException.java +++ b/src/main/java/xy/spring2nosql/exception/GetMappingFailedException.java @@ -1,7 +1,7 @@ -package xy.SpringBoot2NoSQL.exception; - -public class GetMappingFailedException extends RuntimeException { - public GetMappingFailedException(String indexName, Throwable cause) { - super(String.format("Create Mapping failed for Index '%s'", indexName), cause); - } -} +package xy.spring2nosql.exception; + +public class GetMappingFailedException extends RuntimeException { + public GetMappingFailedException(String indexName, Throwable cause) { + super(String.format("Create Mapping failed for Index '%s'", indexName), cause); + } +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/exception/IndicesExistsFailedException.java b/src/main/java/xy/spring2nosql/exception/IndicesExistsFailedException.java similarity index 84% rename from src/main/java/xy/SpringBoot2NoSQL/exception/IndicesExistsFailedException.java rename to src/main/java/xy/spring2nosql/exception/IndicesExistsFailedException.java index f31c8dd..4fefa69 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/exception/IndicesExistsFailedException.java +++ b/src/main/java/xy/spring2nosql/exception/IndicesExistsFailedException.java @@ -1,7 +1,7 @@ -package xy.SpringBoot2NoSQL.exception; - -public class IndicesExistsFailedException extends RuntimeException { - public IndicesExistsFailedException(String indexName, Throwable cause) { - super(String.format("Indices '%s' failed", indexName), cause); - } +package xy.spring2nosql.exception; + +public class IndicesExistsFailedException extends RuntimeException { + public IndicesExistsFailedException(String indexName, Throwable cause) { + super(String.format("Indices '%s' failed", indexName), cause); + } } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/exception/PutMappingFailedException.java b/src/main/java/xy/spring2nosql/exception/PutMappingFailedException.java similarity index 84% rename from src/main/java/xy/SpringBoot2NoSQL/exception/PutMappingFailedException.java rename to src/main/java/xy/spring2nosql/exception/PutMappingFailedException.java index 85c3b65..5920a9d 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/exception/PutMappingFailedException.java +++ b/src/main/java/xy/spring2nosql/exception/PutMappingFailedException.java @@ -1,7 +1,7 @@ -package xy.SpringBoot2NoSQL.exception; - -public class PutMappingFailedException extends RuntimeException { - public PutMappingFailedException(String indexName, Throwable cause) { - super(String.format("Put Mapping failed for Index '%s'", indexName), cause); - } -} +package xy.spring2nosql.exception; + +public class PutMappingFailedException extends RuntimeException { + public PutMappingFailedException(String indexName, Throwable cause) { + super(String.format("Put Mapping failed for Index '%s'", indexName), cause); + } +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/Cassandra/Customer.java b/src/main/java/xy/spring2nosql/model/Cassandra/Customer.java similarity index 92% rename from src/main/java/xy/SpringBoot2NoSQL/model/Cassandra/Customer.java rename to src/main/java/xy/spring2nosql/model/Cassandra/Customer.java index 1c78fd8..757e15d 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/Cassandra/Customer.java +++ b/src/main/java/xy/spring2nosql/model/Cassandra/Customer.java @@ -1,76 +1,76 @@ -package xy.SpringBoot2NoSQL.model.Cassandra; - -import java.util.HashSet; -import java.util.Set; - -import org.springframework.data.cassandra.core.mapping.Column; -import org.springframework.data.cassandra.core.mapping.PrimaryKey; -import org.springframework.data.cassandra.core.mapping.Table; - -@Table -public class Customer { - - @PrimaryKey - private String id; - private String firstname; - private String lastname; - private int age; - -// @Column -// private Set tags = new HashSet<>(); - - public Customer(){} - - public Customer(String id, String firstname, String lastname, int age){ - this.id = id; - this.firstname = firstname; - this.lastname = lastname; - this.age = age; - } - - public void setId(String id){ - this.id = id; - } - - public String getId(){ - return this.id; - } - - public void setFirstname(String firstname){ - this.firstname = firstname; - } - - public String getFirstname(){ - return this.firstname; - } - - public void setLastname(String lastname){ - this.lastname = lastname; - } - - public String getLastname(){ - return this.lastname; - } - - public void setAge(int age){ - this.age = age; - } - - public int getAge(){ - return this.age; - } - -// public Set getTags() { -// return tags; -// } -// -// public void setTags(final Set tags) { -// this.tags = tags; -// } - - @Override - public String toString() { - return String.format("Customer[id=%d, firstName='%s', lastName='%s', age=%d]", this.id, - this.firstname, this.lastname, this.age); - } -} +package xy.spring2nosql.model.Cassandra; + +import java.util.HashSet; +import java.util.Set; + +import org.springframework.data.cassandra.core.mapping.Column; +import org.springframework.data.cassandra.core.mapping.PrimaryKey; +import org.springframework.data.cassandra.core.mapping.Table; + +@Table +public class Customer { + + @PrimaryKey + private String id; + private String firstname; + private String lastname; + private int age; + +// @Column +// private Set tags = new HashSet<>(); + + public Customer(){} + + public Customer(String id, String firstname, String lastname, int age){ + this.id = id; + this.firstname = firstname; + this.lastname = lastname; + this.age = age; + } + + public void setId(String id){ + this.id = id; + } + + public String getId(){ + return this.id; + } + + public void setFirstname(String firstname){ + this.firstname = firstname; + } + + public String getFirstname(){ + return this.firstname; + } + + public void setLastname(String lastname){ + this.lastname = lastname; + } + + public String getLastname(){ + return this.lastname; + } + + public void setAge(int age){ + this.age = age; + } + + public int getAge(){ + return this.age; + } + +// public Set getTags() { +// return tags; +// } +// +// public void setTags(final Set tags) { +// this.tags = tags; +// } + + @Override + public String toString() { + return String.format("Customer[id=%d, firstName='%s', lastName='%s', age=%d]", this.id, + this.firstname, this.lastname, this.age); + } +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/Couchbase/Customer.java b/src/main/java/xy/spring2nosql/model/Couchbase/Customer.java similarity index 91% rename from src/main/java/xy/SpringBoot2NoSQL/model/Couchbase/Customer.java rename to src/main/java/xy/spring2nosql/model/Couchbase/Customer.java index 71bff3e..2bc02e6 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/Couchbase/Customer.java +++ b/src/main/java/xy/spring2nosql/model/Couchbase/Customer.java @@ -1,55 +1,55 @@ -//package xy.SpringBoot2NoSQL.model.Couchbase; -// -//import org.springframework.data.couchbase.core.mapping.Document; -// -//import com.couchbase.client.java.repository.annotation.Field; -//import com.couchbase.client.java.repository.annotation.Id; -// -// -//@Document -//public class Customer { -// @Id -// private String id; -// -// @Field -// private String firstName; -// -// @Field -// private String lastName; -// -// public Customer(String id, String firstName, String lastName){ -// this.id = id; -// this.firstName = firstName; -// this.lastName = lastName; -// } -// -// public String getId() { -// return this.id; -// } -// -// public void setId(String id) { -// this.id = id; -// } -// -// public String getFirstName() { -// return this.firstName; -// } -// -// public void setFirstName(String firstName) { -// this.firstName = firstName; -// } -// -// public String getLastName() { -// return this.lastName; -// } -// -// public void setLastName(String lastName) { -// this.lastName = lastName; -// } -// -// @Override -// public String toString() { -// return String.format("Customer[ id=%s, firstName=%s, lastName=%s]", this.id, this.firstName, this.lastName); -// } -//} -// +//package xy.spring2nosql.model.Couchbase; +// +//import org.springframework.data.couchbase.core.mapping.Document; +// +//import com.couchbase.client.java.repository.annotation.Field; +//import com.couchbase.client.java.repository.annotation.Id; +// +// +//@Document +//public class Customer { +// @Id +// private String id; +// +// @Field +// private String firstName; +// +// @Field +// private String lastName; +// +// public Customer(String id, String firstName, String lastName){ +// this.id = id; +// this.firstName = firstName; +// this.lastName = lastName; +// } +// +// public String getId() { +// return this.id; +// } +// +// public void setId(String id) { +// this.id = id; +// } +// +// public String getFirstName() { +// return this.firstName; +// } +// +// public void setFirstName(String firstName) { +// this.firstName = firstName; +// } +// +// public String getLastName() { +// return this.lastName; +// } +// +// public void setLastName(String lastName) { +// this.lastName = lastName; +// } +// +// @Override +// public String toString() { +// return String.format("Customer[ id=%s, firstName=%s, lastName=%s]", this.id, this.firstName, this.lastName); +// } +//} +// diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/ElasticSearch/Product.java b/src/main/java/xy/spring2nosql/model/ElasticSearch/Product.java similarity index 92% rename from src/main/java/xy/SpringBoot2NoSQL/model/ElasticSearch/Product.java rename to src/main/java/xy/spring2nosql/model/ElasticSearch/Product.java index b4b60a0..7bb057f 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/ElasticSearch/Product.java +++ b/src/main/java/xy/spring2nosql/model/ElasticSearch/Product.java @@ -1,57 +1,57 @@ -package xy.SpringBoot2NoSQL.model.ElasticSearch; - -import org.springframework.data.annotation.Id; -import org.springframework.data.elasticsearch.annotations.Document; - -@Document(indexName = "book",type = "book" , shards = 1, replicas = 0, refreshInterval = "-1") -public class Product { - @Id - private String id; - private String name; - private String description; - private boolean enabled; - - public Product() { - } - - public Product(String id, String name, String description, boolean enabled) { - this(); - this.id = id; - this.name = name; - this.description = description; - this.enabled = enabled; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - -} +package xy.spring2nosql.model.ElasticSearch; + +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; + +@Document(indexName = "book",type = "book" , shards = 1, replicas = 0, refreshInterval = "-1") +public class Product { + @Id + private String id; + private String name; + private String description; + private boolean enabled; + + public Product() { + } + + public Product(String id, String name, String description, boolean enabled) { + this(); + this.id = id; + this.name = name; + this.description = description; + this.enabled = enabled; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Department.java b/src/main/java/xy/spring2nosql/model/Mongo/Department.java similarity index 87% rename from src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Department.java rename to src/main/java/xy/spring2nosql/model/Mongo/Department.java index 629f9df..399ec41 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Department.java +++ b/src/main/java/xy/spring2nosql/model/Mongo/Department.java @@ -1,35 +1,35 @@ -package xy.SpringBoot2NoSQL.model.Mongo; - -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; - -@Document -public class Department { - - @Id - private String id; - - - private String name; - - public Department(String id, String name) { - super(); - this.id = id; - this.name = name; - } - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - - -} +package xy.spring2nosql.model.Mongo; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +@Document +public class Department { + + @Id + private String id; + + + private String name; + + public Department(String id, String name) { + super(); + this.id = id; + this.name = name; + } + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Location.java b/src/main/java/xy/spring2nosql/model/Mongo/Location.java similarity index 84% rename from src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Location.java rename to src/main/java/xy/spring2nosql/model/Mongo/Location.java index b3788de..260825c 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Location.java +++ b/src/main/java/xy/spring2nosql/model/Mongo/Location.java @@ -1,38 +1,38 @@ -package xy.SpringBoot2NoSQL.model.Mongo; - -public class Location { - - private String place; - - private String year; - - - - public Location(String place, String year) { - super(); - this.place = place; - this.year = year; - } - - public String getPlace() { - return place; - } - - public void setPlace(String place) { - this.place = place; - } - - public String getYear() { - return year; - } - - public void setYear(String year) { - this.year = year; - } - - - - - - +package xy.spring2nosql.model.Mongo; + +public class Location { + + private String place; + + private String year; + + + + public Location(String place, String year) { + super(); + this.place = place; + this.year = year; + } + + public String getPlace() { + return place; + } + + public void setPlace(String place) { + this.place = place; + } + + public String getYear() { + return year; + } + + public void setYear(String year) { + this.year = year; + } + + + + + + } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Person.java b/src/main/java/xy/spring2nosql/model/Mongo/Person.java similarity index 92% rename from src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Person.java rename to src/main/java/xy/spring2nosql/model/Mongo/Person.java index f1d0b79..44b7c43 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/Mongo/Person.java +++ b/src/main/java/xy/spring2nosql/model/Mongo/Person.java @@ -1,69 +1,69 @@ -package xy.SpringBoot2NoSQL.model.Mongo; - -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; -import org.springframework.data.mongodb.core.mapping.Field; -import org.springframework.data.mongodb.core.mapping.DBRef; - -import java.util.Collection; -import java.util.LinkedHashSet; - -@Document -public class Person { - @Id - private String id; - private String name; - private Integer age; - @Field("locs") - private Collection locations = new LinkedHashSet(); - @DBRef - Department department; - - - public Person(String name, Integer age) { - super(); - this.name = name; - this.age = age; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getAge() { - return age; - } - - public void setAge(Integer age) { - this.age = age; - } - - public Collection getLocations() { - return locations; - } - - public void setLocations(Collection locations) { - this.locations = locations; - } - - public Department getDepartment() { - return department; - } - - public void setDepartment(Department department) { - this.department = department; - } - +package xy.spring2nosql.model.Mongo; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.Field; +import org.springframework.data.mongodb.core.mapping.DBRef; + +import java.util.Collection; +import java.util.LinkedHashSet; + +@Document +public class Person { + @Id + private String id; + private String name; + private Integer age; + @Field("locs") + private Collection locations = new LinkedHashSet(); + @DBRef + Department department; + + + public Person(String name, Integer age) { + super(); + this.name = name; + this.age = age; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public Collection getLocations() { + return locations; + } + + public void setLocations(Collection locations) { + this.locations = locations; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } + } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/Redis/User.java b/src/main/java/xy/spring2nosql/model/Redis/User.java similarity index 90% rename from src/main/java/xy/SpringBoot2NoSQL/model/Redis/User.java rename to src/main/java/xy/spring2nosql/model/Redis/User.java index 2647b91..aaffd1a 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/Redis/User.java +++ b/src/main/java/xy/spring2nosql/model/Redis/User.java @@ -1,49 +1,49 @@ -package xy.SpringBoot2NoSQL.model.Redis; - -import java.io.Serializable; -import java.util.Date; - -public class User implements Serializable{ - - private static final long serialVersionUID = 1945136152785232109L; - - private String login; - - private String fullName; - - private Date lastLogin; - - public User() {} - - public User(String login, String fullName) { - this.login = login; - this.fullName = fullName; - this.lastLogin = new Date(); - } - - public String getLogin() { - return login; - } - - public void setLogin(String login) { - this.login = login; - } - - public String getFullName() { - return fullName; - } - - public void setFullName(String fullName) { - this.fullName = fullName; - } - - public Date getLastLogin() { - return lastLogin; - } - - public void setLastLogin(Date lastLogin) { - this.lastLogin = lastLogin; - } - -} - +package xy.spring2nosql.model.Redis; + +import java.io.Serializable; +import java.util.Date; + +public class User implements Serializable{ + + private static final long serialVersionUID = 1945136152785232109L; + + private String login; + + private String fullName; + + private Date lastLogin; + + public User() {} + + public User(String login, String fullName) { + this.login = login; + this.fullName = fullName; + this.lastLogin = new Date(); + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public Date getLastLogin() { + return lastLogin; + } + + public void setLastLogin(Date lastLogin) { + this.lastLogin = lastLogin; + } + +} + diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/Solr/Customer.java b/src/main/java/xy/spring2nosql/model/Solr/Customer.java similarity index 90% rename from src/main/java/xy/SpringBoot2NoSQL/model/Solr/Customer.java rename to src/main/java/xy/spring2nosql/model/Solr/Customer.java index 04ac131..db18592 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/Solr/Customer.java +++ b/src/main/java/xy/spring2nosql/model/Solr/Customer.java @@ -1,57 +1,57 @@ -package xy.SpringBoot2NoSQL.model.Solr; - -import org.apache.solr.client.solrj.beans.Field; -import org.springframework.data.annotation.Id; -import org.springframework.data.solr.core.mapping.SolrDocument; - -@SolrDocument(collection = "customer") -public class Customer { - @Id - @Field - private String id; - - @Field - private String name; - - @Field - private Integer age; - - public Customer() { - } - - public Customer(String id, String name, Integer age){ - this.id = id; - this.name = name; - this.age = age; - } - - public void setId(String id){ - this.id = id; - } - - public String getId(){ - return this.id; - } - - public void setName(String name){ - this.name = name; - } - - public String getName(){ - return this.name; - } - - public void setAge(Integer age){ - this.age = age; - } - - public Integer getAge(){ - return this.age; - } - - @Override - public String toString() { - return "Customer [id=" + this.id + ", name=" + this.name + ", age=" + this.age + "]"; - } -} - +package xy.spring2nosql.model.Solr; + +import org.apache.solr.client.solrj.beans.Field; +import org.springframework.data.annotation.Id; +import org.springframework.data.solr.core.mapping.SolrDocument; + +@SolrDocument(collection = "customer") +public class Customer { + @Id + @Field + private String id; + + @Field + private String name; + + @Field + private Integer age; + + public Customer() { + } + + public Customer(String id, String name, Integer age){ + this.id = id; + this.name = name; + this.age = age; + } + + public void setId(String id){ + this.id = id; + } + + public String getId(){ + return this.id; + } + + public void setName(String name){ + this.name = name; + } + + public String getName(){ + return this.name; + } + + public void setAge(Integer age){ + this.age = age; + } + + public Integer getAge(){ + return this.age; + } + + @Override + public String toString() { + return "Customer [id=" + this.id + ", name=" + this.name + ", age=" + this.age + "]"; + } +} + diff --git a/src/main/java/xy/SpringBoot2NoSQL/model/User.java b/src/main/java/xy/spring2nosql/model/User.java similarity index 91% rename from src/main/java/xy/SpringBoot2NoSQL/model/User.java rename to src/main/java/xy/spring2nosql/model/User.java index e81ae3b..9e99e00 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/model/User.java +++ b/src/main/java/xy/spring2nosql/model/User.java @@ -1,54 +1,54 @@ -package xy.SpringBoot2NoSQL.model; - -import java.io.Serializable; -import java.util.Date; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class User implements Serializable{ - - private static final long serialVersionUID = -510562806568452731L; - - Logger logger = LogManager.getLogger(getClass()); - - private String login; - - private String fullName; - - private Date lastLogin; - - public User() {} - - public User(String login, String fullName) { - this.login = login; - this.fullName = fullName; - this.lastLogin = new Date(); - } - - public String getLogin() { - return login; - } - - public void setLogin(String login) { - this.login = login; - } - - public String getFullName() { - return fullName; - } - - public void setFullName(String fullName) { - this.fullName = fullName; - } - - public Date getLastLogin() { - return lastLogin; - } - - public void setLastLogin(Date lastLogin) { - this.lastLogin = lastLogin; - } - -} - +package xy.spring2nosql.model; + +import java.io.Serializable; +import java.util.Date; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class User implements Serializable{ + + private static final long serialVersionUID = -510562806568452731L; + + Logger logger = LogManager.getLogger(getClass()); + + private String login; + + private String fullName; + + private Date lastLogin; + + public User() {} + + public User(String login, String fullName) { + this.login = login; + this.fullName = fullName; + this.lastLogin = new Date(); + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public Date getLastLogin() { + return lastLogin; + } + + public void setLastLogin(Date lastLogin) { + this.lastLogin = lastLogin; + } + +} + diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/Cassandra/CustomerRepository.java b/src/main/java/xy/spring2nosql/repository/Cassandra/CustomerRepository.java similarity index 85% rename from src/main/java/xy/SpringBoot2NoSQL/repository/Cassandra/CustomerRepository.java rename to src/main/java/xy/spring2nosql/repository/Cassandra/CustomerRepository.java index 258d394..94cb93d 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/Cassandra/CustomerRepository.java +++ b/src/main/java/xy/spring2nosql/repository/Cassandra/CustomerRepository.java @@ -1,25 +1,25 @@ -package xy.SpringBoot2NoSQL.repository.Cassandra; - -import java.util.List; - -import org.springframework.data.cassandra.repository.AllowFiltering; -import org.springframework.data.cassandra.repository.CassandraRepository; -import org.springframework.data.cassandra.repository.Query; - - -import xy.SpringBoot2NoSQL.model.Cassandra.Customer; - -public interface CustomerRepository extends CassandraRepository { - - @Query(value="SELECT * FROM customer WHERE firstname=?0") - public List findByFirstname(String firstname); - - @Query("SELECT * FROM customer WHERE age > ?0") - public List findCustomerHasAgeGreaterThan(int age); - - @AllowFiltering - public List findByLastname(String lastname); - - @AllowFiltering - public List findByAgeGreaterThan(int age); +package xy.spring2nosql.repository.Cassandra; + +import java.util.List; + +import org.springframework.data.cassandra.repository.AllowFiltering; +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.data.cassandra.repository.Query; + + +import xy.spring2nosql.model.Cassandra.Customer; + +public interface CustomerRepository extends CassandraRepository { + + @Query(value="SELECT * FROM customer WHERE firstname=?0") + public List findByFirstname(String firstname); + + @Query("SELECT * FROM customer WHERE age > ?0") + public List findCustomerHasAgeGreaterThan(int age); + + @AllowFiltering + public List findByLastname(String lastname); + + @AllowFiltering + public List findByAgeGreaterThan(int age); } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/Couchbase/CouchbaseCustomerRepository.java b/src/main/java/xy/spring2nosql/repository/Couchbase/CouchbaseCustomerRepository.java similarity index 80% rename from src/main/java/xy/SpringBoot2NoSQL/repository/Couchbase/CouchbaseCustomerRepository.java rename to src/main/java/xy/spring2nosql/repository/Couchbase/CouchbaseCustomerRepository.java index de1f756..2f43a46 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/Couchbase/CouchbaseCustomerRepository.java +++ b/src/main/java/xy/spring2nosql/repository/Couchbase/CouchbaseCustomerRepository.java @@ -1,17 +1,17 @@ -//package xy.SpringBoot2NoSQL.repository.Couchbase; -// -//import java.util.List; -// -//import org.springframework.data.couchbase.core.query.N1qlPrimaryIndexed; -//import org.springframework.data.couchbase.core.query.ViewIndexed; -//import org.springframework.data.couchbase.repository.CouchbaseRepository; -// -//import xy.SpringBoot2NoSQL.model.Couchbase.Customer; -// -// -//@N1qlPrimaryIndexed -//@ViewIndexed(designDoc = "customer", viewName = "all") -//public interface CouchbaseCustomerRepository extends CouchbaseRepository { -// -// List findByLastName(String name); -//} +//package xy.spring2nosql.repository.Couchbase; +// +//import java.util.List; +// +//import org.springframework.data.couchbase.core.query.N1qlPrimaryIndexed; +//import org.springframework.data.couchbase.core.query.ViewIndexed; +//import org.springframework.data.couchbase.repository.CouchbaseRepository; +// +//import xy.spring2nosql.model.Couchbase.Customer; +// +// +//@N1qlPrimaryIndexed +//@ViewIndexed(designDoc = "customer", viewName = "all") +//public interface CouchbaseCustomerRepository extends CouchbaseRepository { +// +// List findByLastName(String name); +//} diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/ElasticSearch/SampleProductRepository.java b/src/main/java/xy/spring2nosql/repository/ElasticSearch/SampleProductRepository.java similarity index 80% rename from src/main/java/xy/SpringBoot2NoSQL/repository/ElasticSearch/SampleProductRepository.java rename to src/main/java/xy/spring2nosql/repository/ElasticSearch/SampleProductRepository.java index 681bcc7..96d9629 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/ElasticSearch/SampleProductRepository.java +++ b/src/main/java/xy/spring2nosql/repository/ElasticSearch/SampleProductRepository.java @@ -1,15 +1,15 @@ -package xy.SpringBoot2NoSQL.repository.ElasticSearch; - -import org.springframework.data.domain.Pageable; -import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; - -import xy.SpringBoot2NoSQL.model.ElasticSearch.Product; - -import java.util.List; - -public interface SampleProductRepository extends ElasticsearchRepository { - List findByName(String name); - List findByDescription(String description); - List findByName(String name, Pageable pageable); - List findByNameAndId(String name, String id); -} +package xy.spring2nosql.repository.ElasticSearch; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; + +import xy.spring2nosql.model.ElasticSearch.Product; + +import java.util.List; + +public interface SampleProductRepository extends ElasticsearchRepository { + List findByName(String name); + List findByDescription(String description); + List findByName(String name, Pageable pageable); + List findByNameAndId(String name, String id); +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/Mongo/DepartmentRepository.java b/src/main/java/xy/spring2nosql/repository/Mongo/DepartmentRepository.java similarity index 66% rename from src/main/java/xy/SpringBoot2NoSQL/repository/Mongo/DepartmentRepository.java rename to src/main/java/xy/spring2nosql/repository/Mongo/DepartmentRepository.java index 563d2a1..b5fabaa 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/Mongo/DepartmentRepository.java +++ b/src/main/java/xy/spring2nosql/repository/Mongo/DepartmentRepository.java @@ -1,13 +1,13 @@ -package xy.SpringBoot2NoSQL.repository.Mongo; - -import org.springframework.data.mongodb.repository.MongoRepository; - -import xy.SpringBoot2NoSQL.model.Mongo.Department; - - -public interface DepartmentRepository extends MongoRepository { - - Department findByName(String name); - -} - +package xy.spring2nosql.repository.Mongo; + +import org.springframework.data.mongodb.repository.MongoRepository; + +import xy.spring2nosql.model.Mongo.Department; + + +public interface DepartmentRepository extends MongoRepository { + + Department findByName(String name); + +} + diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/Mongo/PersonRepository.java b/src/main/java/xy/spring2nosql/repository/Mongo/PersonRepository.java similarity index 82% rename from src/main/java/xy/SpringBoot2NoSQL/repository/Mongo/PersonRepository.java rename to src/main/java/xy/spring2nosql/repository/Mongo/PersonRepository.java index 6ff6944..0045cc1 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/Mongo/PersonRepository.java +++ b/src/main/java/xy/spring2nosql/repository/Mongo/PersonRepository.java @@ -1,20 +1,20 @@ -package xy.SpringBoot2NoSQL.repository.Mongo; - - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.mongodb.repository.MongoRepository; -import org.springframework.data.mongodb.repository.Query; -import xy.SpringBoot2NoSQL.model.Mongo.Person; -import java.util.List; - -public interface PersonRepository extends MongoRepository { - - Person findByName(String name); - - @Query("{'age': { '$lt' : ?0}}") - List withQueryFindByAge(Integer age); - - Page findAll(Pageable pageable); - -} +package xy.spring2nosql.repository.Mongo; + + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.data.mongodb.repository.Query; +import xy.spring2nosql.model.Mongo.Person; +import java.util.List; + +public interface PersonRepository extends MongoRepository { + + Person findByName(String name); + + @Query("{'age': { '$lt' : ?0}}") + List withQueryFindByAge(Integer age); + + Page findAll(Pageable pageable); + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/Redis/ObjectRepository.java b/src/main/java/xy/spring2nosql/repository/Redis/ObjectRepository.java similarity index 84% rename from src/main/java/xy/SpringBoot2NoSQL/repository/Redis/ObjectRepository.java rename to src/main/java/xy/spring2nosql/repository/Redis/ObjectRepository.java index 34a5be0..ca819b1 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/Redis/ObjectRepository.java +++ b/src/main/java/xy/spring2nosql/repository/Redis/ObjectRepository.java @@ -1,27 +1,27 @@ -package xy.SpringBoot2NoSQL.repository.Redis; - -import javax.annotation.Resource; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; -import org.springframework.stereotype.Repository; - -import xy.SpringBoot2NoSQL.model.Redis.User; - -@Repository -public class ObjectRepository { - @Autowired - RedisTemplate redisTemplate; - - @Resource(name = "redisTemplate") - ValueOperations valOps; - - public void save(User user) { - valOps.set(user.getLogin(), user); - } - - public User get(String id) { - return (User) valOps.get(id); - } -} +package xy.spring2nosql.repository.Redis; + +import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Repository; + +import xy.spring2nosql.model.Redis.User; + +@Repository +public class ObjectRepository { + @Autowired + RedisTemplate redisTemplate; + + @Resource(name = "redisTemplate") + ValueOperations valOps; + + public void save(User user) { + valOps.set(user.getLogin(), user); + } + + public User get(String id) { + return (User) valOps.get(id); + } +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/Redis/StringStringRepository.java b/src/main/java/xy/spring2nosql/repository/Redis/StringStringRepository.java similarity index 89% rename from src/main/java/xy/SpringBoot2NoSQL/repository/Redis/StringStringRepository.java rename to src/main/java/xy/spring2nosql/repository/Redis/StringStringRepository.java index a454afe..e8213df 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/Redis/StringStringRepository.java +++ b/src/main/java/xy/spring2nosql/repository/Redis/StringStringRepository.java @@ -1,25 +1,25 @@ -package xy.SpringBoot2NoSQL.repository.Redis; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Repository; - -@Repository -public class StringStringRepository { - - @Autowired - private RedisTemplate template; - - public void add(String key, String value) { - template.opsForValue().set(key, value); - } - - public String getValue(String key) { - return template.opsForValue().get(key); - } - - public void delete(String key) { - template.opsForValue().getOperations().delete(key); - } - +package xy.spring2nosql.repository.Redis; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +@Repository +public class StringStringRepository { + + @Autowired + private RedisTemplate template; + + public void add(String key, String value) { + template.opsForValue().set(key, value); + } + + public String getValue(String key) { + return template.opsForValue().get(key); + } + + public void delete(String key) { + template.opsForValue().getOperations().delete(key); + } + } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/Redis/UserRepository.java b/src/main/java/xy/spring2nosql/repository/Redis/UserRepository.java similarity index 84% rename from src/main/java/xy/SpringBoot2NoSQL/repository/Redis/UserRepository.java rename to src/main/java/xy/spring2nosql/repository/Redis/UserRepository.java index ccd6fab..5cc4426 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/Redis/UserRepository.java +++ b/src/main/java/xy/spring2nosql/repository/Redis/UserRepository.java @@ -1,30 +1,30 @@ -package xy.SpringBoot2NoSQL.repository.Redis; - -import javax.annotation.Resource; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; -import org.springframework.stereotype.Repository; - -import xy.SpringBoot2NoSQL.model.Redis.User; - -@Repository -public class UserRepository { - -// @Autowired -// RedisTemplate redisTemplate; -// -// @Resource(name = "redisTemplate") -// ValueOperations valOps; -// -// public void save(User user) { -// valOps.set(user.getLogin(), user); -// } -// -// public User get(String id) { -// return valOps.get(id); -// } - - +package xy.spring2nosql.repository.Redis; + +import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Repository; + +import xy.spring2nosql.model.Redis.User; + +@Repository +public class UserRepository { + +// @Autowired +// RedisTemplate redisTemplate; +// +// @Resource(name = "redisTemplate") +// ValueOperations valOps; +// +// public void save(User user) { +// valOps.set(user.getLogin(), user); +// } +// +// public User get(String id) { +// return valOps.get(id); +// } + + } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/repository/Solr/SolrCustomerRepository.java b/src/main/java/xy/spring2nosql/repository/Solr/SolrCustomerRepository.java similarity index 70% rename from src/main/java/xy/SpringBoot2NoSQL/repository/Solr/SolrCustomerRepository.java rename to src/main/java/xy/spring2nosql/repository/Solr/SolrCustomerRepository.java index 4b78648..b5fab69 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/repository/Solr/SolrCustomerRepository.java +++ b/src/main/java/xy/spring2nosql/repository/Solr/SolrCustomerRepository.java @@ -1,10 +1,10 @@ -package xy.SpringBoot2NoSQL.repository.Solr; - -import java.util.List; -import org.springframework.data.solr.repository.SolrCrudRepository; -import xy.SpringBoot2NoSQL.model.Solr.Customer; - - -public interface SolrCustomerRepository extends SolrCrudRepository { - List findByNameEndsWith(String name); -} +package xy.spring2nosql.repository.Solr; + +import java.util.List; +import org.springframework.data.solr.repository.SolrCrudRepository; +import xy.spring2nosql.model.Solr.Customer; + + +public interface SolrCustomerRepository extends SolrCrudRepository { + List findByNameEndsWith(String name); +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/service/Ehcache/UserService.java b/src/main/java/xy/spring2nosql/service/Ehcache/UserService.java similarity index 92% rename from src/main/java/xy/SpringBoot2NoSQL/service/Ehcache/UserService.java rename to src/main/java/xy/spring2nosql/service/Ehcache/UserService.java index 3ca2c39..fa5db8c 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/service/Ehcache/UserService.java +++ b/src/main/java/xy/spring2nosql/service/Ehcache/UserService.java @@ -1,49 +1,49 @@ -package xy.SpringBoot2NoSQL.service.Ehcache; - -import org.springframework.cache.annotation.CacheConfig; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.stereotype.Service; -import net.sf.ehcache.Cache; -import net.sf.ehcache.CacheManager; -import net.sf.ehcache.Element; -import xy.SpringBoot2NoSQL.model.User; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -@Service -@CacheConfig(cacheNames="users") -public class UserService { - - Logger logger = LogManager.getLogger(getClass()); - - @CacheEvict(allEntries = true) - public void clearCache(){} - - public User getUser(String login) { - // 获取缓存实例 - Cache userCache = CacheManager.getInstance().getCache("users"); - - if (userCache.get(login)!=null){ - - User user = (User) userCache.get(login).getObjectValue(); - logger.info("从缓存获取user用户: {}", login); - logger.info("从缓存JVM内存中获取获取user用户: {}-{}",login, userCache.isElementInMemory(login)); - logger.info("从缓存OffHeap内存中获取获取user用户: {}-{}",login, userCache.isElementOffHeap(login)); - logger.info("已持久化磁盘,用户: {}-{}",login, userCache.isElementOnDisk(login)); - - return user; - } - else{ - User user = new User(login,login+"的姓名"); - logger.info("新user用户: {}", login); - // 写入缓存,注意我们故意设置maxElementsInMemory内存最大值是5 - Element element = new Element(login, user); - userCache.put(element); - - return user; - } - - } - -} +package xy.spring2nosql.service.Ehcache; + +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.stereotype.Service; +import net.sf.ehcache.Cache; +import net.sf.ehcache.CacheManager; +import net.sf.ehcache.Element; +import xy.spring2nosql.model.User; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +@Service +@CacheConfig(cacheNames="users") +public class UserService { + + Logger logger = LogManager.getLogger(getClass()); + + @CacheEvict(allEntries = true) + public void clearCache(){} + + public User getUser(String login) { + // 获取缓存实例 + Cache userCache = CacheManager.getInstance().getCache("users"); + + if (userCache.get(login)!=null){ + + User user = (User) userCache.get(login).getObjectValue(); + logger.info("从缓存获取user用户: {}", login); + logger.info("从缓存JVM内存中获取获取user用户: {}-{}",login, userCache.isElementInMemory(login)); + logger.info("从缓存OffHeap内存中获取获取user用户: {}-{}",login, userCache.isElementOffHeap(login)); + logger.info("已持久化磁盘,用户: {}-{}",login, userCache.isElementOnDisk(login)); + + return user; + } + else{ + User user = new User(login,login+"的姓名"); + logger.info("新user用户: {}", login); + // 写入缓存,注意我们故意设置maxElementsInMemory内存最大值是5 + Element element = new Element(login, user); + userCache.put(element); + + return user; + } + + } + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/utils/ESSearchUtil.java b/src/main/java/xy/spring2nosql/utils/ESSearchUtil.java similarity index 91% rename from src/main/java/xy/SpringBoot2NoSQL/utils/ESSearchUtil.java rename to src/main/java/xy/spring2nosql/utils/ESSearchUtil.java index 0e70f5b..449e744 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/utils/ESSearchUtil.java +++ b/src/main/java/xy/spring2nosql/utils/ESSearchUtil.java @@ -1,160 +1,160 @@ -package xy.SpringBoot2NoSQL.utils; - -import java.io.IOException; - -import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; -import org.elasticsearch.client.Client; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; - -import xy.SpringBoot2NoSQL.exception.CreateIndexFailedException; -import xy.SpringBoot2NoSQL.exception.IndicesExistsFailedException; -import xy.SpringBoot2NoSQL.exception.PutMappingFailedException; - -public class ESSearchUtil { - - /** - * 索引是否存在 - * @param client - * @param indexName - * @return - */ - public static IndicesExistsResponse indexExist(Client client, String indexName) { - try { - return client.admin().indices().prepareExists(indexName).execute().actionGet(); - } catch (Exception e) { - - throw new IndicesExistsFailedException(indexName, e); - } - } - - /** - * 创建索引 - * @param client - * @param indexName - * @return - */ - public static CreateIndexResponse createIndex(Client client, String indexName) { - try { - return internalCreateIndex(client, indexName); - } catch (Exception e) { - throw new CreateIndexFailedException(indexName, e); - } - } - - public static PutMappingResponse putMapping(Client client, String indexName, IElasticSearchMapping mapping) { - try { - return internalPutMapping(client, indexName, mapping); - } catch (Exception e) { - - throw new PutMappingFailedException(indexName, e); - } - } - - private static CreateIndexResponse internalCreateIndex(Client client, String indexName) throws IOException { - final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName); - - final CreateIndexResponse indexResponse = createIndexRequestBuilder.execute().actionGet(); - - return indexResponse; - } - - private static PutMappingResponse internalPutMapping(Client client, String indexName, IElasticSearchMapping mapping) - throws IOException { - - final PutMappingRequest putMappingRequest = new PutMappingRequest(indexName).type(mapping.getIndexType()) - .source(mapping.getMapping().string()); - - final PutMappingResponse putMappingResponse = client.admin().indices().putMapping(putMappingRequest) - .actionGet(); - - return putMappingResponse; - } - - /** - * 部分匹配查询,包括模糊匹配和短语或邻近查询。 - * - * @param key - * @param value - * @return - */ - public static QueryBuilder matchQuery(String key, String value) { - return QueryBuilders.matchQuery(key, value); - } - - /** - * 完全匹配。 - * - * @param key - * @param value - * @return - */ - public static QueryBuilder matchPhraseQuery(String key, String value) { - return QueryBuilders.matchPhraseQuery(key, value); - } - - /** - * 多字段匹配 - * - * @param text - * @param fieldNames - * @return - */ - public static QueryBuilder multiMatchQuery(Object text, String... fieldNames) { - return QueryBuilders.multiMatchQuery(text, fieldNames); - - } - - /** - * 模糊查询 - * - * @param key - * @param value - * @return - */ - public static QueryBuilder fuzzyQuery(String key, String value) { - return QueryBuilders.fuzzyQuery(key, value); - } - - /** - * 全部查询 - * - * @return - */ - public static QueryBuilder matchAllQuery() { - return QueryBuilders.matchAllQuery(); - } - - /** - * 范围查询 - * - * @param key - * @param from - * @param to - * @return - */ - public static QueryBuilder rangeQuery(String key, Object from, Object to) { - return QueryBuilders.rangeQuery(key).from(from).to(to).includeLower(true) // 包括下界 - .includeUpper(false); // 包括上界 - } - - /** - * 完全匹配查询 - * - * @param key - * @param values - * @return - */ - public static QueryBuilder termsQuery(String key, String... values) { - return QueryBuilders.termsQuery(key, values); - } - - public static QueryBuilder termsQuery(String key, Object values) { - return QueryBuilders.termsQuery(key, values); - } - -} +package xy.spring2nosql.utils; + +import java.io.IOException; + +import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; +import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; + +import xy.spring2nosql.exception.CreateIndexFailedException; +import xy.spring2nosql.exception.IndicesExistsFailedException; +import xy.spring2nosql.exception.PutMappingFailedException; + +public class ESSearchUtil { + + /** + * 索引是否存在 + * @param client + * @param indexName + * @return + */ + public static IndicesExistsResponse indexExist(Client client, String indexName) { + try { + return client.admin().indices().prepareExists(indexName).execute().actionGet(); + } catch (Exception e) { + + throw new IndicesExistsFailedException(indexName, e); + } + } + + /** + * 创建索引 + * @param client + * @param indexName + * @return + */ + public static CreateIndexResponse createIndex(Client client, String indexName) { + try { + return internalCreateIndex(client, indexName); + } catch (Exception e) { + throw new CreateIndexFailedException(indexName, e); + } + } + + public static PutMappingResponse putMapping(Client client, String indexName, IElasticSearchMapping mapping) { + try { + return internalPutMapping(client, indexName, mapping); + } catch (Exception e) { + + throw new PutMappingFailedException(indexName, e); + } + } + + private static CreateIndexResponse internalCreateIndex(Client client, String indexName) throws IOException { + final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName); + + final CreateIndexResponse indexResponse = createIndexRequestBuilder.execute().actionGet(); + + return indexResponse; + } + + private static PutMappingResponse internalPutMapping(Client client, String indexName, IElasticSearchMapping mapping) + throws IOException { + + final PutMappingRequest putMappingRequest = new PutMappingRequest(indexName).type(mapping.getIndexType()) + .source(mapping.getMapping().string()); + + final PutMappingResponse putMappingResponse = client.admin().indices().putMapping(putMappingRequest) + .actionGet(); + + return putMappingResponse; + } + + /** + * 部分匹配查询,包括模糊匹配和短语或邻近查询。 + * + * @param key + * @param value + * @return + */ + public static QueryBuilder matchQuery(String key, String value) { + return QueryBuilders.matchQuery(key, value); + } + + /** + * 完全匹配。 + * + * @param key + * @param value + * @return + */ + public static QueryBuilder matchPhraseQuery(String key, String value) { + return QueryBuilders.matchPhraseQuery(key, value); + } + + /** + * 多字段匹配 + * + * @param text + * @param fieldNames + * @return + */ + public static QueryBuilder multiMatchQuery(Object text, String... fieldNames) { + return QueryBuilders.multiMatchQuery(text, fieldNames); + + } + + /** + * 模糊查询 + * + * @param key + * @param value + * @return + */ + public static QueryBuilder fuzzyQuery(String key, String value) { + return QueryBuilders.fuzzyQuery(key, value); + } + + /** + * 全部查询 + * + * @return + */ + public static QueryBuilder matchAllQuery() { + return QueryBuilders.matchAllQuery(); + } + + /** + * 范围查询 + * + * @param key + * @param from + * @param to + * @return + */ + public static QueryBuilder rangeQuery(String key, Object from, Object to) { + return QueryBuilders.rangeQuery(key).from(from).to(to).includeLower(true) // 包括下界 + .includeUpper(false); // 包括上界 + } + + /** + * 完全匹配查询 + * + * @param key + * @param values + * @return + */ + public static QueryBuilder termsQuery(String key, String... values) { + return QueryBuilders.termsQuery(key, values); + } + + public static QueryBuilder termsQuery(String key, Object values) { + return QueryBuilders.termsQuery(key, values); + } + +} diff --git a/src/main/java/xy/SpringBoot2NoSQL/utils/IElasticSearchMapping.java b/src/main/java/xy/spring2nosql/utils/IElasticSearchMapping.java similarity index 83% rename from src/main/java/xy/SpringBoot2NoSQL/utils/IElasticSearchMapping.java rename to src/main/java/xy/spring2nosql/utils/IElasticSearchMapping.java index eb6b04e..2c29507 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/utils/IElasticSearchMapping.java +++ b/src/main/java/xy/spring2nosql/utils/IElasticSearchMapping.java @@ -1,14 +1,14 @@ -package xy.SpringBoot2NoSQL.utils; - -import org.elasticsearch.Version; -import org.elasticsearch.common.xcontent.XContentBuilder; - -public interface IElasticSearchMapping { - - XContentBuilder getMapping(); - - String getIndexType(); - - Version getVersion(); - +package xy.spring2nosql.utils; + +import org.elasticsearch.Version; +import org.elasticsearch.common.xcontent.XContentBuilder; + +public interface IElasticSearchMapping { + + XContentBuilder getMapping(); + + String getIndexType(); + + Version getVersion(); + } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/utils/RandomUtil.java b/src/main/java/xy/spring2nosql/utils/RandomUtil.java similarity index 95% rename from src/main/java/xy/SpringBoot2NoSQL/utils/RandomUtil.java rename to src/main/java/xy/spring2nosql/utils/RandomUtil.java index b88cafb..a788634 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/utils/RandomUtil.java +++ b/src/main/java/xy/spring2nosql/utils/RandomUtil.java @@ -1,120 +1,120 @@ -package xy.SpringBoot2NoSQL.utils; - -import java.util.Random; - -public class RandomUtil { - public static final String ALLCHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - public static final String LETTERCHAR = "abcdefghijkllmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - public static final String NUMBERCHAR = "0123456789"; - - /** - * 返回一个定长的随机字符串(只包含大小写字母、数字) - * - * @param length - * 随机字符串长度 - * @return 随机字符串 - */ - public static String generateString(int length) { - StringBuffer sb = new StringBuffer(); - Random random = new Random(); - for (int i = 0; i < length; i++) { - sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length()))); - } - return sb.toString(); - } - - /** - * 返回一个定长的随机纯字母字符串(只包含大小写字母) - * - * @param length - * 随机字符串长度 - * @return 随机字符串 - */ - public static String generateMixString(int length) { - StringBuffer sb = new StringBuffer(); - Random random = new Random(); - for (int i = 0; i < length; i++) { - sb.append(ALLCHAR.charAt(random.nextInt(LETTERCHAR.length()))); - } - return sb.toString(); - } - - /** - * 返回一个定长的随机纯大写字母字符串(只包含大小写字母) - * - * @param length - * 随机字符串长度 - * @return 随机字符串 - */ - public static String generateLowerString(int length) { - return generateMixString(length).toLowerCase(); - } - - /** - * 返回一个定长的随机纯小写字母字符串(只包含大小写字母) - * - * @param length - * 随机字符串长度 - * @return 随机字符串 - */ - public static String generateUpperString(int length) { - return generateMixString(length).toUpperCase(); - } - - /** - * 生成一个定长的纯0字符串 - * - * @param length - * 字符串长度 - * @return 纯0字符串 - */ - public static String generateZeroString(int length) { - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < length; i++) { - sb.append('0'); - } - return sb.toString(); - } - - /** - * 根据数字生成一个定长的字符串,长度不够前面补0 - * - * @param num - * 数字 - * @param fixdlenth - * 字符串长度 - * @return 定长的字符串 - */ - public static String toFixdLengthString(long num, int fixdlenth) { - StringBuffer sb = new StringBuffer(); - String strNum = String.valueOf(num); - if (fixdlenth - strNum.length() >= 0) { - sb.append(generateZeroString(fixdlenth - strNum.length())); - } else { - throw new RuntimeException("将数字" + num + "转化为长度为" + fixdlenth + "的字符串发生异常!"); - } - sb.append(strNum); - return sb.toString(); - } - - /** - * 每次生成的len位数都不相同 - * - * @param param - * @return 定长的数字 - */ - public static int getNotSimple(int[] param, int len) { - Random rand = new Random(); - for (int i = param.length; i > 1; i--) { - int index = rand.nextInt(i); - int tmp = param[index]; - param[index] = param[i - 1]; - param[i - 1] = tmp; - } - int result = 0; - for (int i = 0; i < len; i++) { - result = result * 10 + param[i]; - } - return result; - } +package xy.spring2nosql.utils; + +import java.util.Random; + +public class RandomUtil { + public static final String ALLCHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + public static final String LETTERCHAR = "abcdefghijkllmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + public static final String NUMBERCHAR = "0123456789"; + + /** + * 返回一个定长的随机字符串(只包含大小写字母、数字) + * + * @param length + * 随机字符串长度 + * @return 随机字符串 + */ + public static String generateString(int length) { + StringBuffer sb = new StringBuffer(); + Random random = new Random(); + for (int i = 0; i < length; i++) { + sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length()))); + } + return sb.toString(); + } + + /** + * 返回一个定长的随机纯字母字符串(只包含大小写字母) + * + * @param length + * 随机字符串长度 + * @return 随机字符串 + */ + public static String generateMixString(int length) { + StringBuffer sb = new StringBuffer(); + Random random = new Random(); + for (int i = 0; i < length; i++) { + sb.append(ALLCHAR.charAt(random.nextInt(LETTERCHAR.length()))); + } + return sb.toString(); + } + + /** + * 返回一个定长的随机纯大写字母字符串(只包含大小写字母) + * + * @param length + * 随机字符串长度 + * @return 随机字符串 + */ + public static String generateLowerString(int length) { + return generateMixString(length).toLowerCase(); + } + + /** + * 返回一个定长的随机纯小写字母字符串(只包含大小写字母) + * + * @param length + * 随机字符串长度 + * @return 随机字符串 + */ + public static String generateUpperString(int length) { + return generateMixString(length).toUpperCase(); + } + + /** + * 生成一个定长的纯0字符串 + * + * @param length + * 字符串长度 + * @return 纯0字符串 + */ + public static String generateZeroString(int length) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; i++) { + sb.append('0'); + } + return sb.toString(); + } + + /** + * 根据数字生成一个定长的字符串,长度不够前面补0 + * + * @param num + * 数字 + * @param fixdlenth + * 字符串长度 + * @return 定长的字符串 + */ + public static String toFixdLengthString(long num, int fixdlenth) { + StringBuffer sb = new StringBuffer(); + String strNum = String.valueOf(num); + if (fixdlenth - strNum.length() >= 0) { + sb.append(generateZeroString(fixdlenth - strNum.length())); + } else { + throw new RuntimeException("将数字" + num + "转化为长度为" + fixdlenth + "的字符串发生异常!"); + } + sb.append(strNum); + return sb.toString(); + } + + /** + * 每次生成的len位数都不相同 + * + * @param param + * @return 定长的数字 + */ + public static int getNotSimple(int[] param, int len) { + Random rand = new Random(); + for (int i = param.length; i > 1; i--) { + int index = rand.nextInt(i); + int tmp = param[index]; + param[index] = param[i - 1]; + param[i - 1] = tmp; + } + int result = 0; + for (int i = 0; i < len; i++) { + result = result * 10 + param[i]; + } + return result; + } } \ No newline at end of file diff --git a/src/main/java/xy/SpringBoot2NoSQL/utils/RedisCacheUtils.java b/src/main/java/xy/spring2nosql/utils/RedisCacheUtils.java similarity index 96% rename from src/main/java/xy/SpringBoot2NoSQL/utils/RedisCacheUtils.java rename to src/main/java/xy/spring2nosql/utils/RedisCacheUtils.java index b8e3898..f8c3944 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/utils/RedisCacheUtils.java +++ b/src/main/java/xy/spring2nosql/utils/RedisCacheUtils.java @@ -1,649 +1,649 @@ -//package xy.SpringBoot2NoSQL.utils; -// -//import java.util.ArrayList; -//import java.util.List; -//import java.util.Map; -//import java.util.Set; -//import java.util.concurrent.TimeUnit; -// -//import javax.annotation.PostConstruct; -//import javax.annotation.Resource; -// -//import org.springframework.data.redis.connection.RedisZSetCommands; -//import org.springframework.data.redis.core.ListOperations; -//import org.springframework.data.redis.core.RedisCallback; -//import org.springframework.data.redis.core.RedisTemplate; -//import org.springframework.data.redis.core.SetOperations; -//import org.springframework.data.redis.core.ValueOperations; -// -//import com.alibaba.fastjson.JSON; -//import com.alibaba.fastjson.parser.Feature; -// -//public class RedisCacheUtils { -// @Resource -// private RedisTemplate redisTemplate; -// -// private static RedisCacheUtils cacheUtils; -// -// @PostConstruct -// public void init() { -// cacheUtils = this; -// cacheUtils.redisTemplate = this.redisTemplate; -// } -// -// /** -// * 将数据存入缓存 -// * -// * @param key -// * @param val -// * @return -// */ -// public static void saveString(String key, String val) { -// -// ValueOperations vo = cacheUtils.redisTemplate.opsForValue(); -// vo.set(key, val); -// } -// -// /** -// * 将数据存入缓存的集合中 -// * -// * @param key -// * @param val -// * @return -// */ -// public static void saveToSet(String key, String val) { -// -// SetOperations so = cacheUtils.redisTemplate.opsForSet(); -// -// so.add(key, val); -// } -// -// /** -// * key 缓存Key -// * @param key -// * @return -// */ -// public static String getFromSet(String key) { -// return cacheUtils.redisTemplate.opsForSet().pop(key); -// } -// -// /** -// * 将 key的值保存为 value ,当且仅当 key 不存在。 若给定的 key 已经存在,则 SETNX 不做任何动作。 SETNX 是『SET if -// * Not eXists』(如果不存在,则 SET)的简写。
-// * 保存成功,返回 true
-// * 保存失败,返回 false -// */ -// public static boolean saveNX(String key, String val) { -// -// /** 设置成功,返回 1 设置失败,返回 0 **/ -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.setNX(key.getBytes(), val.getBytes()); -// }); -// -// } -// -// /** -// * 将 key的值保存为 value ,当且仅当 key 不存在。 若给定的 key 已经存在,则 SETNX 不做任何动作。 SETNX 是『SET if -// * Not eXists』(如果不存在,则 SET)的简写。
-// * 保存成功,返回 true
-// * 保存失败,返回 false -// * -// * @param key -// * @param val -// * @param expire 超时时间 -// * @return 保存成功,返回 true 否则返回 false -// */ -// public static boolean saveNX(String key, String val, int expire) { -// -// boolean ret = saveNX(key, val); -// if (ret) { -// cacheUtils.redisTemplate.expire(key, expire, TimeUnit.SECONDS); -// } -// return ret; -// } -// -// /** -// * 将数据存入缓存(并设置失效时间) -// * -// * @param key -// * @param val -// * @param seconds -// * @return -// */ -// public static void saveString(String key, String val, int seconds) { -// -// cacheUtils.redisTemplate.opsForValue().set(key, val, seconds, TimeUnit.SECONDS); -// } -// -// /** -// * 将自增变量存入缓存 -// */ -// public static void saveSeq(String key, long seqNo) { -// -// cacheUtils.redisTemplate.delete(key); -// cacheUtils.redisTemplate.opsForValue().increment(key, seqNo); -// } -// -// /** -// * 将递增浮点数存入缓存 -// */ -// public static void saveFloat(String key, float data) { -// -// cacheUtils.redisTemplate.delete(key); -// cacheUtils.redisTemplate.opsForValue().increment(key, data); -// } -// -// /** -// * 保存复杂类型数据到缓存 -// * -// * @param key -// * @param obj -// * @return -// */ -// public static void saveBean(String key, Object obj) { -// -// cacheUtils.redisTemplate.opsForValue().set(key, JSON.toJSONString(obj)); -// } -// -// /** -// * 保存复杂类型数据到缓存(并设置失效时间) -// * -// * @param key -// * @param obj -// * @param seconds -// */ -// public static void saveBean(String key, Object obj, int seconds) { -// -// cacheUtils.redisTemplate.opsForValue().set(key, JSON.toJSONString(obj), seconds, TimeUnit.SECONDS); -// } -// -// /** -// * 存到指定的队列中 -// * @param key -// * @param val -// * @param size -// */ -// public static void saveToQueue(String key, String val, long size) { -// -// ListOperations lo = cacheUtils.redisTemplate.opsForList(); -// -// if (size > 0 && lo.size(key) >= size) { -// lo.rightPop(key); -// } -// lo.leftPush(key, val); -// } -// -// /** -// * 保存到hash集合中 -// * -// * @param hName 集合名 -// * @param key -// * @param value -// */ -// public static void hashSet(String hName, String key, String value) { -// -// cacheUtils.redisTemplate.opsForHash().put(hName, key, value); -// } -// -// /** -// * 根据key获取所以值 -// * -// * @param key -// * @return -// */ -// public static Map hgetAll(String key) { -// -// return cacheUtils.redisTemplate.opsForHash().entries(key); -// } -// -// /** -// * 保存到hash集合中 -// * -// * @param -// * @param hName 集合名 -// * @param key -// * @param t -// */ -// public static void hashSet(String hName, String key, T t) { -// -// hashSet(hName, key, JSON.toJSONString(t)); -// } -// -// /** -// * 取得复杂JSON数据 -// * -// * @param key -// * @param clazz -// * @param clazz -// * @return -// */ -// public static T getBean(String key, Class clazz) { -// -// String value = cacheUtils.redisTemplate.opsForValue().get(key); -// if (value == null) { -// return null; -// } -// return JSON.parseObject(value, clazz); -// } -// -// /** -// * 从缓存中取得字符串数据 -// * -// * @param key -// * @return 数据 -// */ -// public static String getString(String key) { -// cacheUtils.redisTemplate.opsForValue().get(key); -// -// return cacheUtils.redisTemplate.opsForValue().get(key); -// } -// -// /** -// * 从指定队列里取得数据 -// * @param key -// * @param size -// * @return -// */ -// public static List getFromQueue(String key, long size) { -// -// boolean flag = cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.exists(key.getBytes()); -// }); -// -// if (flag) { -// return new ArrayList<>(); -// } -// ListOperations lo = cacheUtils.redisTemplate.opsForList(); -// if (size > 0) { -// return lo.range(key, 0, size - 1); -// } else { -// return lo.range(key, 0, lo.size(key) - 1); -// } -// } -// -// /** -// * 从指定队列里取得数据 -// * @param key -// * @return -// */ -// public static String popQueue(String key) { -// -// return cacheUtils.redisTemplate.opsForList().rightPop(key); -// -// } -// -// /** -// * 取得序列值的下一个 -// * -// * @param key -// * @return -// */ -// public static Long getSeqNext(String key) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// -// return connection.incr(key.getBytes()); -// -// }); -// } -// -// /** -// * 取得序列值的下一个 -// * -// * @param key -// * @return -// */ -// public static Long getSeqNext(String key, long value) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// -// return connection.incrBy(key.getBytes(), value); -// -// }); -// -// } -// -// /** -// * 将序列值回退一个 -// * -// * @param key -// * @return -// */ -// public static void getSeqBack(String key) { -// -// cacheUtils.redisTemplate.execute((RedisCallback) connection -> connection.decr(key.getBytes())); -// -// } -// -// /** -// * 从hash集合里取得 -// * -// * @param hName -// * @param key -// * @return -// */ -// public static Object hashGet(String hName, String key) { -// -// return cacheUtils.redisTemplate.opsForHash().get(hName, key); -// } -// -// public static T hashGet(String hName, String key, Class clazz) { -// -// return JSON.parseObject((String) hashGet(hName, key), clazz); -// } -// -// /** -// * 增加浮点数的值 -// * -// * @param key -// * @return -// */ -// public static Double incrFloat(String key, double incrBy) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// -// return connection.incrBy(key.getBytes(), incrBy); -// -// }); -// } -// -// /** -// * 判断是否缓存了数据 -// * -// * @param key 数据KEY -// * @return 判断是否缓存了 -// */ -// public static boolean isCached(String key) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.exists(key.getBytes()); -// }); -// } -// -// /** -// * 判断hash集合中是否缓存了数据 -// * -// * @param hName -// * @param key 数据KEY -// * @return 判断是否缓存了 -// */ -// public static boolean hashCached(String hName, String key) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.hExists(key.getBytes(), key.getBytes()); -// }); -// } -// -// /** -// * 判断是否缓存在指定的集合中 -// * -// * @param key 数据KEY -// * @param val 数据 -// * @return 判断是否缓存了 -// */ -// public static boolean isMember(String key, String val) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.sIsMember(key.getBytes(), val.getBytes()); -// }); -// } -// -// /** -// * 从缓存中删除数据 -// * -// * @param key -// * @return -// */ -// public static void delKey(String key) { -// -// cacheUtils.redisTemplate.execute((RedisCallback) connection -> connection.del(key.getBytes())); -// } -// -// /** -// * 设置超时时间 -// * -// * @param key -// * @param seconds -// */ -// public static void expire(String key, int seconds) { -// cacheUtils.redisTemplate -// .execute((RedisCallback) connection -> connection.expire(key.getBytes(), seconds)); -// -// } -// -// /** -// * 列出set中所有成员 -// * -// * @param setName set名 -// * @return -// */ -// public static Set listSet(String setName) { -// -// return cacheUtils.redisTemplate.opsForHash().keys(setName); -// -// } -// -// /** -// * 向set中追加一个值 -// * -// * @param setName set名 -// * @param value -// */ -// public static void setSave(String setName, String value) { -// -// cacheUtils.redisTemplate -// .execute((RedisCallback) connection -> connection.sAdd(setName.getBytes(), value.getBytes())); -// -// } -// -// /** -// * 逆序列出sorted set包括分数的set列表 -// * -// * @param key set名 -// * @param start 开始位置 -// * @param end 结束位置 -// * @return 列表 -// */ -// public static Set listSortedsetRev(String key, int start, int end) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback>) connection -> { -// return connection.zRevRangeWithScores(key.getBytes(), start, end); -// }); -// } -// -// /** -// * 逆序取得sorted sort排名 -// * -// * @param key set名 -// * @param member 成员名 -// * @return 排名 -// */ -// public static Long getRankRev(String key, String member) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.zRevRank(key.getBytes(), member.getBytes()); -// }); -// -// } -// -// /** -// * 根据成员名取得sorted sort分数 -// * -// * @param key set名 -// * @param member 成员名 -// * @return 分数 -// */ -// public static Double getMemberScore(String key, String member) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.zScore(key.getBytes(), member.getBytes()); -// }); -// } -// -// /** -// * 向sorted set中追加一个值 -// * -// * @param key set名 -// * @param score 分数 -// * @param member 成员名称 -// */ -// public static void saveToSortedset(String key, Double score, String member) { -// -// cacheUtils.redisTemplate.execute( -// (RedisCallback) connection -> connection.zAdd(key.getBytes(), score, member.getBytes())); -// } -// -// /** -// * 从sorted set删除一个值 -// * -// * @param key set名 -// * @param member 成员名称 -// */ -// public static void delFromSortedset(String key, String member) { -// cacheUtils.redisTemplate -// .execute((RedisCallback) connection -> connection.zRem(key.getBytes(), member.getBytes())); -// -// } -// -// /** -// * 从hash map中取得复杂JSON数据 -// * -// * @param key -// * @param field -// * @param clazz -// */ -// public static T getBeanFromMap(String key, String field, Class clazz) { -// -// byte[] input = cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.hGet(key.getBytes(), field.getBytes()); -// }); -// return JSON.parseObject(input, clazz, Feature.AutoCloseSource); -// } -// -// /** -// * 从hashmap中删除一个值 -// * -// * @param key map名 -// * @param field 成员名称 -// */ -// public static void delFromMap(String key, String field) { -// -// cacheUtils.redisTemplate -// .execute((RedisCallback) connection -> connection.hDel(key.getBytes(), field.getBytes())); -// -// } -// -// /** -// * @param key -// * @return -// * @Description: 根据key增长 ,计数器 -// * @author clg -// * @date 2016年6月30日 下午2:37:52 -// */ -// public static long incr(String key) { -// -// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { -// return connection.incr(key.getBytes()); -// }); -// } -// -// -// /** -// * 根据key获取当前计数结果 -// * @param key -// * @return -// */ -// public static String getCount(String key) { -// -// return cacheUtils.redisTemplate.opsForValue().get(key); -// } -// -// /** -// * 将所有指定的值插入到存于 key 的列表的头部。如果 key 不存在,那么在进行 push 操作前会创建一个空列表 -// * -// * @param -// * @param key -// * @param value -// * @return -// */ -// public static Long lpush(String key, T value) { -// -// return cacheUtils.redisTemplate.opsForList().leftPush(key, JSON.toJSONString(value)); -// } -// -// /** -// * 只有当 key 已经存在并且存着一个 list 的时候,在这个 key 下面的 list 的头部插入 value。 与 LPUSH 相反,当 key -// * 不存在的时候不会进行任何操作 -// * -// * @param key -// * @param value -// * @return -// */ -// public static Long lpushx(String key, T value) { -// -// return cacheUtils.redisTemplate.opsForList().leftPushIfPresent(key, JSON.toJSONString(value)); -// } -// -// /** -// * 返回存储在 key 里的list的长度。 如果 key 不存在,那么就被看作是空list,并且返回长度为 0 -// * -// * @param key -// * @return -// */ -// public static Long llen(String key) { -// -// return cacheUtils.redisTemplate.opsForList().size(key); -// } -// -// /** -// * 返回存储在 key 的列表里指定范围内的元素。 start 和 end -// * 偏移量都是基于0的下标,即list的第一个元素下标是0(list的表头),第二个元素下标是1,以此类推 -// * -// * @param key -// * @return -// */ -// public static List lrange(String key, long start, long end) { -// -// return cacheUtils.redisTemplate.opsForList().range(key, start, end); -// } -// -// /** -// * 移除并且返回 key 对应的 list 的第一个元素 -// * -// * @param key -// * @return -// */ -// public static String lpop(String key) { -// -// return cacheUtils.redisTemplate.opsForList().leftPop(key); -// } -// -// /** -// * 保存到hash集合中 只在 key 指定的哈希集中不存在指定的字段时,设置字段的值。如果 key 指定的哈希集不存在,会创建一个新的哈希集并与 key -// * 关联。如果字段已存在,该操作无效果。 -// * -// * @param hName 集合名 -// * @param key -// * @param value -// */ -// public static void hsetnx(String hName, String key, String value) { -// -// cacheUtils.redisTemplate.execute((RedisCallback) connection -> connection.hSetNX(key.getBytes(), -// key.getBytes(), value.getBytes())); -// -// } -// -// /** -// * 保存到hash集合中 只在 key 指定的哈希集中不存在指定的字段时,设置字段的值。如果 key 指定的哈希集不存在,会创建一个新的哈希集并与 key -// * 关联。如果字段已存在,该操作无效果。 -// * -// * @param hName 集合名 -// * @param key -// * @param t -// * @param -// */ -// public static void hsetnx(String hName, String key, T t) { -// hsetnx(hName, key, JSON.toJSONString(t)); -// } -// -//} +//package xy.spring2nosql.utils; +// +//import java.util.ArrayList; +//import java.util.List; +//import java.util.Map; +//import java.util.Set; +//import java.util.concurrent.TimeUnit; +// +//import javax.annotation.PostConstruct; +//import javax.annotation.Resource; +// +//import org.springframework.data.redis.connection.RedisZSetCommands; +//import org.springframework.data.redis.core.ListOperations; +//import org.springframework.data.redis.core.RedisCallback; +//import org.springframework.data.redis.core.RedisTemplate; +//import org.springframework.data.redis.core.SetOperations; +//import org.springframework.data.redis.core.ValueOperations; +// +//import com.alibaba.fastjson.JSON; +//import com.alibaba.fastjson.parser.Feature; +// +//public class RedisCacheUtils { +// @Resource +// private RedisTemplate redisTemplate; +// +// private static RedisCacheUtils cacheUtils; +// +// @PostConstruct +// public void init() { +// cacheUtils = this; +// cacheUtils.redisTemplate = this.redisTemplate; +// } +// +// /** +// * 将数据存入缓存 +// * +// * @param key +// * @param val +// * @return +// */ +// public static void saveString(String key, String val) { +// +// ValueOperations vo = cacheUtils.redisTemplate.opsForValue(); +// vo.set(key, val); +// } +// +// /** +// * 将数据存入缓存的集合中 +// * +// * @param key +// * @param val +// * @return +// */ +// public static void saveToSet(String key, String val) { +// +// SetOperations so = cacheUtils.redisTemplate.opsForSet(); +// +// so.add(key, val); +// } +// +// /** +// * key 缓存Key +// * @param key +// * @return +// */ +// public static String getFromSet(String key) { +// return cacheUtils.redisTemplate.opsForSet().pop(key); +// } +// +// /** +// * 将 key的值保存为 value ,当且仅当 key 不存在。 若给定的 key 已经存在,则 SETNX 不做任何动作。 SETNX 是『SET if +// * Not eXists』(如果不存在,则 SET)的简写。
+// * 保存成功,返回 true
+// * 保存失败,返回 false +// */ +// public static boolean saveNX(String key, String val) { +// +// /** 设置成功,返回 1 设置失败,返回 0 **/ +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.setNX(key.getBytes(), val.getBytes()); +// }); +// +// } +// +// /** +// * 将 key的值保存为 value ,当且仅当 key 不存在。 若给定的 key 已经存在,则 SETNX 不做任何动作。 SETNX 是『SET if +// * Not eXists』(如果不存在,则 SET)的简写。
+// * 保存成功,返回 true
+// * 保存失败,返回 false +// * +// * @param key +// * @param val +// * @param expire 超时时间 +// * @return 保存成功,返回 true 否则返回 false +// */ +// public static boolean saveNX(String key, String val, int expire) { +// +// boolean ret = saveNX(key, val); +// if (ret) { +// cacheUtils.redisTemplate.expire(key, expire, TimeUnit.SECONDS); +// } +// return ret; +// } +// +// /** +// * 将数据存入缓存(并设置失效时间) +// * +// * @param key +// * @param val +// * @param seconds +// * @return +// */ +// public static void saveString(String key, String val, int seconds) { +// +// cacheUtils.redisTemplate.opsForValue().set(key, val, seconds, TimeUnit.SECONDS); +// } +// +// /** +// * 将自增变量存入缓存 +// */ +// public static void saveSeq(String key, long seqNo) { +// +// cacheUtils.redisTemplate.delete(key); +// cacheUtils.redisTemplate.opsForValue().increment(key, seqNo); +// } +// +// /** +// * 将递增浮点数存入缓存 +// */ +// public static void saveFloat(String key, float data) { +// +// cacheUtils.redisTemplate.delete(key); +// cacheUtils.redisTemplate.opsForValue().increment(key, data); +// } +// +// /** +// * 保存复杂类型数据到缓存 +// * +// * @param key +// * @param obj +// * @return +// */ +// public static void saveBean(String key, Object obj) { +// +// cacheUtils.redisTemplate.opsForValue().set(key, JSON.toJSONString(obj)); +// } +// +// /** +// * 保存复杂类型数据到缓存(并设置失效时间) +// * +// * @param key +// * @param obj +// * @param seconds +// */ +// public static void saveBean(String key, Object obj, int seconds) { +// +// cacheUtils.redisTemplate.opsForValue().set(key, JSON.toJSONString(obj), seconds, TimeUnit.SECONDS); +// } +// +// /** +// * 存到指定的队列中 +// * @param key +// * @param val +// * @param size +// */ +// public static void saveToQueue(String key, String val, long size) { +// +// ListOperations lo = cacheUtils.redisTemplate.opsForList(); +// +// if (size > 0 && lo.size(key) >= size) { +// lo.rightPop(key); +// } +// lo.leftPush(key, val); +// } +// +// /** +// * 保存到hash集合中 +// * +// * @param hName 集合名 +// * @param key +// * @param value +// */ +// public static void hashSet(String hName, String key, String value) { +// +// cacheUtils.redisTemplate.opsForHash().put(hName, key, value); +// } +// +// /** +// * 根据key获取所以值 +// * +// * @param key +// * @return +// */ +// public static Map hgetAll(String key) { +// +// return cacheUtils.redisTemplate.opsForHash().entries(key); +// } +// +// /** +// * 保存到hash集合中 +// * +// * @param +// * @param hName 集合名 +// * @param key +// * @param t +// */ +// public static void hashSet(String hName, String key, T t) { +// +// hashSet(hName, key, JSON.toJSONString(t)); +// } +// +// /** +// * 取得复杂JSON数据 +// * +// * @param key +// * @param clazz +// * @param clazz +// * @return +// */ +// public static T getBean(String key, Class clazz) { +// +// String value = cacheUtils.redisTemplate.opsForValue().get(key); +// if (value == null) { +// return null; +// } +// return JSON.parseObject(value, clazz); +// } +// +// /** +// * 从缓存中取得字符串数据 +// * +// * @param key +// * @return 数据 +// */ +// public static String getString(String key) { +// cacheUtils.redisTemplate.opsForValue().get(key); +// +// return cacheUtils.redisTemplate.opsForValue().get(key); +// } +// +// /** +// * 从指定队列里取得数据 +// * @param key +// * @param size +// * @return +// */ +// public static List getFromQueue(String key, long size) { +// +// boolean flag = cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.exists(key.getBytes()); +// }); +// +// if (flag) { +// return new ArrayList<>(); +// } +// ListOperations lo = cacheUtils.redisTemplate.opsForList(); +// if (size > 0) { +// return lo.range(key, 0, size - 1); +// } else { +// return lo.range(key, 0, lo.size(key) - 1); +// } +// } +// +// /** +// * 从指定队列里取得数据 +// * @param key +// * @return +// */ +// public static String popQueue(String key) { +// +// return cacheUtils.redisTemplate.opsForList().rightPop(key); +// +// } +// +// /** +// * 取得序列值的下一个 +// * +// * @param key +// * @return +// */ +// public static Long getSeqNext(String key) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// +// return connection.incr(key.getBytes()); +// +// }); +// } +// +// /** +// * 取得序列值的下一个 +// * +// * @param key +// * @return +// */ +// public static Long getSeqNext(String key, long value) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// +// return connection.incrBy(key.getBytes(), value); +// +// }); +// +// } +// +// /** +// * 将序列值回退一个 +// * +// * @param key +// * @return +// */ +// public static void getSeqBack(String key) { +// +// cacheUtils.redisTemplate.execute((RedisCallback) connection -> connection.decr(key.getBytes())); +// +// } +// +// /** +// * 从hash集合里取得 +// * +// * @param hName +// * @param key +// * @return +// */ +// public static Object hashGet(String hName, String key) { +// +// return cacheUtils.redisTemplate.opsForHash().get(hName, key); +// } +// +// public static T hashGet(String hName, String key, Class clazz) { +// +// return JSON.parseObject((String) hashGet(hName, key), clazz); +// } +// +// /** +// * 增加浮点数的值 +// * +// * @param key +// * @return +// */ +// public static Double incrFloat(String key, double incrBy) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// +// return connection.incrBy(key.getBytes(), incrBy); +// +// }); +// } +// +// /** +// * 判断是否缓存了数据 +// * +// * @param key 数据KEY +// * @return 判断是否缓存了 +// */ +// public static boolean isCached(String key) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.exists(key.getBytes()); +// }); +// } +// +// /** +// * 判断hash集合中是否缓存了数据 +// * +// * @param hName +// * @param key 数据KEY +// * @return 判断是否缓存了 +// */ +// public static boolean hashCached(String hName, String key) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.hExists(key.getBytes(), key.getBytes()); +// }); +// } +// +// /** +// * 判断是否缓存在指定的集合中 +// * +// * @param key 数据KEY +// * @param val 数据 +// * @return 判断是否缓存了 +// */ +// public static boolean isMember(String key, String val) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.sIsMember(key.getBytes(), val.getBytes()); +// }); +// } +// +// /** +// * 从缓存中删除数据 +// * +// * @param key +// * @return +// */ +// public static void delKey(String key) { +// +// cacheUtils.redisTemplate.execute((RedisCallback) connection -> connection.del(key.getBytes())); +// } +// +// /** +// * 设置超时时间 +// * +// * @param key +// * @param seconds +// */ +// public static void expire(String key, int seconds) { +// cacheUtils.redisTemplate +// .execute((RedisCallback) connection -> connection.expire(key.getBytes(), seconds)); +// +// } +// +// /** +// * 列出set中所有成员 +// * +// * @param setName set名 +// * @return +// */ +// public static Set listSet(String setName) { +// +// return cacheUtils.redisTemplate.opsForHash().keys(setName); +// +// } +// +// /** +// * 向set中追加一个值 +// * +// * @param setName set名 +// * @param value +// */ +// public static void setSave(String setName, String value) { +// +// cacheUtils.redisTemplate +// .execute((RedisCallback) connection -> connection.sAdd(setName.getBytes(), value.getBytes())); +// +// } +// +// /** +// * 逆序列出sorted set包括分数的set列表 +// * +// * @param key set名 +// * @param start 开始位置 +// * @param end 结束位置 +// * @return 列表 +// */ +// public static Set listSortedsetRev(String key, int start, int end) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback>) connection -> { +// return connection.zRevRangeWithScores(key.getBytes(), start, end); +// }); +// } +// +// /** +// * 逆序取得sorted sort排名 +// * +// * @param key set名 +// * @param member 成员名 +// * @return 排名 +// */ +// public static Long getRankRev(String key, String member) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.zRevRank(key.getBytes(), member.getBytes()); +// }); +// +// } +// +// /** +// * 根据成员名取得sorted sort分数 +// * +// * @param key set名 +// * @param member 成员名 +// * @return 分数 +// */ +// public static Double getMemberScore(String key, String member) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.zScore(key.getBytes(), member.getBytes()); +// }); +// } +// +// /** +// * 向sorted set中追加一个值 +// * +// * @param key set名 +// * @param score 分数 +// * @param member 成员名称 +// */ +// public static void saveToSortedset(String key, Double score, String member) { +// +// cacheUtils.redisTemplate.execute( +// (RedisCallback) connection -> connection.zAdd(key.getBytes(), score, member.getBytes())); +// } +// +// /** +// * 从sorted set删除一个值 +// * +// * @param key set名 +// * @param member 成员名称 +// */ +// public static void delFromSortedset(String key, String member) { +// cacheUtils.redisTemplate +// .execute((RedisCallback) connection -> connection.zRem(key.getBytes(), member.getBytes())); +// +// } +// +// /** +// * 从hash map中取得复杂JSON数据 +// * +// * @param key +// * @param field +// * @param clazz +// */ +// public static T getBeanFromMap(String key, String field, Class clazz) { +// +// byte[] input = cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.hGet(key.getBytes(), field.getBytes()); +// }); +// return JSON.parseObject(input, clazz, Feature.AutoCloseSource); +// } +// +// /** +// * 从hashmap中删除一个值 +// * +// * @param key map名 +// * @param field 成员名称 +// */ +// public static void delFromMap(String key, String field) { +// +// cacheUtils.redisTemplate +// .execute((RedisCallback) connection -> connection.hDel(key.getBytes(), field.getBytes())); +// +// } +// +// /** +// * @param key +// * @return +// * @Description: 根据key增长 ,计数器 +// * @author clg +// * @date 2016年6月30日 下午2:37:52 +// */ +// public static long incr(String key) { +// +// return cacheUtils.redisTemplate.execute((RedisCallback) connection -> { +// return connection.incr(key.getBytes()); +// }); +// } +// +// +// /** +// * 根据key获取当前计数结果 +// * @param key +// * @return +// */ +// public static String getCount(String key) { +// +// return cacheUtils.redisTemplate.opsForValue().get(key); +// } +// +// /** +// * 将所有指定的值插入到存于 key 的列表的头部。如果 key 不存在,那么在进行 push 操作前会创建一个空列表 +// * +// * @param +// * @param key +// * @param value +// * @return +// */ +// public static Long lpush(String key, T value) { +// +// return cacheUtils.redisTemplate.opsForList().leftPush(key, JSON.toJSONString(value)); +// } +// +// /** +// * 只有当 key 已经存在并且存着一个 list 的时候,在这个 key 下面的 list 的头部插入 value。 与 LPUSH 相反,当 key +// * 不存在的时候不会进行任何操作 +// * +// * @param key +// * @param value +// * @return +// */ +// public static Long lpushx(String key, T value) { +// +// return cacheUtils.redisTemplate.opsForList().leftPushIfPresent(key, JSON.toJSONString(value)); +// } +// +// /** +// * 返回存储在 key 里的list的长度。 如果 key 不存在,那么就被看作是空list,并且返回长度为 0 +// * +// * @param key +// * @return +// */ +// public static Long llen(String key) { +// +// return cacheUtils.redisTemplate.opsForList().size(key); +// } +// +// /** +// * 返回存储在 key 的列表里指定范围内的元素。 start 和 end +// * 偏移量都是基于0的下标,即list的第一个元素下标是0(list的表头),第二个元素下标是1,以此类推 +// * +// * @param key +// * @return +// */ +// public static List lrange(String key, long start, long end) { +// +// return cacheUtils.redisTemplate.opsForList().range(key, start, end); +// } +// +// /** +// * 移除并且返回 key 对应的 list 的第一个元素 +// * +// * @param key +// * @return +// */ +// public static String lpop(String key) { +// +// return cacheUtils.redisTemplate.opsForList().leftPop(key); +// } +// +// /** +// * 保存到hash集合中 只在 key 指定的哈希集中不存在指定的字段时,设置字段的值。如果 key 指定的哈希集不存在,会创建一个新的哈希集并与 key +// * 关联。如果字段已存在,该操作无效果。 +// * +// * @param hName 集合名 +// * @param key +// * @param value +// */ +// public static void hsetnx(String hName, String key, String value) { +// +// cacheUtils.redisTemplate.execute((RedisCallback) connection -> connection.hSetNX(key.getBytes(), +// key.getBytes(), value.getBytes())); +// +// } +// +// /** +// * 保存到hash集合中 只在 key 指定的哈希集中不存在指定的字段时,设置字段的值。如果 key 指定的哈希集不存在,会创建一个新的哈希集并与 key +// * 关联。如果字段已存在,该操作无效果。 +// * +// * @param hName 集合名 +// * @param key +// * @param t +// * @param +// */ +// public static void hsetnx(String hName, String key, T t) { +// hsetnx(hName, key, JSON.toJSONString(t)); +// } +// +//} diff --git a/src/main/java/xy/SpringBoot2NoSQL/utils/RedissonUtil.java b/src/main/java/xy/spring2nosql/utils/RedissonUtil.java similarity index 94% rename from src/main/java/xy/SpringBoot2NoSQL/utils/RedissonUtil.java rename to src/main/java/xy/spring2nosql/utils/RedissonUtil.java index 3d490f7..0ea52d8 100644 --- a/src/main/java/xy/SpringBoot2NoSQL/utils/RedissonUtil.java +++ b/src/main/java/xy/spring2nosql/utils/RedissonUtil.java @@ -1,157 +1,157 @@ -package xy.SpringBoot2NoSQL.utils; - -import org.redisson.Redisson; -import org.redisson.api.RAtomicLong; -import org.redisson.api.RBucket; -import org.redisson.api.RCountDownLatch; -import org.redisson.api.RDeque; -import org.redisson.api.RList; -import org.redisson.api.RLock; -import org.redisson.api.RMap; -import org.redisson.api.RQueue; -import org.redisson.api.RSet; -import org.redisson.api.RSortedSet; -import org.redisson.api.RTopic; -import org.redisson.api.RedissonClient; - -/** - * Redisson分布式操作类 - * @author 王昕 - * - */ -public class RedissonUtil { - - /** - * 关闭Redisson客户端连接 - * @param redisson - */ - public static void closeRedisson(RedissonClient redisson){ - redisson.shutdown(); - System.out.println("成功关闭Redis Client连接"); - } - - /** - * 获取字符串对象 - * @param redisson - * @param objectName - * @return - */ - public static RBucket getRBucket(RedissonClient redisson,String objectName){ - RBucket bucket=redisson.getBucket(objectName); - return bucket; - } - - /** - * 获取Map对象 - * @param redisson - * @param objectName - * @return - */ - public static RMap getRMap(RedissonClient redisson,String objectName){ - RMap map=redisson.getMap(objectName); - return map; - } - - /** - * 获取有序集合 - * @param redisson - * @param objectName - * @return - */ - public static RSortedSet getRSortedSet(RedissonClient redisson,String objectName){ - RSortedSet sortedSet=redisson.getSortedSet(objectName); - return sortedSet; - } - - /** - * 获取集合 - * @param redisson - * @param objectName - * @return - */ - public static RSet getRSet(RedissonClient redisson,String objectName){ - RSet rSet=redisson.getSet(objectName); - return rSet; - } - - /** - * 获取列表 - * @param redisson - * @param objectName - * @return - */ - public static RList getRList(RedissonClient redisson,String objectName){ - RList rList=redisson.getList(objectName); - return rList; - } - - /** - * 获取队列 - * @param redisson - * @param objectName - * @return - */ - public static RQueue getRQueue(RedissonClient redisson,String objectName){ - RQueue rQueue=redisson.getQueue(objectName); - return rQueue; - } - - /** - * 获取双端队列 - * @param redisson - * @param objectName - * @return - */ - public static RDeque getRDeque(RedissonClient redisson,String objectName){ - RDeque rDeque=redisson.getDeque(objectName); - return rDeque; - } - - - - /** - * 获取锁 - * @param redisson - * @param objectName - * @return - */ - public static RLock getRLock(RedissonClient redisson,String objectName){ - RLock rLock=redisson.getLock(objectName); - return rLock; - } - - /** - * 获取原子数 - * @param redisson - * @param objectName - * @return - */ - public static RAtomicLong getRAtomicLong(RedissonClient redisson,String objectName){ - RAtomicLong rAtomicLong=redisson.getAtomicLong(objectName); - return rAtomicLong; - } - - /** - * 获取记数锁 - * @param redisson - * @param objectName - * @return - */ - public static RCountDownLatch getRCountDownLatch(RedissonClient redisson,String objectName){ - RCountDownLatch rCountDownLatch=redisson.getCountDownLatch(objectName); - return rCountDownLatch; - } - - /** - * 获取消息的Topic - * @param redisson - * @param objectName - * @return - */ - public static RTopic getRTopic(RedissonClient redisson,String objectName){ - RTopic rTopic=redisson.getTopic(objectName); - return rTopic; - - } - -} +package xy.spring2nosql.utils; + +import org.redisson.Redisson; +import org.redisson.api.RAtomicLong; +import org.redisson.api.RBucket; +import org.redisson.api.RCountDownLatch; +import org.redisson.api.RDeque; +import org.redisson.api.RList; +import org.redisson.api.RLock; +import org.redisson.api.RMap; +import org.redisson.api.RQueue; +import org.redisson.api.RSet; +import org.redisson.api.RSortedSet; +import org.redisson.api.RTopic; +import org.redisson.api.RedissonClient; + +/** + * Redisson分布式操作类 + * @author 王昕 + * + */ +public class RedissonUtil { + + /** + * 关闭Redisson客户端连接 + * @param redisson + */ + public static void closeRedisson(RedissonClient redisson){ + redisson.shutdown(); + System.out.println("成功关闭Redis Client连接"); + } + + /** + * 获取字符串对象 + * @param redisson + * @param objectName + * @return + */ + public static RBucket getRBucket(RedissonClient redisson,String objectName){ + RBucket bucket=redisson.getBucket(objectName); + return bucket; + } + + /** + * 获取Map对象 + * @param redisson + * @param objectName + * @return + */ + public static RMap getRMap(RedissonClient redisson,String objectName){ + RMap map=redisson.getMap(objectName); + return map; + } + + /** + * 获取有序集合 + * @param redisson + * @param objectName + * @return + */ + public static RSortedSet getRSortedSet(RedissonClient redisson,String objectName){ + RSortedSet sortedSet=redisson.getSortedSet(objectName); + return sortedSet; + } + + /** + * 获取集合 + * @param redisson + * @param objectName + * @return + */ + public static RSet getRSet(RedissonClient redisson,String objectName){ + RSet rSet=redisson.getSet(objectName); + return rSet; + } + + /** + * 获取列表 + * @param redisson + * @param objectName + * @return + */ + public static RList getRList(RedissonClient redisson,String objectName){ + RList rList=redisson.getList(objectName); + return rList; + } + + /** + * 获取队列 + * @param redisson + * @param objectName + * @return + */ + public static RQueue getRQueue(RedissonClient redisson,String objectName){ + RQueue rQueue=redisson.getQueue(objectName); + return rQueue; + } + + /** + * 获取双端队列 + * @param redisson + * @param objectName + * @return + */ + public static RDeque getRDeque(RedissonClient redisson,String objectName){ + RDeque rDeque=redisson.getDeque(objectName); + return rDeque; + } + + + + /** + * 获取锁 + * @param redisson + * @param objectName + * @return + */ + public static RLock getRLock(RedissonClient redisson,String objectName){ + RLock rLock=redisson.getLock(objectName); + return rLock; + } + + /** + * 获取原子数 + * @param redisson + * @param objectName + * @return + */ + public static RAtomicLong getRAtomicLong(RedissonClient redisson,String objectName){ + RAtomicLong rAtomicLong=redisson.getAtomicLong(objectName); + return rAtomicLong; + } + + /** + * 获取记数锁 + * @param redisson + * @param objectName + * @return + */ + public static RCountDownLatch getRCountDownLatch(RedissonClient redisson,String objectName){ + RCountDownLatch rCountDownLatch=redisson.getCountDownLatch(objectName); + return rCountDownLatch; + } + + /** + * 获取消息的Topic + * @param redisson + * @param objectName + * @return + */ + public static RTopic getRTopic(RedissonClient redisson,String objectName){ + RTopic rTopic=redisson.getTopic(objectName); + return rTopic; + + } + +}