Permalink
Browse files

add:spring-boot-nutz-dao-starter

  • Loading branch information...
1 parent 911a12c commit 3dfabad67b2d1309f679434f7a1d8d9e5c8e9a8e 王贵源 committed Jan 11, 2017
Showing with 678 additions and 68 deletions.
  1. +67 −68 nutz-plugins-mock/src/main/java/org/nutz/mock/AbstractMvcTest.java
  2. +32 −0 nutz-plugins-spring-boot-starter/demo/pom.xml
  3. +51 −0 nutz-plugins-spring-boot-starter/demo/src/main/java/demo/App.java
  4. +60 −0 nutz-plugins-spring-boot-starter/demo/src/main/java/demo/bean/User.java
  5. +7 −0 nutz-plugins-spring-boot-starter/demo/src/main/java/demo/bean/package-info.java
  6. +7 −0 nutz-plugins-spring-boot-starter/demo/src/main/java/demo/package-info.java
  7. +34 −0 nutz-plugins-spring-boot-starter/demo/src/main/resources/application.yml
  8. +60 −0 nutz-plugins-spring-boot-starter/demo/src/main/resources/sqls/acl/permission.sql
  9. +30 −0 nutz-plugins-spring-boot-starter/demo/src/main/resources/sqls/acl/role.sql
  10. +11 −0 nutz-plugins-spring-boot-starter/demo/src/main/resources/sqls/acl/user.sql
  11. +51 −0 nutz-plugins-spring-boot-starter/demo/src/main/resources/sqls/branch/branch.sql
  12. +47 −0 nutz-plugins-spring-boot-starter/pom.xml
  13. +51 −0 ...pring-boot-starter/src/main/java/org/nutz/plugin/spring/boot/FileSqlManagerAutoConfiguration.java
  14. +34 −0 ...ugins-spring-boot-starter/src/main/java/org/nutz/plugin/spring/boot/NutzDaoAutoConfiguration.java
  15. +38 −0 ...pring-boot-starter/src/main/java/org/nutz/plugin/spring/boot/config/NutzDaoRuntimeProperties.java
  16. +18 −0 ...ns-spring-boot-starter/src/main/java/org/nutz/plugin/spring/boot/config/SqlManagerProperties.java
  17. +7 −0 nutz-plugins-spring-boot-starter/src/main/java/org/nutz/plugin/spring/boot/config/package-info.java
  18. +54 −0 ...s-spring-boot-starter/src/main/java/org/nutz/plugin/spring/boot/listener/NutzDataBaseaMender.java
  19. +7 −0 ...-plugins-spring-boot-starter/src/main/java/org/nutz/plugin/spring/boot/listener/package-info.java
  20. +7 −0 nutz-plugins-spring-boot-starter/src/main/java/org/nutz/plugin/spring/boot/package-info.java
  21. +3 −0 nutz-plugins-spring-boot-starter/src/main/resources/META-INF/spring.factories
  22. +1 −0 nutz-plugins-spring-boot-starter/src/main/resources/META-INF/spring.provides
  23. +1 −0 pom.xml
@@ -1,68 +1,67 @@
-package org.nutz.mock;
-
-import javax.servlet.Servlet;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.nutz.mock.servlet.MockHttpServletRequest;
-import org.nutz.mock.servlet.MockHttpServletResponse;
-import org.nutz.mock.servlet.MockHttpSession;
-import org.nutz.mock.servlet.MockServletConfig;
-import org.nutz.mock.servlet.MockServletContext;
-import org.nutz.mvc.Mvcs;
-import org.nutz.mvc.NutConfig;
-import org.nutz.mvc.NutServlet;
-
-@Ignore
-@SuppressWarnings("deprecation")
-public abstract class AbstractMvcTest extends NutIocTestBase {
-
- protected Servlet servlet;
-
- protected MockHttpServletRequest request;
-
- protected MockHttpServletResponse response;
-
- protected MockHttpSession session;
-
- protected MockServletContext servletContext;
-
- protected MockServletConfig servletConfig;
-
- protected NutConfig nc;
-
- @Override
- @Before
- public void before() throws Exception {
- servletContext = Mock.servlet.context();
- servletConfig = new MockServletConfig(servletContext, "nutz");
- initServletConfig();
- servlet = new NutServlet();
- servlet.init(servletConfig);
- session = Mock.servlet.session(servletContext);
- newreq();
- nc = Mvcs.getNutConfig();
- ioc = nc.getIoc();
- injectSelfFields();
- _before();
- }
-
- protected void newreq() {
- request = Mock.servlet.request().setSession(session);
- request.setContextPath("");
- request.setSession(session);
- response = new MockHttpServletResponse();
- }
-
- protected abstract void initServletConfig();
-
- @Override
- @After
- public void after() throws Exception {
- _after();
- if (servlet != null)
- servlet.destroy();
- }
-
-}
+package org.nutz.mock;
+
+import javax.servlet.Servlet;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.nutz.mock.servlet.MockHttpServletRequest;
+import org.nutz.mock.servlet.MockHttpServletResponse;
+import org.nutz.mock.servlet.MockHttpSession;
+import org.nutz.mock.servlet.MockServletConfig;
+import org.nutz.mock.servlet.MockServletContext;
+import org.nutz.mvc.Mvcs;
+import org.nutz.mvc.NutConfig;
+import org.nutz.mvc.NutServlet;
+
+@Ignore
+public abstract class AbstractMvcTest extends NutIocTestBase {
+
+ protected Servlet servlet;
+
+ protected MockHttpServletRequest request;
+
+ protected MockHttpServletResponse response;
+
+ protected MockHttpSession session;
+
+ protected MockServletContext servletContext;
+
+ protected MockServletConfig servletConfig;
+
+ protected NutConfig nc;
+
+ @Override
+ @Before
+ public void before() throws Exception {
+ servletContext = Mock.servlet.context();
+ servletConfig = new MockServletConfig(servletContext, "nutz");
+ initServletConfig();
+ servlet = new NutServlet();
+ servlet.init(servletConfig);
+ session = Mock.servlet.session(servletContext);
+ newreq();
+ nc = Mvcs.getNutConfig();
+ ioc = nc.getIoc();
+ injectSelfFields();
+ _before();
+ }
+
+ protected void newreq() {
+ request = Mock.servlet.request().setSession(session);
+ request.setContextPath("");
+ request.setSession(session);
+ response = new MockHttpServletResponse();
+ }
+
+ protected abstract void initServletConfig();
+
+ @Override
+ @After
+ public void after() throws Exception {
+ _after();
+ if (servlet != null)
+ servlet.destroy();
+ }
+
+}
@@ -0,0 +1,32 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>club.zhcs</groupId>
+ <artifactId>sb-nutz-starter-demo</artifactId>
+ <version>1.0</version>
+ <parent>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-parent</artifactId>
+ <version>1.4.3.RELEASE</version>
+ </parent>
+ <build />
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.nutz</groupId>
+ <artifactId>nutz-plugins-spring-boot-starter</artifactId>
+ <version>1.r.60-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>druid</artifactId>
+ <version>1.0.27</version>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,51 @@
+package demo;
+
+import org.nutz.dao.Dao;
+import org.nutz.plugin.spring.boot.config.SqlManagerProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import demo.bean.User;
+
+@SpringBootApplication
+@EnableAutoConfiguration
+@EnableConfigurationProperties(SqlManagerProperties.class)
+@RestController
+public class App {
+
+ @RequestMapping("/")
+ public SqlManagerProperties hello() {
+ return sqlManagerProperties;
+ }
+
+ @RequestMapping("/dao")
+ public Object dao() {
+ return dao.meta();
+ }
+
+ @RequestMapping("/sqls")
+ public Object sqls() {
+ return dao.sqls().keys();
+ }
+
+ @RequestMapping("/count")
+ public int count() {
+ return dao.count(User.class);
+ }
+
+ @Autowired
+ private SqlManagerProperties sqlManagerProperties;
+
+ @Autowired
+ Dao dao;
+
+ public static void main(String[] args) {
+ SpringApplication application = new SpringApplication(App.class);
+ application.run(args);
+ }
+}
@@ -0,0 +1,60 @@
+package demo.bean;
+
+import java.util.Date;
+
+import org.nutz.dao.entity.annotation.Column;
+import org.nutz.dao.entity.annotation.Id;
+import org.nutz.dao.entity.annotation.Table;
+
+@Table("t_user")
+public class User {
+
+ @Id
+ private int id;
+
+ @Column("u_name")
+ private String name;
+
+ @Column("u_birth")
+ private Date brithDay;
+
+ @Column("u_sex")
+ private Sex sex;
+
+ public static enum Sex {
+ MALE, FEMALE
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Date getBrithDay() {
+ return brithDay;
+ }
+
+ public void setBrithDay(Date brithDay) {
+ this.brithDay = brithDay;
+ }
+
+ public Sex getSex() {
+ return sex;
+ }
+
+ public void setSex(Sex sex) {
+ this.sex = sex;
+ }
+
+}
@@ -0,0 +1,7 @@
+/**
+ * @author guiyuan.wang-N
+ *
+ * createTime 2017年1月11日下午3:13:50
+ *
+ */
+package demo.bean;
@@ -0,0 +1,7 @@
+/**
+ * @author guiyuan.wang-N
+ *
+ * createTime 2017年1月11日下午1:19:52
+ *
+ */
+package demo;
@@ -0,0 +1,34 @@
+spring:
+ datasource:
+ name: test
+ url: jdbc:h2:~/.h2db/nutz-starter;MODE=MYSQL
+ #url: jdbc:mysql://127.0.0.1:3306/camunda?useUnicode=true&characterEncoding=utf-8&useSSL=false
+ username: root
+ password: 123456
+ # 使用druid数据源
+ type: com.alibaba.druid.pool.DruidDataSource
+ driver-class-name: org.h2.Driver
+ #driver-class-name: com.mysql.jdbc.Driver
+ filters: stat,wall,log4j
+ connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
+ maxActive: 20
+ initialSize: 1
+ maxWait: 60000
+ minIdle: 1
+ timeBetweenEvictionRunsMillis: 60000
+ minEvictableIdleTimeMillis: 300000
+ validationQuery: select 'x'
+ testWhileIdle: true
+ testOnBorrow: false
+ testOnReturn: false
+ poolPreparedStatements: true
+ maxOpenPreparedStatements: 20
+ jackson:
+ date-format: yyyy-MM-dd HH:mm:ss
+
+nutz:
+ dao:
+ runtime:
+ create: true
+ migration: true
+ basepackage: demo
@@ -0,0 +1,60 @@
+/*
+list.direct.permission.by.user.id
+*/
+SELECT
+ *
+FROM
+ t_permission p
+LEFT JOIN t_user_permission up ON p.id = up.p_id
+WHERE
+ up.u_id = @userId
+/*
+list.indirect.permission.by.user.id
+*/
+SELECT
+ p.*
+FROM
+ t_permission p
+LEFT JOIN t_role_permission rp ON p.id = rp.p_id
+LEFT JOIN t_user_role ur ON ur.r_id = rp.r_id
+WHERE ur.u_id = @userId
+/*
+find.permissions.with.user.powered.info.by.user.id
+*/
+SELECT
+ p.*, CASE sup.id IS NULL
+WHEN 1 THEN
+ ''
+ELSE
+ 'selected'
+END AS has_permission
+FROM
+ t_permission p
+LEFT JOIN (
+ SELECT
+ *
+ FROM
+ t_user_permission
+ WHERE
+ u_id = @id
+) sup ON p.id = sup.p_id
+/*
+find.permissions.with.role.powered.info.by.role.id
+*/
+SELECT
+ p.*, CASE srp.id IS NULL
+WHEN 1 THEN
+ ''
+ELSE
+ 'selected'
+END AS hasr_permission
+FROM
+ t_permission p
+LEFT JOIN (
+ SELECT
+ *
+ FROM
+ t_role_permission
+ WHERE
+ r_id =@id
+) srp ON p.id = srp.p_id
Oops, something went wrong.

0 comments on commit 3dfabad

Please sign in to comment.