├── .gitignore ├── LICENSE ├── README.md ├── bin ├── README.md ├── eclipse.bat ├── idea.bat ├── install.bat └── myeclipse.bat ├── dactiv-common ├── bin │ ├── README.md │ ├── eclipse.bat │ ├── idea.bat │ ├── install.bat │ └── myeclipse.bat ├── pom.xml └── src │ ├── main │ └── java │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ └── com │ │ └── github │ │ └── dactiv │ │ └── common │ │ ├── bundle │ │ ├── BeanResourceBundle.java │ │ └── JacksonBundle.java │ │ ├── spring │ │ ├── SpringContextHolder.java │ │ ├── mail │ │ │ └── JavaMailService.java │ │ └── mvc │ │ │ └── SpringMvcHolder.java │ │ ├── type │ │ └── FieldType.java │ │ ├── unit │ │ ├── Fixtures.java │ │ ├── JettyFactory.java │ │ └── selenium │ │ │ ├── Selenium2.java │ │ │ └── WebDriverFactory.java │ │ └── utils │ │ ├── CaptchaUtils.java │ │ ├── CollectionUtils.java │ │ ├── ConvertUtils.java │ │ ├── CryptoUtils.java │ │ ├── EncodeUtils.java │ │ ├── ExceptionUtils.java │ │ ├── JaxWsFactoryUtils.java │ │ ├── PropertiesUtils.java │ │ ├── ReflectionUtils.java │ │ └── ServletUtils.java │ └── test │ ├── java │ └── com │ │ └── github │ │ └── dactiv │ │ └── common │ │ └── test │ │ ├── bundle │ │ ├── TestBeanResourceBundle.java │ │ └── TestJacksonBundle.java │ │ ├── entity │ │ ├── Group.java │ │ ├── UniversallyUniqueIdentifier.java │ │ └── User.java │ │ └── utils │ │ ├── TestJaxWsFactoryUtils.java │ │ └── TestReflectionUtils.java │ └── resources │ └── logback.xml ├── dactiv-orm ├── bin │ ├── README.md │ ├── eclipse.bat │ ├── idea.bat │ ├── install.bat │ └── myeclipse.bat ├── pom.xml └── src │ ├── main │ └── java │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ └── com │ │ └── github │ │ └── dactiv │ │ └── orm │ │ ├── annotation │ │ └── StateDelete.java │ │ └── core │ │ ├── MatchValue.java │ │ ├── Page.java │ │ ├── PageRequest.java │ │ ├── PropertyFilter.java │ │ ├── PropertyFilters.java │ │ ├── RestrictionNames.java │ │ ├── hibernate │ │ ├── CriterionBuilder.java │ │ ├── HibernateRestrictionBuilder.java │ │ ├── restriction │ │ │ ├── CriterionMultipleValueSupport.java │ │ │ ├── CriterionSingleValueSupport.java │ │ │ └── support │ │ │ │ ├── EqRestriction.java │ │ │ │ ├── GeRestriction.java │ │ │ │ ├── GtRestriction.java │ │ │ │ ├── InRestriction.java │ │ │ │ ├── LLikeRestriction.java │ │ │ │ ├── LeRestriction.java │ │ │ │ ├── LikeRestriction.java │ │ │ │ ├── LtRestriction.java │ │ │ │ ├── NeRestriction.java │ │ │ │ ├── NinRestriction.java │ │ │ │ └── RLikeRestriction.java │ │ └── support │ │ │ ├── BasicHibernateDao.java │ │ │ └── HibernateSupportDao.java │ │ └── spring │ │ └── data │ │ └── jpa │ │ ├── JpaRestrictionBuilder.java │ │ ├── PredicateBuilder.java │ │ ├── factory │ │ ├── BasicJpaRepositoryFactory.java │ │ └── BasicRepositoryFactoryBean.java │ │ ├── repository │ │ ├── BasicJpaRepository.java │ │ └── support │ │ │ └── JpaSupportRepository.java │ │ ├── restriction │ │ ├── PredicateMultipleValueSupport.java │ │ ├── PredicateSingleValueSupport.java │ │ └── support │ │ │ ├── EqRestriction.java │ │ │ ├── GeRestriction.java │ │ │ ├── GtRestriction.java │ │ │ ├── InRestriction.java │ │ │ ├── LLikeRestriction.java │ │ │ ├── LeRestriction.java │ │ │ ├── LikeRestriction.java │ │ │ ├── LtRestriction.java │ │ │ ├── NeRestriction.java │ │ │ ├── NinRestriction.java │ │ │ └── RLikeRestriction.java │ │ └── specification │ │ ├── SpecificationEntity.java │ │ ├── Specifications.java │ │ └── support │ │ ├── PropertyFilterSpecification.java │ │ └── PropertySpecification.java │ └── test │ ├── java │ └── com │ │ └── github │ │ └── dactiv │ │ └── orm │ │ └── test │ │ ├── CreateTestInitializeDataBaseSqlFile.java │ │ ├── entity │ │ ├── Menu.java │ │ ├── Role.java │ │ ├── UniversallyUniqueIdentifier.java │ │ └── User.java │ │ ├── hibernate │ │ ├── TestBasicHibernateDao.java │ │ └── TestHibernateSupportDao.java │ │ ├── jpa │ │ └── TestJpaSupportRepository.java │ │ └── simple │ │ ├── hibernate │ │ ├── BasicHiberanteDaoSimple.java │ │ └── HibernateDaoSimple.java │ │ └── jpa │ │ └── UserRepository.java │ └── resources │ ├── applicationContext-test.xml │ ├── h2schma.sql │ ├── hibernate.cfg.xml │ ├── logback.xml │ └── sample-data.xml ├── dactiv-parent ├── README.md ├── install.bat └── pom.xml ├── doc ├── md │ ├── common 使用说明.md │ ├── orm 使用说明.md │ ├── shrio 实用功能说明.md │ └── spring mvc 实用功能说明.md └── reference.md ├── pom.xml ├── quick-start.bat └── showcase └── base-curd ├── .gitignore ├── bin ├── README.md ├── archetype-generate.bat ├── eclipse.bat ├── idea.bat ├── install.bat ├── jetty.bat ├── myeclipse.bat ├── reset-db.bat └── war.bat ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── github │ │ └── dactiv │ │ └── showcase │ │ ├── common │ │ ├── SessionVariable.java │ │ ├── SystemVariableUtils.java │ │ ├── annotation │ │ │ └── OperatingAudit.java │ │ └── enumeration │ │ │ ├── SystemDictionaryCode.java │ │ │ ├── ValueEnum.java │ │ │ └── entity │ │ │ ├── GroupType.java │ │ │ ├── OperatingState.java │ │ │ ├── ResourceType.java │ │ │ └── State.java │ │ ├── dao │ │ ├── account │ │ │ ├── GroupDao.java │ │ │ ├── ResourceDao.java │ │ │ └── UserDao.java │ │ └── foundation │ │ │ ├── audit │ │ │ └── OperatingRecordDao.java │ │ │ └── variable │ │ │ ├── DataDictionaryDao.java │ │ │ └── DictionaryCategoryDao.java │ │ ├── entity │ │ ├── IdEntity.java │ │ ├── account │ │ │ ├── Group.java │ │ │ ├── Resource.java │ │ │ └── User.java │ │ └── foundation │ │ │ ├── audit │ │ │ └── OperatingRecord.java │ │ │ └── variable │ │ │ ├── DataDictionary.java │ │ │ └── DictionaryCategory.java │ │ ├── service │ │ ├── ServiceException.java │ │ ├── account │ │ │ ├── AccountManager.java │ │ │ ├── AuthorizationRealm.java │ │ │ ├── CaptchaAuthenticationFilter.java │ │ │ ├── ChainDefinitionSectionMetaSource.java │ │ │ └── JdbcAuthenticationRealm.java │ │ └── foundation │ │ │ ├── OperatingRecordAspect.java │ │ │ ├── SystemAuditManager.java │ │ │ └── SystemVariableManager.java │ │ └── web │ │ ├── SystemCommonController.java │ │ ├── account │ │ ├── GroupController.java │ │ ├── ResourceController.java │ │ └── UserController.java │ │ └── foundation │ │ ├── audit │ │ └── OperatingRecordController.java │ │ └── variable │ │ ├── DataDictionaryController.java │ │ └── DictionaryCategoryController.java ├── resources │ ├── application.properties │ ├── applicationContext-core.xml │ ├── applicationContext-mail.xml │ ├── applicationContext-mvc.xml │ ├── applicationContext-shiro.xml │ ├── ehcache.xml │ ├── email │ │ └── operating-mail-template.ftl │ ├── logback.xml │ └── sql │ │ ├── h2.sql │ │ └── mysql.sql └── webapp │ ├── META-INF │ └── MANIFEST.MF │ ├── WEB-INF │ ├── error-page │ │ ├── 404.jsp │ │ └── 500.jsp │ ├── page │ │ ├── account │ │ │ ├── group │ │ │ │ ├── read.html │ │ │ │ └── view.html │ │ │ ├── resource │ │ │ │ ├── read.html │ │ │ │ └── view.html │ │ │ └── user │ │ │ │ ├── create.html │ │ │ │ ├── read.html │ │ │ │ └── view.html │ │ ├── basic │ │ │ ├── default.html │ │ │ ├── info.html │ │ │ ├── navbar.html │ │ │ └── profile-setting.html │ │ ├── exception │ │ │ ├── defaule-error.html │ │ │ └── unauthorized.html │ │ ├── foundation │ │ │ ├── audit │ │ │ │ └── operating-record │ │ │ │ │ ├── read.html │ │ │ │ │ └── view.html │ │ │ └── variable │ │ │ │ ├── data-dictionary │ │ │ │ ├── read.html │ │ │ │ └── view.html │ │ │ │ └── dictionary-category │ │ │ │ ├── read.html │ │ │ │ └── view.html │ │ ├── index.html │ │ └── login.html │ ├── taglib │ │ └── shiro.tld │ └── web.xml │ └── resource │ ├── css │ ├── bootstrap-theme.css │ ├── bootstrap.min.css │ └── layout.min.css │ ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff │ ├── image │ ├── bg.png │ ├── book-cover.png │ ├── empty.png │ ├── grids.png │ ├── header-bg.png │ ├── ie.png │ ├── portrait.png │ └── ribbon.png │ ├── script │ ├── bootstrap.min.js │ ├── default.config.min.js │ ├── jquery-1.10.2.min.js │ ├── jquery.extends.min.js │ ├── jquery.form.min.js │ ├── jquery.validate.min.js │ └── respond.min.js │ └── swf │ └── FaustCplus.swf └── test ├── java └── com │ └── github │ └── dactiv │ └── showcase │ └── test │ ├── CreateDataBaseTableByHibernateConfigFile.java │ ├── LaunchJetty.java │ ├── founction │ ├── FunctionTestCaseSupport.java │ ├── account │ │ ├── TestGroupManagerFunction.java │ │ ├── TestResourceManagerFunction.java │ │ └── TestUserManagerFunction.java │ └── foundation │ │ └── variable │ │ ├── TestDataDictonaryManagerFunction.java │ │ └── TestDictionaryCategoryManagerFunction.java │ └── manager │ ├── ManagerTestCaseSupport.java │ ├── account │ ├── TestGroupManager.java │ ├── TestResourceManager.java │ └── TestUserManager.java │ └── foundation │ ├── audit │ └── TestOperatingRecordManager.java │ └── variable │ ├── TestDataDictionaryManager.java │ └── TestDictionaryCategoryManager.java └── resources ├── application.test.properties ├── data └── h2 │ ├── cleanup-data.sql │ ├── create-table.sql │ └── insert-data.sql └── hibernate.cfg.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/ 2 | .project 3 | .classpath 4 | 5 | */logs/ 6 | */target/ 7 | */.settings/ 8 | */.project 9 | */.classpath 10 | */.springBeans 11 | 12 | 13 | /showcase/*/logs/* 14 | /showcase/*/target/* 15 | /showcase/*/.settings/ 16 | /showcase/*/.project 17 | /showcase/*/.classpath 18 | /showcase/*/.springBeans 19 | 20 | *.class 21 | *.jar 22 | *.war 23 | *.ear -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ###框架说明 2 | 3 | 4 | base-framework是对常用的java web开发封装实用功能来提高开发效率的底层框架。base-framework基于spring做核心框架、hibernate或spring data jpa做持久化框架,用spring mvc框架对mvc做管理。使用到的新功能有spring缓存工厂、apeche shiro安全框架、spring mvc,spring data jpa等主要流行技术, 该项目分为两个部分做底层的封装,和带有一个项目演示例子。 5 | 6 | [相关帮助文档](https://github.com/dactiv/base-framework/wiki) 7 | 8 | #### 初始化工作: 9 | 10 | *** 11 | 12 | ##### 配置maven 13 | 14 | 1. 下载[maven](http://maven.apache.org/download.html) 15 | 1. 解压maven-[版本]-bin.zip到你想安装的位置 16 | 1. 设置maven系统环境变量,M2_HOME=[maven安装目录位置] 17 | 1. 添加maven bin目录至系统环境变量PATH中, %M2_HOME%\bin 18 | 1. 确认Maven的安装:cmd > mvn -version 19 | 20 | ##### 安装base-framework到maven中 21 | 22 | 1. 使用git或者svn下载base-framework 23 | 24 | *** 25 | git地址:git://github.com/dactiv/base-framework.git 26 | svn地址:https://github.com/dactiv/base-framework.git 27 | *** 28 | 29 | 1. 点击根目录下的quick-start.bat文件进行安装,当看见以下信息时表示安装成功: 30 | 31 | *** 32 | [INFO] ------------------------------------------------------------------------ 33 | [INFO] BUILD SUCCESS 34 | [INFO] ------------------------------------------------------------------------ 35 | [INFO] Total time: 6.147s 36 | [INFO] Finished at: Mon Oct 07 10:59:23 CST 2013 37 | [INFO] Final Memory: 9M/156M 38 | [INFO] ------------------------------------------------------------------------ 39 | [INFO] start basic curd app 40 | [INFO] Please wait a moment. When you see "[INFO] Started Jetty Server", you can visit: http://localhost:8080/base-curd/ to view the demo 41 | *** 42 | 43 | 你可以通过http://localhost:8080/base-curd/来访问项目 44 | 45 | 该安装过程会将base-framework中的dactiv-common和dactiv-orm生成jar包放入maven的.m2文件夹中(当然,这两个框架使用到的依赖jar包也会下载到.m2文件夹中).同时也会初始化h2数据库和启动jetty,让执行完成后直接访问。 46 | 47 | ##### dactiv common 简单说明 48 | 49 | 该jar包是对基本的常用工具类的一些简单封装。如泛型,反射,配置文件等工具类的封装。 50 | 51 | ##### dactiv orm 简单说明 52 | 53 | 该jar包是对持久化层的框架封装,目前只对Hibernate4和spring data jpa的curd和辅助查询功能封装。 54 | 55 | ##### 项目功能演示例子 56 | 57 | 在文件夹的shorcase里有一个base-curd项目。该项目是对以上两个框架(dactiv-common和dactiv-orm)和其他技术的整合做的例子,通过该例子使用maven做了一个archetype基础模板。可以通过该archetype来生成一个新的项目。该文件在base-curd\bin下面(archetype-generate.bat)。 58 | 59 | 通过base-curd项目文件夹中的bin/jetty.bat文件运行项目,也可以用eclipse.bat生成项目导入到开发工具中在运行。该工程下有一个基于jeety运行的java文件org.dactiv.showcase.test.LaunchJetty.你也可以通过该文件运行整个项目. 60 | 61 | ##### 导入eclipse或者myeclipse 62 | 在根目录下的bin目录有一个eclipse.bat和myeclipse.bat,点击eclipse.bat/myeclipse.bat会生成project,看见以下信息表示生成成功,可以直接导入eclipse/myclipse 63 | 64 | *** 65 | [INFO] ------------------------------------------------------------------------ 66 | [INFO] Reactor Summary: 67 | [INFO] 68 | [INFO] dactiv parent pom................................... SUCCESS [0.552s] 69 | [INFO] dactiv common jar ............................... SUCCESS [2:21.572s] 70 | [INFO] dactiv orm jar .................................. SUCCESS [6.828s] 71 | [INFO] base curd project war ................................ SUCCESS [1:07.878s] 72 | [INFO] base web framework project ........................ SUCCESS [0.644s] 73 | [INFO] ------------------------------------------------------------------------ 74 | [INFO] BUILD SUCCESS 75 | [INFO] ------------------------------------------------------------------------ 76 | [INFO] Total time: 3:39.025s 77 | [INFO] Finished at: Wed Dec 04 14:50:14 CST 2013 78 | [INFO] Final Memory: 10M/25M 79 | [INFO] ------------------------------------------------------------------------ 80 | *** 81 | 82 | 注意:过于旧版本的的eclipse和myeclipse在导入项目时如果发现有错,请检查工具是否已经配置了maven的仓库路径.具体查看在工具的:window->preferences,然后进入到Java->Build Path->Classpath Variables查看左边是否存在M2_REPO,如果不存在,点击New按钮,Name:M2_REPO,Path:你仓库的位置.如:C:\Users\feng\.m2\repository 83 | -------------------------------------------------------------------------------- /bin/README.md: -------------------------------------------------------------------------------- 1 | ###工具说明 2 | 3 | eclipse:将项目生成为eclipse项目 4 | 5 | idea:将项目生成为idea项目 6 | 7 | myeclipse:将项目生成为myeclipse项目 8 | 9 | install:将该项目所有的依赖初始化到本地m2库 10 | 11 | -------------------------------------------------------------------------------- /bin/eclipse.bat: -------------------------------------------------------------------------------- 1 | 2 | @echo off 3 | echo [INFO] create project to eclipse 4 | 5 | cd %~dp0 6 | cd .. 7 | call mvn clean eclipse:eclipse 8 | cd bin 9 | pause 10 | -------------------------------------------------------------------------------- /bin/idea.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] create project to idea 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn clean idea:idea 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /bin/install.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] Install jar to local repository. 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn clean source:jar install -Dmaven.test.skip=true 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /bin/myeclipse.bat: -------------------------------------------------------------------------------- 1 | 2 | @echo off 3 | echo [INFO] create project to myeclipse 4 | 5 | cd %~dp0 6 | cd .. 7 | call mvn clean eclipse:myeclipse 8 | cd bin 9 | pause 10 | -------------------------------------------------------------------------------- /dactiv-common/bin/README.md: -------------------------------------------------------------------------------- 1 | ###工具说明 2 | 3 | eclipse:将项目生成为eclipse项目 4 | 5 | idea:将项目生成为idea项目 6 | 7 | myeclipse:将项目生成为myeclipse项目 8 | 9 | install:将该项目所有的依赖初始化到本地m2库 10 | 11 | -------------------------------------------------------------------------------- /dactiv-common/bin/eclipse.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] create a project. 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn eclipse:eclipse 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /dactiv-common/bin/idea.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] create project to idea 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn clean idea:idea 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /dactiv-common/bin/install.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] Install jar to local repository. 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn clean source:jar install -Dmaven.test.skip=true 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /dactiv-common/bin/myeclipse.bat: -------------------------------------------------------------------------------- 1 | 2 | @echo off 3 | echo [INFO] create project to myeclipse 4 | 5 | cd %~dp0 6 | cd .. 7 | call mvn eclipse:myeclipse 8 | cd bin 9 | pause 10 | -------------------------------------------------------------------------------- /dactiv-common/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /dactiv-common/src/main/java/com/github/dactiv/common/spring/SpringContextHolder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2005-2012 springside.org.cn 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | */ 6 | package com.github.dactiv.common.spring; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.DisposableBean; 11 | import org.springframework.context.ApplicationContext; 12 | import org.springframework.context.ApplicationContextAware; 13 | import org.springframework.util.Assert; 14 | 15 | /** 16 | * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候取出ApplicaitonContext. 17 | * 18 | * @author calvin 19 | */ 20 | public class SpringContextHolder implements ApplicationContextAware, DisposableBean { 21 | 22 | private static ApplicationContext applicationContext = null; 23 | 24 | private static Logger logger = LoggerFactory.getLogger(SpringContextHolder.class); 25 | 26 | /** 27 | * 取得存储在静态变量中的ApplicationContext. 28 | * 29 | * @return {@link ApplicationContext} 30 | */ 31 | public static ApplicationContext getApplicationContext() { 32 | assertContextInjected(); 33 | return applicationContext; 34 | } 35 | 36 | /** 37 | * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. 38 | * 39 | */ 40 | @SuppressWarnings("unchecked") 41 | public static T getBean(String name) { 42 | assertContextInjected(); 43 | return (T) applicationContext.getBean(name); 44 | } 45 | 46 | /** 47 | * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. 48 | */ 49 | public static T getBean(Class requiredType) { 50 | assertContextInjected(); 51 | return applicationContext.getBean(requiredType); 52 | } 53 | 54 | /** 55 | * 清除SpringContextHolder中的ApplicationContext为Null. 56 | */ 57 | public static void clearHolder() { 58 | logger.debug("清除SpringContextHolder中的ApplicationContext:" + applicationContext); 59 | applicationContext = null; 60 | } 61 | 62 | /** 63 | * 实现ApplicationContextAware接口, 注入Context到静态变量中. 64 | * 65 | * @param applicationContext 66 | */ 67 | public void setApplicationContext(ApplicationContext applicationContext) { 68 | logger.debug("注入ApplicationContext到SpringContextHolder:" + applicationContext); 69 | 70 | if (SpringContextHolder.applicationContext != null) { 71 | logger.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:" 72 | + SpringContextHolder.applicationContext); 73 | } 74 | 75 | SpringContextHolder.applicationContext = applicationContext; //NOSONAR 76 | } 77 | 78 | /** 79 | * 实现DisposableBean接口, 在Context关闭时清理静态变量. 80 | */ 81 | public void destroy() throws Exception { 82 | SpringContextHolder.clearHolder(); 83 | } 84 | 85 | /** 86 | * 检查ApplicationContext不为空. 87 | */ 88 | private static void assertContextInjected() { 89 | Assert.state(applicationContext != null,"applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder."); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /dactiv-common/src/main/java/com/github/dactiv/common/type/FieldType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2005-2012 springside.org.cn 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | */ 6 | package com.github.dactiv.common.type; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * 属性数据类型 12 | * S代表String,I代表Integer,L代表Long, N代表Double, D代表Date,B代表Boolean 13 | * 14 | * @author calvin 15 | * 16 | */ 17 | public enum FieldType { 18 | 19 | /** 20 | * String 21 | */ 22 | S(String.class), 23 | /** 24 | * Integer 25 | */ 26 | I(Integer.class), 27 | /** 28 | * Long 29 | */ 30 | L(Long.class), 31 | /** 32 | * Double 33 | */ 34 | N(Double.class), 35 | /** 36 | * Date 37 | */ 38 | D(Date.class), 39 | /** 40 | * Boolean 41 | */ 42 | B(Boolean.class); 43 | 44 | //类型Class 45 | private Class fieldClass; 46 | 47 | private FieldType(Class fieldClass) { 48 | this.fieldClass = fieldClass; 49 | } 50 | 51 | /** 52 | * 获取类型Class 53 | * 54 | * @return Class 55 | */ 56 | public Class getValue() { 57 | return fieldClass; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /dactiv-common/src/main/java/com/github/dactiv/common/unit/JettyFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2005-2012 springside.org.cn 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | */ 6 | package com.github.dactiv.common.unit; 7 | 8 | import java.util.List; 9 | 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.eclipse.jetty.server.Connector; 12 | import org.eclipse.jetty.server.Server; 13 | import org.eclipse.jetty.server.nio.SelectChannelConnector; 14 | import org.eclipse.jetty.webapp.WebAppClassLoader; 15 | import org.eclipse.jetty.webapp.WebAppContext; 16 | 17 | import com.google.common.collect.Lists; 18 | 19 | /** 20 | * 创建Jetty Server的工厂类. 21 | * 22 | * @author calvin 23 | */ 24 | public class JettyFactory { 25 | 26 | private static final String DEFAULT_WEBAPP_PATH = "src/main/webapp"; 27 | 28 | /** 29 | * 创建用于开发运行调试的Jetty Server, 以src/main/webapp为Web应用目录. 30 | */ 31 | public static Server createServerInSource(int port, String contextPath) { 32 | Server server = new Server(); 33 | // 设置在JVM退出时关闭Jetty的钩子。 34 | server.setStopAtShutdown(true); 35 | 36 | SelectChannelConnector connector = new SelectChannelConnector(); 37 | connector.setPort(port); 38 | // 解决Windows下重复启动Jetty居然不报告端口冲突的问题. 39 | connector.setReuseAddress(false); 40 | server.setConnectors(new Connector[] { connector }); 41 | 42 | WebAppContext webContext = new WebAppContext(DEFAULT_WEBAPP_PATH, contextPath); 43 | server.setHandler(webContext); 44 | 45 | return server; 46 | } 47 | 48 | /** 49 | * 设置除jstl-*.jar外其他含tld文件的jar包的名称. 50 | * jar名称不需要版本号,如sitemesh, shiro-web 51 | */ 52 | public static void setTldJarNames(Server server, String... jarNames) { 53 | WebAppContext context = (WebAppContext) server.getHandler(); 54 | List jarNameExprssions = Lists.newArrayList(".*/jstl-[^/]*\\.jar$", ".*/.*taglibs[^/]*\\.jar$"); 55 | for (String jarName : jarNames) { 56 | jarNameExprssions.add(".*/" + jarName + "-[^/]*\\.jar$"); 57 | } 58 | 59 | context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", 60 | StringUtils.join(jarNameExprssions, '|')); 61 | 62 | } 63 | 64 | /** 65 | * 快速重新启动application,重载target/classes与target/test-classes. 66 | */ 67 | public static void reloadContext(Server server) throws Exception { 68 | WebAppContext context = (WebAppContext) server.getHandler(); 69 | 70 | System.out.println("[INFO] Application reloading"); 71 | context.stop(); 72 | 73 | WebAppClassLoader classLoader = new WebAppClassLoader(context); 74 | classLoader.addClassPath("target/classes"); 75 | classLoader.addClassPath("target/test-classes"); 76 | context.setClassLoader(classLoader); 77 | 78 | context.start(); 79 | 80 | System.out.println("[INFO] Application reloaded"); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /dactiv-common/src/main/java/com/github/dactiv/common/unit/selenium/WebDriverFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2005-2012 springside.org.cn 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | */ 6 | package com.github.dactiv.common.unit.selenium; 7 | 8 | import java.net.MalformedURLException; 9 | import java.net.URL; 10 | 11 | import org.openqa.selenium.WebDriver; 12 | import org.openqa.selenium.chrome.ChromeDriver; 13 | import org.openqa.selenium.firefox.FirefoxDriver; 14 | import org.openqa.selenium.ie.InternetExplorerDriver; 15 | import org.openqa.selenium.remote.DesiredCapabilities; 16 | import org.openqa.selenium.remote.RemoteWebDriver; 17 | import org.springframework.util.Assert; 18 | 19 | /** 20 | * 创建WebDriver的工厂类. 21 | * 22 | * @author calvin 23 | */ 24 | public class WebDriverFactory { 25 | /** 26 | * 根据driverName创建各种WebDriver的简便方法. 27 | * 28 | * 支持主要的firefox,ie,chrome三种常用浏览器. 29 | * 30 | * 当持续集成服务器安装在非Windows机器上, 没有IE浏览器与XWindows时, 又希望使用真正的浏览器时,需要使用remote driver调用远程的Windows机器. 31 | * drivername如remote:192.168.0.2:4444:firefox, 此时要求远程服务器在http://192.168.0.2:4444/wd/hub上启动selenium remote服务. 32 | */ 33 | public static WebDriver createDriver(String driverName) { 34 | WebDriver driver = null; 35 | 36 | if (BrowserType.firefox.name().equals(driverName)) { 37 | driver = new FirefoxDriver(); 38 | } else if (BrowserType.ie.name().equals(driverName)) { 39 | driver = new InternetExplorerDriver(); 40 | } else if (BrowserType.chrome.name().equals(driverName)) { 41 | driver = new ChromeDriver(); 42 | } else if (driverName.startsWith(BrowserType.remote.name())) { 43 | String[] params = driverName.split(":"); 44 | Assert.isTrue(params.length == 4, 45 | "Remote driver is not right, accept format is \"remote:localhost:4444:firefox\", but the input is\"" 46 | + driverName + "\""); 47 | 48 | String remoteHost = params[1]; 49 | String remotePort = params[2]; 50 | String driverType = params[3]; 51 | 52 | String remoteUrl = "http://" + remoteHost + ":" + remotePort + "/wd/hub"; 53 | 54 | DesiredCapabilities cap = null; 55 | if (BrowserType.firefox.name().equals(driverType)) { 56 | cap = DesiredCapabilities.firefox(); 57 | } else if (BrowserType.ie.name().equals(driverType)) { 58 | cap = DesiredCapabilities.internetExplorer(); 59 | } else if (BrowserType.chrome.name().equals(driverType)) { 60 | cap = DesiredCapabilities.chrome(); 61 | } 62 | 63 | try { 64 | driver = new RemoteWebDriver(new URL(remoteUrl), cap); 65 | } catch (MalformedURLException e) { 66 | throw new RuntimeException(e); 67 | } 68 | } 69 | 70 | Assert.notNull(driver, "Driver could be found by name:" + driverName); 71 | 72 | return driver; 73 | } 74 | 75 | public enum BrowserType { 76 | firefox, ie, chrome, remote 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /dactiv-common/src/main/java/com/github/dactiv/common/utils/ConvertUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2005-2012 springside.org.cn 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | */ 6 | package com.github.dactiv.common.utils; 7 | 8 | import java.util.Date; 9 | 10 | import org.apache.commons.beanutils.converters.DateConverter; 11 | 12 | /** 13 | * 类型转换工具类 14 | * 15 | * @author calvin 16 | * 17 | */ 18 | public class ConvertUtils extends org.apache.commons.beanutils.ConvertUtils{ 19 | 20 | static { 21 | registerDateConverter("yyyy-MM-dd"); 22 | } 23 | 24 | /** 25 | * 注册一个时间类型的转换器,当前默认的格式为:yyyy-MM-dd 26 | * 27 | * @param patterns 日期格式 28 | */ 29 | public static void registerDateConverter(String... patterns) { 30 | DateConverter dc = new DateConverter(); 31 | dc.setUseLocaleFormat(true); 32 | dc.setPatterns(patterns); 33 | register(dc, Date.class); 34 | } 35 | 36 | /** 37 | * 基于Apache BeanUtils转换字符串到相应类型. 38 | * 39 | * @param value 待转换的字符串. 40 | * @param toType 转换目标类型. 41 | */ 42 | public static Object convertToObject(String value, Class toType) { 43 | try { 44 | return convert(value, toType); 45 | } catch (Exception e) { 46 | throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); 47 | } 48 | } 49 | 50 | /** 51 | * 转换字符串数组到相应类型. 52 | * 53 | * @param value 待转换的字符串. 54 | * @param toType 转换目标类型. 55 | */ 56 | public static Object convertToObject(String[] values,Class toType) { 57 | try { 58 | return convert(values, toType); 59 | } catch (Exception e) { 60 | throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /dactiv-common/src/main/java/com/github/dactiv/common/utils/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2005-2012 springside.org.cn 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | */ 6 | package com.github.dactiv.common.utils; 7 | 8 | import java.io.PrintWriter; 9 | import java.io.StringWriter; 10 | 11 | /** 12 | * 关于异常的工具类. 13 | * 14 | * @author calvin 15 | */ 16 | public class ExceptionUtils { 17 | /** 18 | * 将CheckedException转换为UncheckedException. 19 | */ 20 | public static RuntimeException unchecked(Exception e) { 21 | if (e instanceof RuntimeException) { 22 | return (RuntimeException) e; 23 | } else { 24 | return new RuntimeException(e); 25 | } 26 | } 27 | 28 | /** 29 | * 将ErrorStack转化为String. 30 | */ 31 | public static String getStackTraceAsString(Exception e) { 32 | StringWriter stringWriter = new StringWriter(); 33 | e.printStackTrace(new PrintWriter(stringWriter)); 34 | return stringWriter.toString(); 35 | } 36 | 37 | /** 38 | * 判断异常是否由某些底层的异常引起. 39 | */ 40 | public static boolean isCausedBy(Exception ex, Class... causeExceptionClasses) { 41 | Throwable cause = ex; 42 | while (cause != null) { 43 | for (Class causeClass : causeExceptionClasses) { 44 | if (causeClass.isInstance(cause)) { 45 | return true; 46 | } 47 | } 48 | cause = cause.getCause(); 49 | } 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /dactiv-common/src/main/java/com/github/dactiv/common/utils/PropertiesUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2005-2012 springside.org.cn 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | */ 6 | package com.github.dactiv.common.utils; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.InputStreamReader; 11 | import java.util.Properties; 12 | 13 | import org.apache.commons.io.IOUtils; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | import org.springframework.core.io.DefaultResourceLoader; 17 | import org.springframework.core.io.Resource; 18 | import org.springframework.core.io.ResourceLoader; 19 | import org.springframework.util.DefaultPropertiesPersister; 20 | import org.springframework.util.PropertiesPersister; 21 | 22 | /** 23 | * Properties文件工具类. 24 | * 25 | * @author calvin 26 | */ 27 | public abstract class PropertiesUtils { 28 | 29 | private static final String DEFAULT_ENCODING = "UTF-8"; 30 | 31 | private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class); 32 | 33 | private static PropertiesPersister propertiesPersister = new DefaultPropertiesPersister(); 34 | private static ResourceLoader resourceLoader = new DefaultResourceLoader(); 35 | 36 | /** 37 | * 载入多个properties文件, 相同的属性在最后载入的文件中的值将会覆盖之前的载入. 38 | * 文件路径使用Spring Resource格式, 文件编码使用UTF-8. 39 | * 40 | * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer 41 | */ 42 | public static Properties loadProperties(String... resourcesPaths) { 43 | Properties props = new Properties(); 44 | 45 | for (String location : resourcesPaths) { 46 | 47 | logger.debug("Loading properties file from:" + location); 48 | 49 | InputStream is = null; 50 | try { 51 | Resource resource = resourceLoader.getResource(location); 52 | is = resource.getInputStream(); 53 | propertiesPersister.load(props, new InputStreamReader(is, DEFAULT_ENCODING)); 54 | } catch (IOException ex) { 55 | logger.info("Could not load properties from classpath:" + location + ": " + ex.getMessage()); 56 | } finally { 57 | IOUtils.closeQuietly(is); 58 | } 59 | } 60 | return props; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /dactiv-common/src/test/java/com/github/dactiv/common/test/bundle/TestBeanResourceBundle.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.common.test.bundle; 2 | 3 | import java.util.Map; 4 | import java.util.UUID; 5 | 6 | import static org.junit.Assert.*; 7 | 8 | import org.apache.commons.collections.MapUtils; 9 | import com.github.dactiv.common.bundle.BeanResourceBundle; 10 | import com.github.dactiv.common.test.entity.User; 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.junit.runners.BlockJUnit4ClassRunner; 14 | 15 | import com.google.common.collect.Maps; 16 | 17 | /** 18 | * 单元测试BeanResourceBundle 19 | * 20 | * @author Administrator 21 | * 22 | */ 23 | @RunWith(BlockJUnit4ClassRunner.class) 24 | public class TestBeanResourceBundle { 25 | private User user = new User(); 26 | 27 | @Test 28 | @SuppressWarnings("unchecked") 29 | public void testToMap() { 30 | user.setEmail(null); 31 | user.setId(UUID.randomUUID().toString().replaceAll("-", "")); 32 | user.setPassword("123456"); 33 | user.setRealname("chenxiaobo"); 34 | user.setState(new Integer(1)); 35 | user.setUsername("maurice"); 36 | 37 | Map map = Maps.newHashMap(); 38 | 39 | //测试include属性 40 | map = MapUtils.toMap(new BeanResourceBundle(user,new String[]{"username","password","realname"})); 41 | 42 | assertEquals(map.size(), 3); 43 | assertEquals(map.get("username"), user.getUsername()); 44 | assertEquals(map.get("realname"), user.getRealname()); 45 | assertEquals(map.get("password"), user.getPassword()); 46 | 47 | assertFalse(map.containsKey("email")); 48 | 49 | //测试exclude属性 50 | map = MapUtils.toMap(new BeanResourceBundle(user,null,new String[]{"username","password","realname"})); 51 | 52 | assertEquals(map.size(), 2); 53 | assertEquals(map.get("id"), user.getId()); 54 | assertEquals(map.get("state"),user.getState()); 55 | 56 | assertFalse(map.containsKey("email")); 57 | 58 | //测试ignoreEmptyValue属性 59 | map = MapUtils.toMap(new BeanResourceBundle(user,null,null,false)); 60 | 61 | assertEquals(map.get("id"), user.getId()); 62 | assertEquals(map.get("state"),user.getState()); 63 | assertEquals(map.get("username"), user.getUsername()); 64 | assertEquals(map.get("realname"), user.getRealname()); 65 | assertEquals(map.get("password"), user.getPassword()); 66 | 67 | assertTrue(map.containsKey("email")); 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /dactiv-common/src/test/java/com/github/dactiv/common/test/bundle/TestJacksonBundle.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.common.test.bundle; 2 | 3 | import java.util.ArrayList; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | import org.apache.commons.lang3.StringUtils; 8 | import com.github.dactiv.common.bundle.JacksonBundle; 9 | import com.github.dactiv.common.test.entity.Group; 10 | import com.github.dactiv.common.test.entity.User; 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.BlockJUnit4ClassRunner; 15 | 16 | /** 17 | * JacksonMapper单元测试 18 | * 19 | * @author maurice 20 | * 21 | */ 22 | @RunWith(BlockJUnit4ClassRunner.class) 23 | public class TestJacksonBundle { 24 | 25 | private User user; 26 | 27 | @Before 28 | public void reloadUser() { 29 | user = new User(); 30 | } 31 | 32 | @Test 33 | public void testToJson() { 34 | String json = null; 35 | 36 | //测试不管任何属性的值是否为空,只要存在就序列化成json 37 | json = JacksonBundle.alwaysMapper().toJson(user); 38 | assertTrue(StringUtils.contains(json,"\"groupsList\"")); 39 | 40 | //测试紧存在属性的值不为空的json 41 | user.setGroupsList(new ArrayList()); 42 | json = JacksonBundle.nonEmptyMapper().toJson(user); 43 | assertFalse(StringUtils.contains(json,"\"groupsList\"")); 44 | assertFalse(StringUtils.contains(json,"\"email\"")); 45 | 46 | //测试紧存在属性的值不为null的json 47 | json = JacksonBundle.nonNullMapper().toJson(user); 48 | assertTrue(StringUtils.contains(json,"\"groupsList\"")); 49 | assertTrue(StringUtils.contains(json,"\"groupNames\"")); 50 | 51 | //测试初始值被改变的json user.setGroupsList(new ArrayList()); 52 | user = new User(); 53 | json = JacksonBundle.nonDefaultMapper().toJson(user); 54 | assertTrue(StringUtils.contains(json,"{}")); 55 | 56 | user.setEmail("maurice@es.com"); 57 | user.setUsername("maurice"); 58 | user.setGroupsList(new ArrayList()); 59 | json = JacksonBundle.nonDefaultMapper().toJson(user); 60 | 61 | assertTrue(StringUtils.contains(json,"\"email\"")); 62 | assertTrue(StringUtils.contains(json,"\"groupsList\"")); 63 | assertTrue(StringUtils.contains(json,"\"groupNames\"")); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /dactiv-common/src/test/java/com/github/dactiv/common/test/entity/UniversallyUniqueIdentifier.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.common.test.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.xml.bind.annotation.XmlAccessType; 6 | import javax.xml.bind.annotation.XmlAccessorType; 7 | import javax.xml.bind.annotation.XmlRootElement; 8 | 9 | import org.apache.commons.lang3.StringUtils; 10 | 11 | /** 12 | * UUID主键父类 13 | * 14 | * @author maurice 15 | * 16 | */ 17 | @XmlRootElement 18 | @XmlAccessorType(XmlAccessType.PROPERTY) 19 | @SuppressWarnings("serial") 20 | public class UniversallyUniqueIdentifier implements Serializable{ 21 | 22 | protected String id; 23 | 24 | /** 25 | * 获取主键ID 26 | * 27 | * @return String 28 | */ 29 | public String getId() { 30 | if (StringUtils.isEmpty(id)) { 31 | return null; 32 | } 33 | return this.id; 34 | } 35 | 36 | /** 37 | * 设置主键ID, 38 | * @param id 39 | */ 40 | public void setId(String id) { 41 | if (StringUtils.isEmpty(id)) { 42 | this.id = null; 43 | } else { 44 | this.id = id; 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /dactiv-common/src/test/java/com/github/dactiv/common/test/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.common.test.entity; 2 | 3 | import java.util.List; 4 | 5 | import javax.xml.bind.annotation.XmlRootElement; 6 | 7 | import com.github.dactiv.common.utils.CollectionUtils; 8 | 9 | @XmlRootElement(name="user") 10 | @SuppressWarnings("serial") 11 | public class User extends UniversallyUniqueIdentifier{ 12 | //登录名称 13 | private String username = "maurice"; 14 | //登录密码 15 | private String password = "dkfjsoj42kl34j2348aslkdfj"; 16 | //真实名称 17 | private String realname = "chen"; 18 | //状态 19 | private Integer state = new Integer(1); 20 | //邮件 21 | private String email = null; 22 | //用户所在的组 23 | private List groupsList; 24 | 25 | /** 26 | * 构造方法 27 | */ 28 | public User() { 29 | } 30 | 31 | /** 32 | * 获取登录名称 33 | * 34 | * @return String 35 | */ 36 | public String getUsername() { 37 | return username; 38 | } 39 | 40 | /** 41 | * 设置登录名称 42 | * 43 | * @param username 登录名称 44 | */ 45 | public void setUsername(String username) { 46 | this.username = username; 47 | } 48 | 49 | /** 50 | * 获取登录密码 51 | * 52 | * @return String 53 | */ 54 | public String getPassword() { 55 | return password; 56 | } 57 | 58 | /** 59 | * 设置登录密码 60 | * 61 | * @param password 登录密码 62 | */ 63 | public void setPassword(String password) { 64 | this.password = password; 65 | } 66 | 67 | /** 68 | * 获取真实姓名 69 | * 70 | * @return String 71 | */ 72 | public String getRealname() { 73 | return realname; 74 | } 75 | 76 | /** 77 | * 设置真实名称 78 | * 79 | * @param realName 真实姓名 80 | */ 81 | public void setRealname(String realname) { 82 | this.realname = realname; 83 | } 84 | 85 | 86 | /** 87 | * 获取用户状态 88 | * 89 | * @return Integer 90 | */ 91 | public Integer getState() { 92 | return state; 93 | } 94 | 95 | /** 96 | * 设置用户状态 97 | * 98 | * @param state 用户状态 99 | */ 100 | public void setState(Integer state) { 101 | this.state = state; 102 | } 103 | 104 | /** 105 | * 获取邮件 106 | * @return String 107 | */ 108 | public String getEmail() { 109 | return email; 110 | } 111 | 112 | /** 113 | * 设置邮件 114 | * @param email 邮件地址 115 | */ 116 | public void setEmail(String email) { 117 | this.email = email; 118 | } 119 | 120 | /** 121 | * 获取该用户所在的组 122 | * 123 | * @return List 124 | */ 125 | public List getGroupsList() { 126 | return groupsList; 127 | } 128 | 129 | /** 130 | * 设置用户所在的组 131 | * 132 | * @param groupsList 组集合 133 | */ 134 | public void setGroupsList(List groupsList) { 135 | this.groupsList = groupsList; 136 | } 137 | 138 | /** 139 | * 获取所在组所用名称 140 | * 141 | * @return String 142 | */ 143 | public String getGroupNames() { 144 | return CollectionUtils.extractToString(this.groupsList, "name", ","); 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /dactiv-common/src/test/java/com/github/dactiv/common/test/utils/TestJaxWsFactoryUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.common.test.utils; 2 | 3 | import com.github.dactiv.common.utils.JaxWsFactoryUtils; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.BlockJUnit4ClassRunner; 8 | 9 | /** 10 | * JaxWsFactory工具类单元测试 11 | * 12 | * @author maurice 13 | * 14 | */ 15 | @RunWith(BlockJUnit4ClassRunner.class) 16 | public class TestJaxWsFactoryUtils { 17 | 18 | @Test 19 | public void testInvoke() throws Exception { 20 | Object[] result = null; 21 | 22 | //首次调用,CXF会创建动态客户端,效率相当低。 23 | result = JaxWsFactoryUtils.invoke("http://webservice.webxml.com.cn/webservices/mobilecodews.asmx?wsdl", 24 | "getMobileCodeInfo", 25 | "18776974353", 26 | null); 27 | 28 | Assert.assertEquals(result[0],"18776974353:广西 南宁 广西移动全球通卡"); 29 | 30 | //二次调用,不在创建动态客户端,速度比首次快很多。 31 | result = JaxWsFactoryUtils.invoke("http://webservice.webxml.com.cn/webservices/mobilecodews.asmx?wsdl", 32 | "getMobileCodeInfo", 33 | "15277108562", 34 | null); 35 | 36 | Assert.assertEquals(result[0],"15277108562:广西 南宁 广西移动动感地带卡"); 37 | 38 | //刷新所有动态客户端 39 | JaxWsFactoryUtils.refreshClientMap(); 40 | //刷新单个动态客户端 41 | JaxWsFactoryUtils.refreshClient("http://webservice.webxml.com.cn/webservices/mobilecodews.asmx?wsdl"); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /dactiv-common/src/test/java/com/github/dactiv/common/test/utils/TestReflectionUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.common.test.utils; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.lang.reflect.Field; 6 | import java.lang.reflect.Method; 7 | import java.util.List; 8 | 9 | import javax.xml.bind.annotation.XmlRootElement; 10 | 11 | import com.github.dactiv.common.test.entity.User; 12 | import com.github.dactiv.common.utils.ReflectionUtils; 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | 16 | /** 17 | * 反射工具类单元测试 18 | * 19 | * @author maurice 20 | * 21 | */ 22 | public class TestReflectionUtils { 23 | 24 | private User user; 25 | 26 | @Before 27 | public void initData() { 28 | user = new User(); 29 | } 30 | 31 | @Test 32 | public void testInvokeMethod() { 33 | ReflectionUtils.invokeMethod(user, "setUsername", new Class[]{String.class}, new String[]{"maurice"}); 34 | assertEquals(user.getUsername(), "maurice"); 35 | } 36 | 37 | @Test 38 | public void testHasField() { 39 | assertEquals(ReflectionUtils.hasField(user, "username"),true); 40 | assertEquals(ReflectionUtils.hasField(user, "vicnent"),false); 41 | } 42 | 43 | @Test(expected=IllegalArgumentException.class) 44 | public void testGetFieldValue() { 45 | ReflectionUtils.invokeMethod(user, "setUsername", new Class[]{String.class}, new String[]{"maurice"}); 46 | assertEquals("maurice", ReflectionUtils.getFieldValue(user, "username")); 47 | ReflectionUtils.getFieldValue(user, "maurice"); 48 | assertEquals(null, ReflectionUtils.getFieldValue(user, "password")); 49 | } 50 | 51 | @Test 52 | public void testSetFieldValue() { 53 | ReflectionUtils.setFieldValue(user, "username", "maurice"); 54 | 55 | assertEquals(ReflectionUtils.getFieldValue(user, "username"), "maurice"); 56 | } 57 | 58 | @Test 59 | public void testGetAccessibleField() { 60 | Field field = ReflectionUtils.getAccessibleField(user, "groupsList"); 61 | assertEquals(field.getType(),List.class); 62 | } 63 | 64 | @Test 65 | public void testGetAccessibleFields() { 66 | List parends = ReflectionUtils.getAccessibleFields(user.getClass(), false); 67 | List fields = ReflectionUtils.getAccessibleFields(user.getClass(), true); 68 | 69 | assertEquals(fields.size(),6); 70 | assertEquals(parends.size(),7); 71 | } 72 | 73 | @Test 74 | public void testGetAccessibleMethod() { 75 | Method method = ReflectionUtils.getAccessibleMethod(user, "getUsername"); 76 | assertEquals(method.getName(),"getUsername"); 77 | } 78 | 79 | @Test 80 | public void testGetAccessibleMethods() { 81 | List methods = ReflectionUtils.getAccessibleMethods(user.getClass(),true); 82 | List parents = ReflectionUtils.getAccessibleMethods(user.getClass()); 83 | 84 | assertEquals(methods.size(),13); 85 | assertEquals(parents.size(),15); 86 | } 87 | 88 | @Test 89 | public void testGetAnnotation() { 90 | XmlRootElement element = ReflectionUtils.getAnnotation(user.getClass(), XmlRootElement.class); 91 | 92 | assertEquals(element.name(),"user"); 93 | } 94 | 95 | @Test 96 | public void testGetAccessibleFieldNames() { 97 | List fieldNames = ReflectionUtils.getAccessibleFieldNames(user.getClass(), String.class); 98 | assertEquals(fieldNames.size(), 4); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /dactiv-common/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d [%t] %-5p [%c:%L] - %m%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /dactiv-orm/bin/README.md: -------------------------------------------------------------------------------- 1 | ###工具说明 2 | 3 | eclipse:将项目生成为eclipse项目 4 | 5 | idea:将项目生成为idea项目 6 | 7 | myeclipse:将项目生成为myeclipse项目 8 | 9 | install:将该项目所有的依赖初始化到本地m2库 10 | 11 | -------------------------------------------------------------------------------- /dactiv-orm/bin/eclipse.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] create a project. 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn eclipse:eclipse 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /dactiv-orm/bin/idea.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] create project to idea 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn clean idea:idea 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /dactiv-orm/bin/install.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] Install jar to local repository. 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn clean source:jar install -Dmaven.test.skip=true 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /dactiv-orm/bin/myeclipse.bat: -------------------------------------------------------------------------------- 1 | 2 | @echo off 3 | echo [INFO] create project to myeclipse 4 | 5 | cd %~dp0 6 | cd .. 7 | call mvn eclipse:myeclipse 8 | cd bin 9 | pause 10 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/annotation/StateDelete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | import com.github.dactiv.common.type.FieldType; 24 | 25 | 26 | 27 | /** 28 | * Hibernate状态删除,如果在orm实体配置该注解,将不会物理删除数据,会根据该配置来进行对orm实体的update操作 29 | * 30 | * 31 | *
32 |  * @Entity
33 |  * @Table(name="tb_user")
34 |  * @StateDelete(propertyName = "state",type = FieldType.S,value="2")
35 |  * public class User{
36 |  * 	private String username;
37 |  * 	private String state;
38 |  * 
39 |  * 	public User() {
40 |  * 	}
41 |  * 	getter/setter.....
42 |  * }
43 |  * User user = dao.get(1);
44 |  * dao.delete(user);
45 |  * ----------------------------------
46 |  * sql:update tb_user set state = ? where id = ?
47 |  * 
48 | * 49 | * @author maurice 50 | * 51 | */ 52 | @Target(ElementType.TYPE) 53 | @Retention(RetentionPolicy.RUNTIME) 54 | public @interface StateDelete { 55 | 56 | /** 57 | * 属性名称 58 | * 59 | * @return String 60 | */ 61 | public String propertyName(); 62 | 63 | /** 64 | * 要改变的值 65 | * 66 | * @return String 67 | */ 68 | public String value(); 69 | 70 | /** 71 | * 改变值的类型 72 | * 73 | * @return {@link FieldType} 74 | */ 75 | public FieldType type() default FieldType.I; 76 | } 77 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/MatchValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import org.apache.commons.collections.CollectionUtils; 22 | import org.apache.commons.lang3.StringUtils; 23 | import com.github.dactiv.common.utils.ConvertUtils; 24 | 25 | /** 26 | * 对比值实体,根据该类的信息进行对一个或多个属性值该如何or或者and进行条件关联 27 | * 28 | * @author maurice 29 | * 30 | */ 31 | public class MatchValue { 32 | 33 | private boolean hasOrOperate; 34 | private List values; 35 | 36 | /** 37 | * 对比值实体,根据该类的信息进行对一个或多个属性值该如何是 or或者and进行条件关联 38 | * 39 | * @param hasOrOperate 是否存在or提哦间操作 40 | * @param values 要对比的值 41 | */ 42 | public MatchValue(boolean hasOrOperate,List values) { 43 | this.hasOrOperate = hasOrOperate; 44 | this.values = values; 45 | } 46 | 47 | /** 48 | * 获取是否存在or条件对比 49 | * 50 | * @return boolean 51 | */ 52 | public boolean hasOrOperate() { 53 | return hasOrOperate; 54 | } 55 | 56 | /** 57 | * 获取要对比的所有值 58 | * 59 | * @return List 60 | */ 61 | public List getValues() { 62 | return values; 63 | } 64 | 65 | /** 66 | * 创建对比值模型,如果是多值以andValueSeparator(并且值)或者orValueSeparator(或者值)分割 67 | * 68 | * @param matchValue 值 69 | * @param type 值类型 70 | * @param andValueSeparator 并且分隔符 71 | * @param orValueSeparator 或者分隔符 72 | * 73 | * @return {@link MatchValue} 74 | */ 75 | public static MatchValue createMatchValueModel(String matchValue,Class type,String andValueSeparator,String orValueSeparator) { 76 | 77 | List values = new ArrayList(); 78 | 79 | if (StringUtils.contains(matchValue, andValueSeparator)) { 80 | String[] siplit = StringUtils.splitByWholeSeparator(matchValue, andValueSeparator); 81 | CollectionUtils.addAll(values, (Object[])ConvertUtils.convertToObject(siplit, type)); 82 | return new MatchValue(false, values); 83 | } else if (StringUtils.contains(matchValue, orValueSeparator)){ 84 | String[] siplit = StringUtils.splitByWholeSeparator(matchValue, orValueSeparator); 85 | CollectionUtils.addAll(values, (Object[])ConvertUtils.convertToObject(siplit, type)); 86 | return new MatchValue(true, values); 87 | } else { 88 | values.add(ConvertUtils.convertToObject(matchValue, type)); 89 | return new MatchValue(false, values); 90 | } 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/RestrictionNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core; 17 | 18 | /** 19 | * 所有约束名称 20 | * 21 | * @author maurice 22 | * 23 | */ 24 | public interface RestrictionNames { 25 | 26 | /** 27 | * 等于查询(from Object o where o.property = ?) 28 | */ 29 | public static String EQ = "EQ"; 30 | 31 | /** 32 | * 非等于查询(from Object o where o.property <> ?) 33 | */ 34 | public static String NE = "NE"; 35 | 36 | /** 37 | * 大于等于查询(from Object o where o.property >= ?) 38 | */ 39 | public static String GE = "GE"; 40 | 41 | /** 42 | * 大于查询(from Object o where o.property > ?) 43 | */ 44 | public static String GT = "GT"; 45 | 46 | /** 47 | * 小于等于查询(from Object o where o.property <= ?) 48 | */ 49 | public static String LE = "LE"; 50 | 51 | /** 52 | * 小于查询(from Object o where o.property < ?) 53 | */ 54 | public static String LT = "LT"; 55 | 56 | /** 57 | * 包含查询(from Object o where o.property in(?,?,?)) 58 | */ 59 | public static String IN = "IN"; 60 | 61 | /** 62 | * 非包含查询(from Object o where o.property not in(?,?,?)) 63 | */ 64 | public static String NIN = "NIN"; 65 | 66 | /** 67 | * 左模糊查询(from Object o where o.property like %?) 68 | */ 69 | public static String LLIKE = "LLIKE"; 70 | 71 | /** 72 | * 右模糊查询(from Object o where o.property like ?%) 73 | */ 74 | public static String RLIKE= "RLIKE"; 75 | 76 | /** 77 | * 模糊查询(from Object o where o.property like %?%) 78 | */ 79 | public static String LIKE = "LIKE"; 80 | } 81 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/CriterionBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate; 17 | 18 | import com.github.dactiv.orm.core.PropertyFilter; 19 | import org.hibernate.Criteria; 20 | import org.hibernate.criterion.Criterion; 21 | 22 | /** 23 | * 24 | * 辅助{@link com.github.dactiv.orm.core.PropertyFilters#build(String, String)} 25 | * 方法创建PropertyFilter后使用哪种约束条件向Hibernate的{@link Criteria}进行条件过滤查询的接口, 26 | * 27 | * @author maurice 28 | * 29 | */ 30 | public interface CriterionBuilder { 31 | 32 | /** 33 | * 获取Hibernate的约束标准 34 | * 35 | * @param filter 属性过滤器 36 | * 37 | * @return {@link Criterion} 38 | * 39 | */ 40 | public Criterion build(PropertyFilter filter); 41 | 42 | /** 43 | * 获取Criterion标准的约束名称 44 | * 45 | * @return String 46 | */ 47 | public String getRestrictionName(); 48 | 49 | /** 50 | * 获取Hibernate的约束标准 51 | * 52 | * @param propertyName 属性名 53 | * @param value 值 54 | * 55 | * @return {@link Criterion} 56 | * 57 | */ 58 | public Criterion build(String propertyName,Object value); 59 | } 60 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/CriterionMultipleValueSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | import com.github.dactiv.common.utils.ConvertUtils; 20 | import com.github.dactiv.orm.core.PropertyFilter; 21 | import org.hibernate.criterion.Criterion; 22 | import org.hibernate.criterion.Disjunction; 23 | import org.hibernate.criterion.Restrictions; 24 | import org.springframework.util.Assert; 25 | 26 | /** 27 | * 对{@link PropertyFilter#getMatchValue()}的特殊情况值做处理,例如 in, not in, between的多值情况, 28 | * 该类值处理一种情况 29 | * 30 | *

31 | * 例如: 32 | *

33 | * 34 | * INI_property = "1,2,3,4"; 35 | *

36 | * 会产生的sql为: property in (1,2,3,4) 37 | * 38 | * @author maurice 39 | * 40 | */ 41 | public abstract class CriterionMultipleValueSupport extends CriterionSingleValueSupport{ 42 | 43 | /** 44 | * 将得到值与指定分割符号,分割,得到数组 45 | * 46 | * @param value 值 47 | * @param type 值类型 48 | * 49 | * @return Object 50 | */ 51 | public Object convertMatchValue(String value, Class type) { 52 | Assert.notNull(value,"值不能为空"); 53 | String[] result = StringUtils.splitByWholeSeparator(value, getAndValueSeparator()); 54 | 55 | return ConvertUtils.convertToObject(result,type); 56 | } 57 | 58 | /* 59 | * (non-Javadoc) 60 | * @see com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport#build(com.github.dactiv.orm.core.PropertyFilter) 61 | */ 62 | public Criterion build(PropertyFilter filter) { 63 | Object value = convertMatchValue(filter.getMatchValue(), filter.getFieldType()); 64 | Criterion criterion = null; 65 | if (filter.hasMultiplePropertyNames()) { 66 | Disjunction disjunction = Restrictions.disjunction(); 67 | for (String propertyName:filter.getPropertyNames()) { 68 | disjunction.add(build(propertyName,value)); 69 | } 70 | criterion = disjunction; 71 | } else { 72 | criterion = build(filter.getSinglePropertyName(),value); 73 | } 74 | return criterion; 75 | } 76 | 77 | /* 78 | * (non-Javadoc) 79 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object) 80 | */ 81 | public Criterion build(String propertyName, Object value) { 82 | 83 | return buildRestriction(propertyName, (Object[])value); 84 | } 85 | 86 | 87 | /** 88 | * 89 | * 获取Hibernate的约束标准 90 | * 91 | * @param propertyName 属性名 92 | * @param values 值 93 | * 94 | * @return {@link Criterion} 95 | */ 96 | public abstract Criterion buildRestriction(String propertyName,Object[] values); 97 | } 98 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/EqRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | import com.github.dactiv.orm.core.MatchValue; 20 | import com.github.dactiv.orm.core.RestrictionNames; 21 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport; 22 | import org.hibernate.criterion.Criterion; 23 | import org.hibernate.criterion.Restrictions; 24 | 25 | /** 26 | * 等于约束 (from object o where o.value = ?) RestrictionName:EQ 27 | *

28 | * 表达式:EQ属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class EqRestriction extends CriterionSingleValueSupport { 35 | /* 36 | * (non-Javadoc) 37 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 38 | */ 39 | public String getRestrictionName() { 40 | return RestrictionNames.EQ; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport#getMatchValue(java.lang.String, java.lang.Class) 46 | */ 47 | public MatchValue getMatchValue(String matchValue, Class FieldType) { 48 | 49 | MatchValue matchValueModel = super.getMatchValue(matchValue, FieldType); 50 | for (int i = 0; i < matchValueModel.getValues().size(); i++) { 51 | Object value = matchValueModel.getValues().get(i); 52 | if (value instanceof String && StringUtils.equals(value.toString(),"null")) { 53 | matchValueModel.getValues().remove(i); 54 | matchValueModel.getValues().add(i, null); 55 | } 56 | } 57 | return matchValueModel; 58 | } 59 | 60 | public Criterion build(String propertyName, Object value) { 61 | 62 | return value == null ? Restrictions.isNull(propertyName) : Restrictions.eq(propertyName, value); 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/GeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.Restrictions; 22 | 23 | /** 24 | * 大于等于约束 (from object o where o.value >= ?)RestrictionName:GE 25 | *

26 | * 表达式:GE属性类型_属性名称[_OR_属性名称...] 27 | *

28 | * 29 | * @author maurice 30 | * 31 | */ 32 | public class GeRestriction extends CriterionSingleValueSupport{ 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 37 | */ 38 | public String getRestrictionName() { 39 | 40 | return RestrictionNames.GE; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object) 46 | */ 47 | public Criterion build(String propertyName, Object value) { 48 | 49 | return Restrictions.ge(propertyName, value); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/GtRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.Restrictions; 22 | 23 | /** 24 | * 大于约束 (from object o where o.value > ?)RestrictionName:GT 25 | *

26 | * 表达式:GT属性类型_属性名称[_OR_属性名称...] 27 | *

28 | * 29 | * @author maurice 30 | * 31 | */ 32 | public class GtRestriction extends CriterionSingleValueSupport{ 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 37 | */ 38 | public String getRestrictionName() { 39 | 40 | return RestrictionNames.GT; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object) 46 | */ 47 | public Criterion build(String propertyName, Object value) { 48 | return Restrictions.gt(propertyName, value); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/InRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionMultipleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.Restrictions; 22 | 23 | /** 24 | * 包含约束 (from object o where o.value in (?,?,?,?,?))RestrictionName:IN 25 | *

26 | * 表达式:IN属性类型_属性名称[_OR_属性名称...] 27 | *

28 | * 29 | * @author maurice 30 | * 31 | */ 32 | public class InRestriction extends CriterionMultipleValueSupport{ 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 37 | */ 38 | public String getRestrictionName() { 39 | return RestrictionNames.IN; 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * @see com.github.dactiv.orm.core.hibernate.restriction.CriterionMultipleValueSupport#buildRestriction(java.lang.String, java.lang.Object[]) 45 | */ 46 | public Criterion buildRestriction(String propertyName, Object[] values) { 47 | return Restrictions.in(propertyName,values); 48 | } 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/LLikeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.MatchMode; 22 | import org.hibernate.criterion.Restrictions; 23 | 24 | /** 25 | * 左模糊约束 ( from object o where o.value like '%?') RestrictionName:LLIKE 26 | *

27 | * 表达式:LLIKE属性类型_属性名称[_OR_属性名称...] 28 | *

29 | * 30 | * @author maurice 31 | * 32 | */ 33 | public class LLikeRestriction extends CriterionSingleValueSupport{ 34 | 35 | /* 36 | * (non-Javadoc) 37 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 38 | */ 39 | public String getRestrictionName() { 40 | return RestrictionNames.LLIKE; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object) 46 | */ 47 | public Criterion build(String propertyName, Object value) { 48 | 49 | return Restrictions.like(propertyName, value.toString(), MatchMode.END); 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/LeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.Restrictions; 22 | 23 | /** 24 | * 小于等于约束 ( from object o where o.value <= ?) RestrictionName:LR 25 | *

26 | * 表达式:LE属性类型_属性名称[_OR_属性名称...] 27 | *

28 | * 29 | * @author maurice 30 | * 31 | */ 32 | public class LeRestriction extends CriterionSingleValueSupport{ 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 37 | */ 38 | public String getRestrictionName() { 39 | 40 | return RestrictionNames.LE; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object) 46 | */ 47 | public Criterion build(String propertyName, Object value) { 48 | return Restrictions.le(propertyName, value); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/LikeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.MatchMode; 22 | import org.hibernate.criterion.Restrictions; 23 | 24 | /** 25 | * 模糊约束 ( from object o where o.value like '%?%') RestrictionName:LIKE 26 | *

27 | * 表达式:LIKE属性类型_属性名称[_OR_属性名称...] 28 | *

29 | * 30 | * @author maurice 31 | * 32 | */ 33 | public class LikeRestriction extends CriterionSingleValueSupport{ 34 | 35 | /* 36 | * (non-Javadoc) 37 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 38 | */ 39 | public String getRestrictionName() { 40 | return RestrictionNames.LIKE; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object) 46 | */ 47 | public Criterion build(String propertyName, Object value) { 48 | return Restrictions.like(propertyName, value.toString(), MatchMode.ANYWHERE); 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/LtRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.Restrictions; 22 | 23 | /** 24 | * 小于约束 ( from object o where o.value < ?) RestrictionName:LT 25 | *

26 | * 表达式:LT属性类型_属性名称[_OR_属性名称...] 27 | *

28 | * 29 | * @author maurice 30 | * 31 | */ 32 | public class LtRestriction extends CriterionSingleValueSupport{ 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 37 | */ 38 | public String getRestrictionName() { 39 | return RestrictionNames.LT; 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object) 45 | */ 46 | public Criterion build(String propertyName, Object value) { 47 | return Restrictions.lt(propertyName, value); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/NeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import org.hibernate.criterion.Criterion; 20 | import org.hibernate.criterion.Restrictions; 21 | 22 | /** 23 | * 不等于约束 ( from object o where o.value <> ?) RestrictionName:NE 24 | *

25 | * 表达式:NE属性类型_属性名称[_OR_属性名称...] 26 | *

27 | * 28 | * @author maurice 29 | * 30 | */ 31 | public class NeRestriction extends EqRestriction{ 32 | 33 | /* 34 | * (non-Javadoc) 35 | * @see com.github.dactiv.orm.core.hibernate.restriction.support.EqRestriction#getRestrictionName() 36 | */ 37 | public String getRestrictionName() { 38 | 39 | return RestrictionNames.NE; 40 | } 41 | 42 | /* 43 | * (non-Javadoc) 44 | * @see com.github.dactiv.orm.core.hibernate.restriction.support.EqRestriction#build(java.lang.String, java.lang.Object) 45 | */ 46 | public Criterion build(String propertyName, Object value) { 47 | 48 | return value == null ? Restrictions.isNotNull(propertyName) : Restrictions.ne(propertyName, value); 49 | 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/NinRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionMultipleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.Restrictions; 22 | 23 | /** 24 | * 不包含约束 (from object o where o.value not in (?,?,?,?,?))RestrictionName:NIN 25 | *

26 | * 表达式:NIN属性类型_属性名称[_OR_属性名称...] 27 | *

28 | * 29 | * @author maurice 30 | * 31 | */ 32 | public class NinRestriction extends CriterionMultipleValueSupport{ 33 | 34 | /* 35 | * (non-Javadoc) 36 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 37 | */ 38 | public String getRestrictionName() { 39 | 40 | return RestrictionNames.NIN; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.github.dactiv.orm.core.hibernate.restriction.CriterionMultipleValueSupport#buildRestriction(java.lang.String, java.lang.Object[]) 46 | */ 47 | public Criterion buildRestriction(String propertyName, Object[] values) { 48 | 49 | return Restrictions.not(Restrictions.in(propertyName, values)); 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/hibernate/restriction/support/RLikeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.hibernate.restriction.support; 17 | 18 | import com.github.dactiv.orm.core.RestrictionNames; 19 | import com.github.dactiv.orm.core.hibernate.restriction.CriterionSingleValueSupport; 20 | import org.hibernate.criterion.Criterion; 21 | import org.hibernate.criterion.MatchMode; 22 | import org.hibernate.criterion.Restrictions; 23 | 24 | /** 25 | * 右模糊约束 ( from object o where o.value like '?%') RestrictionName:RLIKE 26 | *

27 | * 表达式:RLIKE属性类型_属性名称[_OR_属性名称...] 28 | *

29 | * 30 | * @author maurice 31 | * 32 | */ 33 | public class RLikeRestriction extends CriterionSingleValueSupport{ 34 | 35 | /* 36 | * (non-Javadoc) 37 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#getRestrictionName() 38 | */ 39 | public String getRestrictionName() { 40 | return RestrictionNames.RLIKE; 41 | } 42 | 43 | /* 44 | * (non-Javadoc) 45 | * @see com.github.dactiv.orm.core.hibernate.CriterionBuilder#build(java.lang.String, java.lang.Object) 46 | */ 47 | public Criterion build(String propertyName, Object value) { 48 | 49 | return Restrictions.like(propertyName, value.toString(), MatchMode.START); 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/PredicateBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Predicate; 20 | 21 | import com.github.dactiv.orm.core.PropertyFilter; 22 | import com.github.dactiv.orm.core.spring.data.jpa.specification.SpecificationEntity; 23 | 24 | /** 25 | * 26 | * 辅助{@link JpaRestrictionBuilder}类创建PropertyFilter后使用哪种约束条件向{@link CriteriaBuilder}添加{@link Predicate}进行条件过滤查询的接口 27 | * 28 | * @author maurice 29 | * 30 | */ 31 | public interface PredicateBuilder { 32 | 33 | /** 34 | * 获取Jpa的约束标准 35 | * 36 | * @param filter 属性过滤器 37 | * @param model jpa绑定模型 38 | * 39 | * @return {@link Predicate} 40 | * 41 | */ 42 | public Predicate build(PropertyFilter filter,SpecificationEntity entity); 43 | 44 | /** 45 | * 获取Predicate标准的约束名称 46 | * 47 | * @return String 48 | */ 49 | public String getRestrictionName(); 50 | 51 | /** 52 | * 获取Jpa的约束标准 53 | * 54 | * @param propertyName 属性名 55 | * @param value 值 56 | * @param builder CriteriaBuilder 57 | * 58 | * @return {@link Predicate} 59 | * 60 | */ 61 | public Predicate build(String propertyName, Object value,SpecificationEntity entity); 62 | } 63 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/factory/BasicRepositoryFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.factory; 17 | 18 | import java.io.Serializable; 19 | 20 | import javax.persistence.EntityManager; 21 | 22 | import org.springframework.data.jpa.repository.JpaRepository; 23 | import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean; 24 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 25 | 26 | /** 27 | * 创建srping data jpa repository接口代理类的FactoryBean 28 | * 29 | * @author maurice 30 | * 31 | * @param repository 32 | */ 33 | public class BasicRepositoryFactoryBean> extends JpaRepositoryFactoryBean{ 34 | 35 | @Override 36 | protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) { 37 | 38 | return new BasicJpaRepositoryFactory(entityManager); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/EqRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import org.apache.commons.lang3.StringUtils; 23 | import com.github.dactiv.orm.core.MatchValue; 24 | import com.github.dactiv.orm.core.RestrictionNames; 25 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport; 26 | 27 | /** 28 | * 等于约束 (from object o where o.value = ?) RestrictionName:EQ 29 | *

30 | * 表达式:EQ属性类型_属性名称[_OR_属性名称...] 31 | *

32 | * 33 | * @author maurice 34 | * 35 | */ 36 | public class EqRestriction extends PredicateSingleValueSupport{ 37 | 38 | /* 39 | * (non-Javadoc) 40 | * @see com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport#getMatchValue(java.lang.String, java.lang.Class) 41 | */ 42 | public MatchValue getMatchValue(String matchValue, Class FieldType) { 43 | MatchValue matchValueModel = super.getMatchValue(matchValue, FieldType); 44 | for (int i = 0; i < matchValueModel.getValues().size(); i++) { 45 | Object value = matchValueModel.getValues().get(i); 46 | if (value instanceof String && StringUtils.equals(value.toString(),"null")) { 47 | matchValueModel.getValues().remove(i); 48 | matchValueModel.getValues().add(i, null); 49 | } 50 | } 51 | return matchValueModel; 52 | } 53 | 54 | /* 55 | * (non-Javadoc) 56 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 57 | */ 58 | public String getRestrictionName() { 59 | return RestrictionNames.EQ; 60 | } 61 | 62 | /* 63 | * (non-Javadoc) 64 | * @see com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 65 | */ 66 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 67 | 68 | return value == null ? builder.isNull(expression) : builder.equal(expression, value); 69 | } 70 | 71 | 72 | 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/GeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport; 24 | 25 | 26 | /** 27 | * 大于等于约束 (from object o where o.value >= ?)RestrictionName:GE 28 | *

29 | * 表达式:GE属性类型_属性名称[_OR_属性名称...] 30 | *

31 | * 32 | * @author maurice 33 | * 34 | */ 35 | public class GeRestriction extends PredicateSingleValueSupport{ 36 | 37 | /* 38 | * (non-Javadoc) 39 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 40 | */ 41 | public String getRestrictionName() { 42 | 43 | return RestrictionNames.GE; 44 | } 45 | 46 | /* 47 | * (non-Javadoc) 48 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 49 | */ 50 | @SuppressWarnings({ "rawtypes", "unchecked" }) 51 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 52 | 53 | return builder.greaterThanOrEqualTo(expression, (Comparable) value); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/GtRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport; 24 | 25 | /** 26 | * 大于约束 (from object o where o.value > ?)RestrictionName:GT 27 | *

28 | * 表达式:GT属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class GtRestriction extends PredicateSingleValueSupport{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | 42 | return RestrictionNames.GT; 43 | } 44 | 45 | /* 46 | * (non-Javadoc) 47 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 48 | */ 49 | @SuppressWarnings({ "rawtypes", "unchecked" }) 50 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 51 | 52 | return builder.greaterThan(expression,(Comparable) value); 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/InRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateMultipleValueSupport; 24 | 25 | /** 26 | * 包含约束 (from object o where o.value in (?,?,?,?,?))RestrictionName:IN 27 | *

28 | * 表达式:IN属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class InRestriction extends PredicateMultipleValueSupport{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | return RestrictionNames.IN; 42 | } 43 | 44 | /* 45 | * (non-Javadoc) 46 | * @see com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateMultipleValueSupport#buildRestriction(javax.persistence.criteria.Path, java.lang.Object[], javax.persistence.criteria.CriteriaBuilder) 47 | */ 48 | @SuppressWarnings("rawtypes") 49 | public Predicate buildRestriction(Path expression, Object[] values,CriteriaBuilder builder) { 50 | return expression.in(values); 51 | } 52 | 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/LLikeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport; 24 | 25 | /** 26 | * 左模糊约束 ( from object o where o.value like '%?') RestrictionName:LLIKE 27 | *

28 | * 表达式:LLIKE属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class LLikeRestriction extends PredicateSingleValueSupport{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | return RestrictionNames.LLIKE; 42 | } 43 | 44 | /* 45 | * (non-Javadoc) 46 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 47 | */ 48 | @SuppressWarnings({ "rawtypes", "unchecked" }) 49 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 50 | 51 | return builder.like(expression, "%" + value); 52 | } 53 | 54 | 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/LeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport; 24 | 25 | /** 26 | * 小于等于约束 ( from object o where o.value <= ?) RestrictionName:LR 27 | *

28 | * 表达式:LE属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class LeRestriction extends PredicateSingleValueSupport{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | 42 | return RestrictionNames.LE; 43 | } 44 | 45 | /* 46 | * (non-Javadoc) 47 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 48 | */ 49 | @SuppressWarnings({ "rawtypes", "unchecked" }) 50 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 51 | return builder.lessThanOrEqualTo(expression, (Comparable)value); 52 | } 53 | 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/LikeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport; 24 | 25 | /** 26 | * 模糊约束 ( from object o where o.value like '%?%') RestrictionName:LIKE 27 | *

28 | * 表达式:LIKE属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class LikeRestriction extends PredicateSingleValueSupport{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | return RestrictionNames.LIKE; 42 | } 43 | 44 | /* 45 | * (non-Javadoc) 46 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 47 | */ 48 | @SuppressWarnings({ "rawtypes", "unchecked" }) 49 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 50 | 51 | return builder.like(expression, "%" + value + "%"); 52 | } 53 | 54 | 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/LtRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport; 24 | 25 | /** 26 | * 小于约束 ( from object o where o.value < ?) RestrictionName:LT 27 | *

28 | * 表达式:LT属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class LtRestriction extends PredicateSingleValueSupport{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | return RestrictionNames.LT; 42 | } 43 | 44 | /* 45 | * (non-Javadoc) 46 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 47 | */ 48 | @SuppressWarnings({ "unchecked", "rawtypes" }) 49 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 50 | return builder.lessThan(expression, (Comparable)value); 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/NeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | 24 | 25 | /** 26 | * 不等于约束 ( from object o where o.value <> ?) RestrictionName:NE 27 | *

28 | * 表达式:NE属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class NeRestriction extends EqRestriction{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.restriction.support.EqRestriction#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | 42 | return RestrictionNames.NE; 43 | } 44 | 45 | /* 46 | * (non-Javadoc) 47 | * @see com.github.dactiv.orm.core.spring.data.jpa.restriction.support.EqRestriction#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 48 | */ 49 | @SuppressWarnings("rawtypes") 50 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 51 | 52 | return value == null ? builder.isNotNull(expression) : builder.notEqual(expression, value); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/NinRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateMultipleValueSupport; 24 | 25 | /** 26 | * 不包含约束 (from object o where o.value not in (?,?,?,?,?))RestrictionName:NIN 27 | *

28 | * 表达式:NIN属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class NinRestriction extends PredicateMultipleValueSupport{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | 42 | return RestrictionNames.NIN; 43 | } 44 | 45 | /* 46 | * (non-Javadoc) 47 | * @see com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateMultipleValueSupport#buildRestriction(javax.persistence.criteria.Path, java.lang.Object[], javax.persistence.criteria.CriteriaBuilder) 48 | */ 49 | public Predicate buildRestriction(Path expression, Object[] values,CriteriaBuilder builder) { 50 | 51 | return builder.not(expression.in(values)); 52 | } 53 | 54 | 55 | 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/restriction/support/RLikeRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.restriction.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.Path; 20 | import javax.persistence.criteria.Predicate; 21 | 22 | import com.github.dactiv.orm.core.RestrictionNames; 23 | import com.github.dactiv.orm.core.spring.data.jpa.restriction.PredicateSingleValueSupport; 24 | 25 | /** 26 | * 右模糊约束 ( from object o where o.value like '?%') RestrictionName:RLIKE 27 | *

28 | * 表达式:RLIKE属性类型_属性名称[_OR_属性名称...] 29 | *

30 | * 31 | * @author maurice 32 | * 33 | */ 34 | public class RLikeRestriction extends PredicateSingleValueSupport{ 35 | 36 | /* 37 | * (non-Javadoc) 38 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#getRestrictionName() 39 | */ 40 | public String getRestrictionName() { 41 | return RestrictionNames.RLIKE; 42 | } 43 | 44 | /* 45 | * (non-Javadoc) 46 | * @see com.github.dactiv.orm.core.spring.data.jpa.PredicateBuilder#build(javax.persistence.criteria.Path, java.lang.Object, javax.persistence.criteria.CriteriaBuilder) 47 | */ 48 | @SuppressWarnings({ "unchecked", "rawtypes" }) 49 | public Predicate build(Path expression, Object value,CriteriaBuilder builder) { 50 | 51 | return builder.like(expression, value + "%"); 52 | } 53 | 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/specification/SpecificationEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.specification; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.CriteriaQuery; 20 | import javax.persistence.criteria.Root; 21 | 22 | /** 23 | * jpa查询绑定载体,辅助属性过滤器查询时需要的jpa属性 24 | * 25 | * @author maurice 26 | * 27 | */ 28 | public class SpecificationEntity { 29 | 30 | private Root root; 31 | private CriteriaQuery query; 32 | private CriteriaBuilder builder; 33 | 34 | public SpecificationEntity() { 35 | 36 | } 37 | 38 | public SpecificationEntity(Root root, CriteriaQuery query, CriteriaBuilder builder) { 39 | super(); 40 | this.root = root; 41 | this.query = query; 42 | this.builder = builder; 43 | } 44 | 45 | public Root getRoot() { 46 | return root; 47 | } 48 | 49 | public void setRoot(Root root) { 50 | this.root = root; 51 | } 52 | 53 | public CriteriaQuery getQuery() { 54 | return query; 55 | } 56 | 57 | public void setQuery(CriteriaQuery query) { 58 | this.query = query; 59 | } 60 | 61 | public CriteriaBuilder getBuilder() { 62 | return builder; 63 | } 64 | 65 | public void setBuilder(CriteriaBuilder builder) { 66 | this.builder = builder; 67 | } 68 | 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/specification/support/PropertyFilterSpecification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.specification.support; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import javax.persistence.criteria.CriteriaBuilder; 22 | import javax.persistence.criteria.CriteriaQuery; 23 | import javax.persistence.criteria.Predicate; 24 | import javax.persistence.criteria.Root; 25 | 26 | import com.github.dactiv.orm.core.PropertyFilter; 27 | import com.github.dactiv.orm.core.spring.data.jpa.JpaRestrictionBuilder; 28 | import com.github.dactiv.orm.core.spring.data.jpa.specification.SpecificationEntity; 29 | import org.springframework.data.jpa.domain.Specification; 30 | 31 | /** 32 | * 实现spring data jpa的{@link Specification}接口,通过该类支持{@link PropertyFilter}以及表达式查询方法 33 | * 34 | * @author maurice 35 | * 36 | * @param orm对象 37 | */ 38 | public class PropertyFilterSpecification implements Specification { 39 | 40 | private List filters = new ArrayList(); 41 | 42 | public PropertyFilterSpecification() { 43 | 44 | } 45 | 46 | /** 47 | * 通过属性过滤器构建 48 | * 49 | * @param filter 属性过滤器 50 | */ 51 | public PropertyFilterSpecification(PropertyFilter filter) { 52 | this.filters.add(filter); 53 | } 54 | 55 | /** 56 | * 通过属性过滤器集合构建 57 | * 58 | * @param filters 集合 59 | */ 60 | public PropertyFilterSpecification(List filters) { 61 | this.filters.addAll(filters); 62 | } 63 | 64 | /* 65 | * (non-Javadoc) 66 | * @see org.springframework.data.jpa.domain.Specification#toPredicate(javax.persistence.criteria.Root, javax.persistence.criteria.CriteriaQuery, javax.persistence.criteria.CriteriaBuilder) 67 | */ 68 | public Predicate toPredicate(Root root, CriteriaQuery query,CriteriaBuilder builder) { 69 | 70 | 71 | List list = new ArrayList(); 72 | 73 | for (PropertyFilter filter : filters) { 74 | list.add(JpaRestrictionBuilder.getRestriction(filter,new SpecificationEntity(root, query, builder))); 75 | } 76 | 77 | return list.size() > 0 ? builder.and(list.toArray(new Predicate[list.size()])) : null; 78 | 79 | } 80 | 81 | /** 82 | * 获取所有属性过滤器 83 | * 84 | * @return List 85 | */ 86 | public List getFilters() { 87 | return filters; 88 | } 89 | 90 | /** 91 | * 设置所有属性过滤器 92 | * 93 | * @param filters 属性过滤器 94 | */ 95 | public void setFilters(List filters) { 96 | this.filters = filters; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /dactiv-orm/src/main/java/com/github/dactiv/orm/core/spring/data/jpa/specification/support/PropertySpecification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.github.dactiv.orm.core.spring.data.jpa.specification.support; 17 | 18 | import javax.persistence.criteria.CriteriaBuilder; 19 | import javax.persistence.criteria.CriteriaQuery; 20 | import javax.persistence.criteria.Predicate; 21 | import javax.persistence.criteria.Root; 22 | 23 | import com.github.dactiv.orm.core.RestrictionNames; 24 | import com.github.dactiv.orm.core.spring.data.jpa.JpaRestrictionBuilder; 25 | import com.github.dactiv.orm.core.spring.data.jpa.specification.SpecificationEntity; 26 | import org.springframework.data.jpa.domain.Specification; 27 | 28 | /** 29 | * 实现spring data jpa的{@link Specification}接口,通过该类支持对象属性名查询方法 30 | * 31 | * @author maurice 32 | * 33 | * @param orm 对象 34 | */ 35 | public class PropertySpecification implements Specification{ 36 | 37 | //属性名称 38 | private String propertyName; 39 | //值 40 | private Object value; 41 | //约束名称 42 | private String restrictionName; 43 | 44 | public PropertySpecification() { 45 | 46 | } 47 | 48 | /** 49 | * 构造属性名查询Specification 50 | * 51 | * @param propertyName 对象属性名 52 | * @param value 值 53 | */ 54 | public PropertySpecification(String propertyName, Object value) { 55 | this.propertyName = propertyName; 56 | this.value = value; 57 | this.restrictionName = RestrictionNames.EQ; 58 | } 59 | 60 | /** 61 | * 构造属性名查询Specification 62 | * 63 | * @param propertyName 对象属性名 64 | * @param value 值 65 | * @param restrictionName 约束名称 66 | */ 67 | public PropertySpecification(String propertyName, Object value,String restrictionName) { 68 | this.propertyName = propertyName; 69 | this.value = value; 70 | this.restrictionName = restrictionName; 71 | } 72 | 73 | /* 74 | * (non-Javadoc) 75 | * @see org.springframework.data.jpa.domain.Specification#toPredicate(javax.persistence.criteria.Root, javax.persistence.criteria.CriteriaQuery, javax.persistence.criteria.CriteriaBuilder) 76 | */ 77 | public Predicate toPredicate(Root root, CriteriaQuery query,CriteriaBuilder builder) { 78 | 79 | 80 | Predicate predicate = builder.and(JpaRestrictionBuilder.getRestriction(propertyName, value, restrictionName, new SpecificationEntity(root, query, builder))); 81 | 82 | 83 | return predicate; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/java/com/github/dactiv/orm/test/CreateTestInitializeDataBaseSqlFile.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.orm.test; 2 | 3 | import org.hibernate.cfg.Configuration; 4 | import org.hibernate.cfg.ImprovedNamingStrategy; 5 | import org.hibernate.tool.EnversSchemaGenerator; 6 | import org.hibernate.tool.hbm2ddl.SchemaExport; 7 | 8 | public class CreateTestInitializeDataBaseSqlFile { 9 | 10 | public static void main(String[] args) { 11 | 12 | Configuration configuration = new Configuration().configure().setNamingStrategy(new ImprovedNamingStrategy()); 13 | EnversSchemaGenerator generator = new EnversSchemaGenerator(configuration); 14 | SchemaExport export = generator.export(); 15 | 16 | export.setFormat(false); 17 | export.setOutputFile("src/test/resources/h2schma.sql"); 18 | export.create(true, false); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/java/com/github/dactiv/orm/test/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.orm.test.entity; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.CascadeType; 6 | import javax.persistence.Entity; 7 | import javax.persistence.FetchType; 8 | import javax.persistence.JoinColumn; 9 | import javax.persistence.ManyToOne; 10 | import javax.persistence.NamedQueries; 11 | import javax.persistence.NamedQuery; 12 | import javax.persistence.OneToMany; 13 | import javax.persistence.Table; 14 | 15 | 16 | @Entity 17 | @Table(name="TB_ACCOUNT_MENU") 18 | @NamedQueries({ 19 | @NamedQuery(name="QueryUserMenuJpa",query="select ml from " + 20 | "User u left join u.roleList rl " + 21 | "left join rl.menuList ml " + 22 | "where u.id=?1 and u.state=?2"), 23 | @NamedQuery(name="QueryUserMenu",query="select ml from " + 24 | "User u left join u.roleList rl " + 25 | "left join rl.menuList ml " + 26 | "where u.id=? and u.state=?") 27 | }) 28 | public class Menu extends UniversallyUniqueIdentifier{ 29 | //名称 30 | private String name; 31 | //所属父类 32 | private Menu parent; 33 | //拥有子菜单 34 | private List childerList; 35 | 36 | private int type; 37 | 38 | /** 39 | * 构造方法 40 | */ 41 | public Menu() { 42 | 43 | } 44 | 45 | /** 46 | * 获取菜单名称 47 | * @return String 48 | */ 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | /** 54 | * 设置菜单名称 55 | * @param name 菜单名称 56 | */ 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | 61 | /** 62 | * 获取父类菜单 63 | * @return {@link Menu} 64 | */ 65 | @ManyToOne 66 | @JoinColumn(name = "FK_PARENT_ID") 67 | public Menu getParent() { 68 | return parent; 69 | } 70 | 71 | /** 72 | * 设置父类菜单 73 | * @param parent 父类菜单 74 | */ 75 | public void setParent(Menu parent) { 76 | this.parent = parent; 77 | } 78 | 79 | /** 80 | * 获取子菜单 81 | * @return List 82 | */ 83 | @OneToMany(mappedBy = "parent",cascade={CascadeType.ALL},fetch=FetchType.LAZY) 84 | public List getChilderList() { 85 | return childerList; 86 | } 87 | 88 | /** 89 | * 设置子菜单 90 | * @param childerList 子菜单 91 | */ 92 | public void setChilderList(List childerList) { 93 | this.childerList = childerList; 94 | } 95 | 96 | public int getType() { 97 | return type; 98 | } 99 | 100 | public void setType(int type) { 101 | this.type = type; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/java/com/github/dactiv/orm/test/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.orm.test.entity; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.JoinColumn; 7 | import javax.persistence.JoinTable; 8 | import javax.persistence.ManyToMany; 9 | import javax.persistence.Table; 10 | 11 | @Entity 12 | @Table(name="TB_ACCOUNT_ROLE") 13 | public class Role extends UniversallyUniqueIdentifier{ 14 | //角色名称 15 | private String name; 16 | //拥有菜单 17 | private List menuList; 18 | 19 | /** 20 | * 构造方法 21 | */ 22 | 23 | public Role() { 24 | 25 | } 26 | 27 | /** 28 | * 获取角色名称 29 | * @return String 30 | */ 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | /** 36 | * 设置角色名称 37 | * @param name 38 | */ 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | @ManyToMany 44 | @JoinTable(name = "TB_ACCOUNT_ROLE_MENU", joinColumns = { @JoinColumn(name = "ROLE_ID") }, inverseJoinColumns = { @JoinColumn(name = "MENU_ID") }) 45 | public List getMenuList() { 46 | return menuList; 47 | } 48 | 49 | public void setMenuList(List menuList) { 50 | this.menuList = menuList; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/java/com/github/dactiv/orm/test/entity/UniversallyUniqueIdentifier.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.orm.test.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | import javax.persistence.MappedSuperclass; 7 | 8 | import org.hibernate.annotations.GenericGenerator; 9 | 10 | @MappedSuperclass 11 | public class UniversallyUniqueIdentifier { 12 | 13 | private String id; 14 | 15 | @Id 16 | @Column(length = 32) 17 | @GeneratedValue(generator = "system-uuid") 18 | @GenericGenerator(name = "system-uuid", strategy = "uuid") 19 | public String getId() { 20 | return this.id; 21 | } 22 | 23 | public void setId(String id) { 24 | this.id = id; 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/java/com/github/dactiv/orm/test/simple/hibernate/BasicHiberanteDaoSimple.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.orm.test.simple.hibernate; 2 | 3 | import com.github.dactiv.orm.core.hibernate.support.BasicHibernateDao; 4 | import com.github.dactiv.orm.test.entity.User; 5 | import org.springframework.stereotype.Repository; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | @Repository 9 | @Transactional 10 | public class BasicHiberanteDaoSimple extends BasicHibernateDao{ 11 | 12 | } 13 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/java/com/github/dactiv/orm/test/simple/hibernate/HibernateDaoSimple.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.orm.test.simple.hibernate; 2 | 3 | import com.github.dactiv.orm.core.hibernate.support.HibernateSupportDao; 4 | import com.github.dactiv.orm.test.entity.User; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public class HibernateDaoSimple extends HibernateSupportDao{ 9 | 10 | } 11 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/java/com/github/dactiv/orm/test/simple/jpa/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.orm.test.simple.jpa; 2 | 3 | import com.github.dactiv.orm.test.entity.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 6 | 7 | public interface UserRepository extends JpaRepository,JpaSpecificationExecutor{ 8 | 9 | } 10 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/resources/h2schma.sql: -------------------------------------------------------------------------------- 1 | alter table tb_account_menu drop constraint FK_nir9pgetp3fr0lu4ka40dd9hc 2 | alter table tb_account_role_menu drop constraint FK_77450a4wnla3lbrl3d83al71s 3 | alter table tb_account_role_menu drop constraint FK_ji2m1uttj9kokkqymf2wykcv5 4 | alter table tb_account_user_aud drop constraint FK_cedx9xim5n5a5ivs4hvkq3e72 5 | alter table tb_account_user_role drop constraint FK_remu85m5drp204gq5a0lgotn7 6 | alter table tb_account_user_role drop constraint FK_rnvr7n8jn0oeu1k77togn0bkv 7 | drop table revinfo if exists 8 | drop table tb_account_menu if exists 9 | drop table tb_account_role if exists 10 | drop table tb_account_role_menu if exists 11 | drop table tb_account_user if exists 12 | drop table tb_account_user_aud if exists 13 | drop table tb_account_user_role if exists 14 | create table revinfo (rev integer generated by default as identity, revtstmp bigint, primary key (rev)) 15 | create table tb_account_menu (id varchar(32) not null, name varchar(255), type integer not null, fk_parent_id varchar(32), primary key (id)) 16 | create table tb_account_role (id varchar(32) not null, name varchar(255), primary key (id)) 17 | create table tb_account_role_menu (role_id varchar(32) not null, menu_id varchar(32) not null) 18 | create table tb_account_user (id varchar(32) not null, create_time timestamp, login_name varchar(255), password varchar(255), pinyin_code varchar(255), real_name varchar(255), state integer, wubi_code varchar(255), primary key (id)) 19 | create table tb_account_user_aud (id varchar(32) not null, rev integer not null, revtype tinyint, create_time timestamp, login_name varchar(255), password varchar(255), pinyin_code varchar(255), real_name varchar(255), state integer, wubi_code varchar(255), primary key (id, rev)) 20 | create table tb_account_user_role (user_id varchar(32) not null, role_id varchar(32) not null) 21 | alter table tb_account_menu add constraint FK_nir9pgetp3fr0lu4ka40dd9hc foreign key (fk_parent_id) references tb_account_menu 22 | alter table tb_account_role_menu add constraint FK_77450a4wnla3lbrl3d83al71s foreign key (menu_id) references tb_account_menu 23 | alter table tb_account_role_menu add constraint FK_ji2m1uttj9kokkqymf2wykcv5 foreign key (role_id) references tb_account_role 24 | alter table tb_account_user_aud add constraint FK_cedx9xim5n5a5ivs4hvkq3e72 foreign key (rev) references revinfo 25 | alter table tb_account_user_role add constraint FK_remu85m5drp204gq5a0lgotn7 foreign key (role_id) references tb_account_role 26 | alter table tb_account_user_role add constraint FK_rnvr7n8jn0oeu1k77togn0bkv foreign key (user_id) references tb_account_user 27 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/resources/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | org.h2.Driver 11 | 12 | sa 13 | 14 | 15 | org.hibernate.dialect.H2Dialect 16 | 17 | 18 | jdbc:h2:mem:dactiv-orm;DB_CLOSE_DELAY=-1 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /dactiv-orm/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d [%t] %-5p [%c:%L] - %m%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dactiv-parent/README.md: -------------------------------------------------------------------------------- 1 | ###项目说明 2 | 3 | 该parent项目为base-framework的基础父类项目,里面的pom仅仅是配置了常用的依赖jar包,由dactiv-orm、dactiv-common继承后使用,而install是起到对该项目重新编译到本地maven库的作用。 4 | 5 | -------------------------------------------------------------------------------- /dactiv-parent/install.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] Install jar to local repository. 3 | 4 | cd %~dp0 5 | call mvn clean install -Dmaven.test.skip=true 6 | pause -------------------------------------------------------------------------------- /doc/md/common 使用说明.md: -------------------------------------------------------------------------------- 1 | #### dactiv common 使用说明 #### -------------------------------------------------------------------------------- /doc/md/orm 使用说明.md: -------------------------------------------------------------------------------- 1 | #### dactiv orm 使用说明 #### 2 | -------------------------------------------------------------------------------- /doc/md/shrio 实用功能说明.md: -------------------------------------------------------------------------------- 1 | ### shrio 实用功能说明 ### 2 | 3 | apache shiro 是功能强大并且容易集成的开源权限框架,它能够完成认证、授权、加密、会话管理等功能。认证和授权为权限控制的核心,简单来说,“认证”就是证明"你是谁?" Web 应用程序一般做法是通过表单提交的用户名及密码达到认证目的。“授权”即是"你能做什么?",很多系统通过资源表的形式来完成用户能做什么。关于 shiro 的一系列特征及优点,很多文章已有列举,这里不再逐一赘述,本文首先会简单的讲述shiro和spring该如何集成,重点介绍 shiro 的几个实用功能和一些 shiro 的扩张知识。 4 | 5 | #### shiro 集成 spring #### 6 | 7 | #### shiro 认证、授权 #### 8 | 9 | #### 动态filterChainDefinitions #### 10 | 11 | #### 扩张 filter 实现验证码登录 #### 12 | 13 | #### 更好性能的 shiro + cache #### 14 | 15 | #### 定义 AuthorizationRealm 抽象类,让多 realms 授权得到统一 #### 16 | -------------------------------------------------------------------------------- /doc/md/spring mvc 实用功能说明.md: -------------------------------------------------------------------------------- 1 | #### spring mvc 实用功能说明 #### -------------------------------------------------------------------------------- /doc/reference.md: -------------------------------------------------------------------------------- 1 | ### spring mvc 实用功能说明 ### 2 | 3 | ### shiro 实用功能说明 ### 4 | 5 | ### dactiv orm 使用说明 ### 6 | 7 | ### dativ common 使用说明 ### -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 4.0.0 8 | com.github.dactiv 9 | base-framework-project 10 | 1.0.0-SNAPSHOT 11 | base web framework project 12 | pom 13 | 14 | base-framework is a base framework based on spring,hibernate,spring mvc,shiro. 15 | http://dactiv.github.com/base-framework 16 | 17 | 18 | 19 | Apache License, Version 2.0 20 | http://www.apache.org/licenses/LICENSE-2.0 21 | 22 | 23 | 24 | 25 | github 26 | https://github.com/dactiv/base-framework/issues 27 | 28 | 29 | 30 | 31 | dactiv 32 | Maurice Chen 33 | es.chenxiaobo@gmail.com 34 | +8 35 | 36 | 37 | 38 | 39 | git@github.com:dactiv/base-framework.git 40 | scm:git:git@github.com:dactiv/base-framework.git 41 | scm:git:git@github.com:dactiv/base-framework.git 42 | 43 | 44 | 45 | dactiv-parent 46 | dactiv-common 47 | dactiv-orm 48 | showcase/base-curd 49 | 50 | 51 | -------------------------------------------------------------------------------- /quick-start.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set base_path=%cd% 4 | 5 | echo [INFO] install jar to local m2 repository. 6 | 7 | call mvn clean source:jar install -Dmaven.test.skip=true 8 | 9 | echo [INFO] create base curd project archetype. 10 | 11 | cd %base_path%\showcase\base-curd 12 | call mvn archetype:create-from-project 13 | 14 | echo [INFO] install base curd archetype to local m2 repository 15 | 16 | cd %base_path%\showcase\base-curd\target\generated-sources\archetype 17 | call mvn clean install -Dmaven.test.skip=true 18 | 19 | cd %base_path%\showcase\base-curd 20 | rd /S /Q target 21 | 22 | echo [INFO] init h2 data 23 | 24 | call mvn antrun:run 25 | 26 | echo [INFO] start base curd app 27 | 28 | start "base curd" mvn clean jetty:run 29 | 30 | echo [INFO] Please wait a moment. When you see "[INFO] Started Jetty Server", you can visit: http://localhost:8080/base-curd/ to view the demo 31 | 32 | cd %base_path% 33 | 34 | pause -------------------------------------------------------------------------------- /showcase/base-curd/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /showcase/base-curd/bin/README.md: -------------------------------------------------------------------------------- 1 | ###工具说明 2 | 3 | eclipse:将项目生成为eclipse项目 4 | 5 | idea:将项目生成为idea项目 6 | 7 | myeclipse:将项目生成为myeclipse项目 8 | 9 | install:将该项目所有的依赖初始化到本地m2库 10 | 11 | archetype-generate:将base-curd项目为模板,生成新的项目 12 | 13 | jetty:启动base-curd项目,启动完成后通过http://localhost:8080访问 14 | 15 | reset-db:重置base-curd项目的数据 16 | 17 | war:将项目打包成.war文件 18 | 19 | -------------------------------------------------------------------------------- /showcase/base-curd/bin/archetype-generate.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] archetype create from project 3 | 4 | if not exist generated-sources (md generated-sources) 5 | 6 | cd generated-sources 7 | 8 | call mvn archetype:generate -DarchetypeCatalog=local -DarchetypeGroupId=com.github.dactiv.showcase -DarchetypeArtifactId=base-curd-archetype -DarchetypeVersion=1.3.0-SNAPSHOT 9 | 10 | cd .. 11 | 12 | pause -------------------------------------------------------------------------------- /showcase/base-curd/bin/eclipse.bat: -------------------------------------------------------------------------------- 1 | 2 | @echo off 3 | echo [INFO] create project to eclipse 4 | 5 | cd %~dp0 6 | cd .. 7 | call mvn clean eclipse:eclipse 8 | cd bin 9 | pause 10 | -------------------------------------------------------------------------------- /showcase/base-curd/bin/idea.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] create project to idea 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn clean idea:idea 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /showcase/base-curd/bin/install.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] Install jar to local repository. 3 | 4 | cd %~dp0 5 | cd .. 6 | call mvn clean source:jar install -Dmaven.test.skip=true 7 | cd bin 8 | pause -------------------------------------------------------------------------------- /showcase/base-curd/bin/jetty.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] Use maven jetty-plugin run the project. 3 | 4 | cd %~dp0 5 | cd .. 6 | 7 | call mvn jetty:run 8 | 9 | cd bin 10 | pause -------------------------------------------------------------------------------- /showcase/base-curd/bin/myeclipse.bat: -------------------------------------------------------------------------------- 1 | 2 | @echo off 3 | echo [INFO] create project to myeclipse 4 | 5 | cd %~dp0 6 | cd .. 7 | call mvn clean eclipse:myeclipse 8 | cd bin 9 | pause 10 | -------------------------------------------------------------------------------- /showcase/base-curd/bin/reset-db.bat: -------------------------------------------------------------------------------- 1 | 2 | @echo off 3 | echo [INFO] reset database data 4 | 5 | cd %~dp0 6 | cd .. 7 | call mvn antrun:run 8 | cd bin 9 | pause 10 | -------------------------------------------------------------------------------- /showcase/base-curd/bin/war.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo [INFO] Use maven jetty-plugin run the project. 3 | 4 | cd %~dp0 5 | cd .. 6 | 7 | call mvn war:war 8 | 9 | cd bin 10 | pause -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/common/SessionVariable.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.common; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | import com.github.dactiv.showcase.entity.account.Group; 7 | import com.github.dactiv.showcase.entity.account.Resource; 8 | import com.github.dactiv.showcase.entity.account.User; 9 | 10 | /** 11 | * 12 | * 系统常用变量模型实体 13 | * 14 | * @author maurice 15 | * 16 | */ 17 | public class SessionVariable implements Serializable { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | 22 | // 当前用户 23 | private User user; 24 | 25 | // 当前用户所在的组集合 26 | private List groupsList; 27 | 28 | // 当前用户的授权资源集合 29 | private List authorizationInfo; 30 | 31 | // 当前用户的菜单集合 32 | private List menusList; 33 | 34 | public SessionVariable() { 35 | 36 | } 37 | 38 | public SessionVariable(User user) { 39 | this.user = user; 40 | } 41 | 42 | public SessionVariable(User user, List groupsList,List authorizationInfo, List menusList) { 43 | this.user = user; 44 | this.groupsList = groupsList; 45 | this.authorizationInfo = authorizationInfo; 46 | this.menusList = menusList; 47 | } 48 | 49 | /** 50 | * 获取当前用户 51 | * 52 | * @return {@link User} 53 | */ 54 | public User getUser() { 55 | return user; 56 | } 57 | 58 | /** 59 | * 设置当前用户 60 | * 61 | * @param user 当前用户 62 | */ 63 | public void setUser(User user) { 64 | this.user = user; 65 | } 66 | 67 | /** 68 | * 获取当前用户所在的组集合 69 | * 70 | * @return List 71 | */ 72 | public List getGroupsList() { 73 | return groupsList; 74 | } 75 | 76 | /** 77 | * 设置当前用户所在的组集合 78 | * 79 | * @param groupsList 组集合 80 | */ 81 | public void setGroupsList(List groupsList) { 82 | this.groupsList = groupsList; 83 | } 84 | 85 | /** 86 | * 获取当前用户的所有授权资源集合 87 | * 88 | * @return List 89 | */ 90 | public List getAuthorizationInfo() { 91 | return authorizationInfo; 92 | } 93 | 94 | /** 95 | * 设置当前用户的所有授权资源集合 96 | * 97 | * @param authorizationInfo 资源集合 98 | */ 99 | public void setAuthorizationInfo(List authorizationInfo) { 100 | this.authorizationInfo = authorizationInfo; 101 | } 102 | 103 | /** 104 | * 获取当前用户拥有的菜单集合 105 | * 106 | * @return List 107 | */ 108 | public List getMenusList() { 109 | return menusList; 110 | } 111 | 112 | /** 113 | * 设置当前用户拥有的菜单集合 114 | * 115 | * @param menusList 资源集合 116 | */ 117 | public void setMenusList(List menusList) { 118 | this.menusList = menusList; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/common/annotation/OperatingAudit.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.common.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import com.github.dactiv.showcase.service.foundation.OperatingRecordAspect; 9 | import com.github.dactiv.showcase.web.account.UserController; 10 | 11 | /** 12 | * 操作审计注解,通过该注解,在类或方法中使用,当调用到该方法时 13 | * 会引起一次aop,就是{@link OperatingRecordAspect}类,通过该类在调用 14 | * 之后都会做一次记录,并个把所有的记录存储在TB_OPERATING_RECORD 15 | * 表中,详细例子:{@link UserController} 16 | * 17 | * @author maurice 18 | * 19 | */ 20 | @Target({ElementType.METHOD, ElementType.TYPE}) 21 | @Retention(RetentionPolicy.RUNTIME) 22 | public @interface OperatingAudit { 23 | 24 | /** 25 | * 模块名称,默认为""值,可以在类中说明该类是什么模块 26 | * 27 | */ 28 | String value() default ""; 29 | 30 | /** 31 | * 功能名称 默认为""值,主要是在类的方法中说明该方法是什么功能 32 | * 33 | */ 34 | String function() default ""; 35 | } 36 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/common/enumeration/SystemDictionaryCode.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.common.enumeration; 2 | 3 | /** 4 | * 字典类型枚举 5 | * 6 | * @author maurice 7 | * 8 | */ 9 | public enum SystemDictionaryCode { 10 | 11 | /** 12 | * 状态类型 13 | */ 14 | State("state"), 15 | 16 | /** 17 | * 资源类型 18 | */ 19 | ResourceType("resource-type"), 20 | 21 | /** 22 | * 组类型 23 | */ 24 | GroupType("group-type"), 25 | 26 | /** 27 | * 属性值类型 28 | */ 29 | ValueType("value-type"), 30 | 31 | /** 32 | * 操作状态类型 33 | */ 34 | OperatingState("operating-state"); 35 | 36 | private String code; 37 | 38 | private SystemDictionaryCode(String code) { 39 | this.code = code; 40 | } 41 | 42 | /** 43 | * 获取类型代码 44 | * 45 | * @return String 46 | */ 47 | public String getCode() { 48 | return this.code; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/common/enumeration/ValueEnum.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.common.enumeration; 2 | 3 | /** 4 | * 针对键为String值任意Object类型的枚举接口父类 5 | * 6 | * @author maurice 7 | * 8 | * @param 9 | */ 10 | public interface ValueEnum { 11 | 12 | /** 13 | * 获取值 14 | * 15 | * @return Object 16 | */ 17 | public V getValue(); 18 | 19 | /** 20 | * 获取名称 21 | * 22 | * @return String 23 | */ 24 | public String getName(); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/common/enumeration/entity/GroupType.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.common.enumeration.entity; 2 | 3 | import com.github.dactiv.showcase.common.enumeration.ValueEnum; 4 | 5 | /** 6 | * 组类型 7 | * 8 | * @author maurice 9 | * 10 | */ 11 | public enum GroupType implements ValueEnum{ 12 | 13 | /** 14 | * 机构类型 15 | */ 16 | Organization("01","机构"), 17 | /** 18 | * 部门类型 19 | */ 20 | Department("02","部门"), 21 | /** 22 | * 角色组类型 23 | */ 24 | RoleGorup("03","角色组"); 25 | 26 | private GroupType(String value,String name) { 27 | this.value = value; 28 | this.name = name; 29 | } 30 | 31 | private String value; 32 | 33 | private String name; 34 | 35 | /** 36 | * 获取类型值 37 | * 38 | * @return String 39 | */ 40 | public String getValue() { 41 | return value; 42 | } 43 | 44 | /** 45 | * 获取类型名称 46 | * 47 | * @return String 48 | */ 49 | public String getName() { 50 | return name; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/common/enumeration/entity/OperatingState.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.common.enumeration.entity; 2 | 3 | import com.github.dactiv.showcase.common.enumeration.ValueEnum; 4 | 5 | /** 6 | * 操作状态 7 | * 8 | * @author maurice 9 | * 10 | */ 11 | public enum OperatingState implements ValueEnum{ 12 | /** 13 | * 成功 14 | */ 15 | Success(1,"成功"), 16 | /** 17 | * 失败 18 | */ 19 | Fail(2,"失败"); 20 | 21 | //值 22 | private Integer value; 23 | //名称 24 | private String name; 25 | 26 | private OperatingState(Integer value,String name) { 27 | this.value = value; 28 | this.name = name; 29 | } 30 | 31 | /** 32 | * 获取值 33 | * @return Integer 34 | */ 35 | public Integer getValue() { 36 | return value; 37 | } 38 | 39 | /** 40 | * 获取名称 41 | * @return String 42 | */ 43 | public String getName() { 44 | return name; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/common/enumeration/entity/ResourceType.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.common.enumeration.entity; 2 | 3 | import com.github.dactiv.showcase.common.enumeration.ValueEnum; 4 | 5 | /** 6 | * 资源类型枚举 7 | * 8 | * @author maurice 9 | * 10 | */ 11 | public enum ResourceType implements ValueEnum{ 12 | 13 | /** 14 | * 菜单类型,该类型为用户可以见的 15 | */ 16 | Menu("01","菜单类型"), 17 | /** 18 | * 安全类型,该类型为shiro拦截的并且用户不可见的 19 | */ 20 | Security("02","安全类型"); 21 | 22 | ResourceType(String value,String name) { 23 | this.name = name; 24 | this.value = value; 25 | } 26 | 27 | private String name; 28 | 29 | private String value; 30 | 31 | /** 32 | * 获取资源类型名称 33 | * @return String 34 | */ 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | /** 40 | * 获取资源类型值 41 | * @return 42 | */ 43 | public String getValue() { 44 | return value; 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/common/enumeration/entity/State.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.common.enumeration.entity; 2 | 3 | import com.github.dactiv.showcase.common.enumeration.ValueEnum; 4 | 5 | /** 6 | * 状态枚举 7 | * 8 | * @author maurice 9 | * 10 | */ 11 | public enum State implements ValueEnum{ 12 | 13 | /** 14 | * 启用 15 | */ 16 | Enable(1,"启用"), 17 | /** 18 | * 禁用 19 | */ 20 | Disable(2,"禁用"), 21 | /** 22 | * 删除 23 | */ 24 | Delete(3,"删除"); 25 | 26 | //值 27 | private Integer value; 28 | //名称 29 | private String name; 30 | 31 | private State(Integer value,String name) { 32 | this.value = value; 33 | this.name = name; 34 | } 35 | 36 | /** 37 | * 获取值 38 | * @return Integer 39 | */ 40 | public Integer getValue() { 41 | return value; 42 | } 43 | 44 | /** 45 | * 获取名称 46 | * @return String 47 | */ 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/dao/account/GroupDao.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.dao.account; 2 | 3 | import java.util.List; 4 | 5 | import com.github.dactiv.orm.core.hibernate.support.HibernateSupportDao; 6 | import com.github.dactiv.showcase.entity.account.Group; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * 部门数据访问 11 | * 12 | * @author maurice 13 | * 14 | */ 15 | @Repository 16 | public class GroupDao extends HibernateSupportDao{ 17 | 18 | /** 19 | * 通过用户id获取所有资源 20 | * 21 | * @param userId 用户id 22 | * 23 | * @return List 24 | */ 25 | public List getUserGorups(String userId) { 26 | return findByQuery(Group.UserGroups, userId); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/dao/account/ResourceDao.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.dao.account; 2 | 3 | import java.util.List; 4 | 5 | import com.github.dactiv.orm.core.hibernate.support.HibernateSupportDao; 6 | import com.github.dactiv.showcase.entity.account.Resource; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * 资源数据访问 11 | * 12 | * @author maurice 13 | * 14 | */ 15 | @Repository 16 | public class ResourceDao extends HibernateSupportDao{ 17 | 18 | /** 19 | * 通过用户id获取用户所有资源 20 | * 21 | * @param userId 用户id 22 | * 23 | * @return List 24 | */ 25 | public List getUserResources(String userId) { 26 | return distinct(Resource.UserResources, userId); 27 | } 28 | 29 | /** 30 | * 刷新一次Resource的leaf字段,如果该leaf = 1 并且该资源没有子类,把该资源的leaf改成0 31 | */ 32 | public void refreshAllLeaf() { 33 | List list = findByQuery(Resource.LeafTureNotAssociated); 34 | for (Resource entity : list) { 35 | entity.setLeaf(false); 36 | save(entity); 37 | } 38 | 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/dao/account/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.dao.account; 2 | 3 | import com.github.dactiv.orm.core.hibernate.support.HibernateSupportDao; 4 | import com.github.dactiv.showcase.entity.account.User; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * 用户数据访问 9 | * @author maurice 10 | * 11 | */ 12 | @Repository 13 | public class UserDao extends HibernateSupportDao{ 14 | 15 | /** 16 | * 通过用户id更新用户密码 17 | * 18 | * @param userId 用户id 19 | * @param password 密码 20 | */ 21 | public void updatePassword(String userId, String password) { 22 | executeUpdate(User.UpdatePassword, password,userId); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/dao/foundation/audit/OperatingRecordDao.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.dao.foundation.audit; 2 | 3 | import com.github.dactiv.orm.core.hibernate.support.HibernateSupportDao; 4 | import com.github.dactiv.showcase.entity.foundation.audit.OperatingRecord; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * 操作记录数据访问 9 | * 10 | * @author maurice 11 | * 12 | */ 13 | @Repository 14 | public class OperatingRecordDao extends HibernateSupportDao{ 15 | 16 | } 17 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/dao/foundation/variable/DataDictionaryDao.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.dao.foundation.variable; 2 | 3 | import java.text.MessageFormat; 4 | import java.util.List; 5 | 6 | import org.apache.commons.collections.CollectionUtils; 7 | import org.apache.commons.lang3.ArrayUtils; 8 | import org.apache.commons.lang3.StringUtils; 9 | import com.github.dactiv.orm.core.hibernate.support.HibernateSupportDao; 10 | import com.github.dactiv.showcase.common.enumeration.SystemDictionaryCode; 11 | import com.github.dactiv.showcase.entity.foundation.variable.DataDictionary; 12 | import org.springframework.stereotype.Repository; 13 | 14 | import com.google.common.collect.Lists; 15 | 16 | /** 17 | * 数据字典数据访问 18 | * 19 | * @author maurice 20 | * 21 | */ 22 | @Repository 23 | public class DataDictionaryDao extends HibernateSupportDao{ 24 | 25 | /** 26 | * 通过字典类别代码获取数据字典集合 27 | * 28 | * @param code 字典列别 29 | * @param ignoreValue 忽略字典的值 30 | * 31 | * @return List 32 | */ 33 | public List getByCategoryCode(SystemDictionaryCode code,String... ignoreValue) { 34 | StringBuffer hql = new StringBuffer("from DataDictionary dd where dd.category.code = ?"); 35 | 36 | List args = Lists.newArrayList(code.getCode()); 37 | 38 | if (ArrayUtils.isNotEmpty(ignoreValue)) { 39 | 40 | String[] qm = new String[ignoreValue.length]; 41 | 42 | for (int i = 0; i < ignoreValue.length; i++) { 43 | qm[i] = "?"; 44 | } 45 | 46 | CollectionUtils.addAll(args, ignoreValue); 47 | hql.append(MessageFormat.format(" and dd.value not in({0})", StringUtils.join(qm,","))); 48 | 49 | } 50 | 51 | return findByQuery(hql.toString(), args.toArray()); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/dao/foundation/variable/DictionaryCategoryDao.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.dao.foundation.variable; 2 | 3 | import com.github.dactiv.orm.core.hibernate.support.HibernateSupportDao; 4 | import com.github.dactiv.showcase.entity.foundation.variable.DictionaryCategory; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * 字典类别数据访问 9 | * 10 | * @author maurice 11 | * 12 | */ 13 | @Repository 14 | public class DictionaryCategoryDao extends HibernateSupportDao{ 15 | 16 | } 17 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/entity/IdEntity.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | import javax.persistence.MappedSuperclass; 9 | 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.hibernate.annotations.GenericGenerator; 12 | 13 | /** 14 | * UUID主键父类 15 | * 16 | * @author maurice 17 | * 18 | */ 19 | @MappedSuperclass 20 | public class IdEntity implements Serializable{ 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | //主键Id 25 | protected String id; 26 | 27 | /** 28 | * 获取主键ID 29 | * 30 | * @return String 31 | */ 32 | @Id 33 | @GeneratedValue(generator="system-uuid") 34 | @Column(length = 32, nullable = false,unique=true) 35 | @GenericGenerator(name="system-uuid", strategy = "uuid") 36 | public String getId() { 37 | if (StringUtils.isEmpty(id)) { 38 | return null; 39 | } 40 | return this.id; 41 | } 42 | 43 | /** 44 | * 设置主键ID, 45 | * @param id 46 | */ 47 | public void setId(String id) { 48 | if (StringUtils.isEmpty(id)) { 49 | this.id = null; 50 | } else { 51 | this.id = id; 52 | } 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/entity/foundation/variable/DataDictionary.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.entity.foundation.variable; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.FetchType; 6 | import javax.persistence.JoinColumn; 7 | import javax.persistence.ManyToOne; 8 | import javax.persistence.Table; 9 | import javax.persistence.Transient; 10 | 11 | import com.github.dactiv.common.type.FieldType; 12 | import com.github.dactiv.common.utils.ConvertUtils; 13 | import com.github.dactiv.showcase.entity.IdEntity; 14 | 15 | 16 | /** 17 | * 数据字典实体 18 | * 19 | * @author maurice 20 | * 21 | */ 22 | @Entity 23 | @Table(name="TB_DATA_DICTIONARY") 24 | public class DataDictionary extends IdEntity{ 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | //名称 29 | private String name; 30 | //值 31 | private String value; 32 | //类型 33 | private String type = "S"; 34 | //备注 35 | private String remark; 36 | //所属类别 37 | public DictionaryCategory category; 38 | 39 | public DataDictionary() { 40 | 41 | } 42 | 43 | public DataDictionary(String name, String value, String type) { 44 | this.name = name; 45 | this.value = value; 46 | this.type = type; 47 | } 48 | 49 | /** 50 | * 获取名称 51 | * 52 | * @return String 53 | */ 54 | @Column(length=256,nullable=false) 55 | public String getName() { 56 | return name; 57 | } 58 | 59 | /** 60 | * 设置名称 61 | * @param name 62 | */ 63 | public void setName(String name) { 64 | this.name = name; 65 | } 66 | 67 | /** 68 | * 获取值 69 | * 70 | * @return String 71 | */ 72 | @Column(length=32,nullable=false) 73 | public String getValue() { 74 | return value; 75 | } 76 | 77 | /** 78 | * 设置值 79 | * 80 | * @param value 值 81 | */ 82 | public void setValue(String value) { 83 | this.value = value; 84 | } 85 | 86 | /** 87 | * 获取值类型 88 | * 89 | * @return String 90 | */ 91 | @Column(length=1,nullable=false) 92 | public String getType() { 93 | return type; 94 | } 95 | 96 | /** 97 | * 设置值类型 98 | * 99 | * @param type 值类型 100 | */ 101 | public void setType(String type) { 102 | this.type = type; 103 | } 104 | 105 | /** 106 | * 获取备注 107 | * 108 | * @return String 109 | */ 110 | @Column(length=512) 111 | public String getRemark() { 112 | return remark; 113 | } 114 | 115 | /** 116 | * 设置备注 117 | * 118 | * @param remark 备注 119 | */ 120 | public void setRemark(String remark) { 121 | this.remark = remark; 122 | } 123 | 124 | /** 125 | * 获取所属类别 126 | * 127 | * @return {@link DictionaryCategory} 128 | */ 129 | @ManyToOne(fetch=FetchType.LAZY) 130 | @JoinColumn(name = "FK_CATEGORY_ID", nullable=false) 131 | public DictionaryCategory getCategory() { 132 | return category; 133 | } 134 | 135 | /** 136 | * 设置所属类别 137 | * 138 | * @param category 所属类别 139 | */ 140 | public void setCategory(DictionaryCategory category) { 141 | this.category = category; 142 | } 143 | 144 | /** 145 | * 根据type属性的值获取真正的值 146 | * 147 | * @return Object 148 | */ 149 | @Transient 150 | public Object getReadValue() { 151 | return ConvertUtils.convertToObject(this.value, FieldType.valueOf(type).getValue()); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/service/ServiceException.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.service; 2 | 3 | /** 4 | * 业务层的异常类 5 | * @author maurice 6 | * 7 | */ 8 | @SuppressWarnings("serial") 9 | public class ServiceException extends RuntimeException { 10 | 11 | public ServiceException() { 12 | super(); 13 | } 14 | 15 | public ServiceException(String message) { 16 | super(message); 17 | } 18 | 19 | public ServiceException(Throwable cause) { 20 | super(cause); 21 | } 22 | 23 | public ServiceException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/service/account/ChainDefinitionSectionMetaSource.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.service.account; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | import org.apache.shiro.config.Ini; 5 | import org.apache.shiro.config.Ini.Section; 6 | import com.github.dactiv.showcase.common.enumeration.entity.GroupType; 7 | import com.github.dactiv.showcase.entity.account.Group; 8 | import com.github.dactiv.showcase.entity.account.Resource; 9 | import org.springframework.beans.BeansException; 10 | import org.springframework.beans.factory.FactoryBean; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | 13 | 14 | /** 15 | * 借助spring {@link FactoryBean} 对apache shiro的premission进行动态创建 16 | * 17 | * @author maurice 18 | * 19 | */ 20 | public class ChainDefinitionSectionMetaSource implements FactoryBean{ 21 | 22 | @Autowired 23 | private AccountManager accountManager; 24 | 25 | //shiro默认的链接定义 26 | private String filterChainDefinitions; 27 | 28 | /** 29 | * 通过filterChainDefinitions对默认的链接过滤定义 30 | * 31 | * @param filterChainDefinitions 默认的接过滤定义 32 | */ 33 | public void setFilterChainDefinitions(String filterChainDefinitions) { 34 | this.filterChainDefinitions = filterChainDefinitions; 35 | } 36 | 37 | @Override 38 | public Section getObject() throws BeansException { 39 | Ini ini = new Ini(); 40 | //加载默认的url 41 | ini.load(filterChainDefinitions); 42 | Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME); 43 | //循环数据库资源的url 44 | for (Resource resource : accountManager.getResources()) { 45 | if(StringUtils.isNotEmpty(resource.getValue()) && StringUtils.isNotEmpty(resource.getPermission())) { 46 | section.put(resource.getValue(), resource.getPermission()); 47 | } 48 | } 49 | 50 | //循环数据库组的url 51 | for (Group group : accountManager.getGroup(GroupType.RoleGorup)) { 52 | if(StringUtils.isNotEmpty(group.getValue()) && StringUtils.isNotEmpty(group.getRole())) { 53 | section.put(group.getValue(), group.getRole()); 54 | } 55 | } 56 | 57 | return section; 58 | } 59 | 60 | @Override 61 | public Class getObjectType() { 62 | return Section.class; 63 | } 64 | 65 | @Override 66 | public boolean isSingleton() { 67 | return true; 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/service/account/JdbcAuthenticationRealm.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.service.account; 2 | 3 | import org.apache.shiro.authc.AccountException; 4 | import org.apache.shiro.authc.AuthenticationException; 5 | import org.apache.shiro.authc.AuthenticationInfo; 6 | import org.apache.shiro.authc.AuthenticationToken; 7 | import org.apache.shiro.authc.DisabledAccountException; 8 | import org.apache.shiro.authc.SimpleAuthenticationInfo; 9 | import org.apache.shiro.authc.UnknownAccountException; 10 | import org.apache.shiro.authc.UsernamePasswordToken; 11 | import com.github.dactiv.showcase.common.SessionVariable; 12 | import com.github.dactiv.showcase.common.enumeration.entity.State; 13 | import com.github.dactiv.showcase.entity.account.User; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | 16 | /** 17 | * 18 | * apache shiro 的身份验证类 19 | * 20 | * @author maurice 21 | * 22 | */ 23 | public class JdbcAuthenticationRealm extends AuthorizationRealm{ 24 | 25 | @Autowired 26 | private AccountManager accountManager; 27 | 28 | /** 29 | * 用户登录的身份验证方法 30 | * 31 | */ 32 | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { 33 | UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token; 34 | 35 | String username = usernamePasswordToken.getUsername(); 36 | 37 | if (username == null) { 38 | throw new AccountException("用户名不能为空"); 39 | } 40 | 41 | User user = accountManager.getUserByUsername(username); 42 | 43 | if (user == null) { 44 | throw new UnknownAccountException("用户不存在"); 45 | } 46 | 47 | if (user.getState().equals(State.Disable.getValue())) { 48 | throw new DisabledAccountException("你的账户已被禁用,请联系管理员开通."); 49 | } 50 | 51 | SessionVariable model = new SessionVariable(user); 52 | 53 | return new SimpleAuthenticationInfo(model,user.getPassword(),getName()); 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/java/com/github/dactiv/showcase/service/foundation/SystemAuditManager.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.service.foundation; 2 | 3 | import java.util.List; 4 | 5 | import com.github.dactiv.orm.core.Page; 6 | import com.github.dactiv.orm.core.PageRequest; 7 | import com.github.dactiv.orm.core.PropertyFilter; 8 | import com.github.dactiv.showcase.dao.foundation.audit.OperatingRecordDao; 9 | import com.github.dactiv.showcase.entity.foundation.audit.OperatingRecord; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | /** 15 | * 系统审计业务逻辑 16 | * 17 | * @author maurice 18 | * 19 | */ 20 | @Service 21 | @Transactional 22 | public class SystemAuditManager { 23 | 24 | @Autowired 25 | private OperatingRecordDao operatingRecordDao; 26 | 27 | //---------------------------------------操作记录管理---------------------------------------// 28 | 29 | /** 30 | * 获取操作记录实体 31 | * 32 | * @param id 操作记录id 33 | */ 34 | public OperatingRecord getOperatingRecord(String id) { 35 | return operatingRecordDao.load(id); 36 | } 37 | 38 | /** 39 | * 保存操作记录 40 | * 41 | * @param entity 操作记录实体 42 | */ 43 | public void insertOperatingRecord(OperatingRecord entity) { 44 | operatingRecordDao.insert(entity); 45 | } 46 | 47 | /** 48 | * 获取操作记录分页对象 49 | * 50 | * @param request 分页参数请求 51 | * @param filters 属性过滤器集合 52 | * 53 | * @return Page 54 | */ 55 | public Page searchOperatingRecordPage(PageRequest request,List filters) { 56 | return operatingRecordDao.findPage(request, filters); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #-------h2 version database settings-------# 2 | jdbc.driver=org.h2.Driver 3 | jdbc.url=jdbc:h2:file:~/.h2/base-curd;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1 4 | 5 | #-------mysql version database settings-------# 6 | #jdbc.driver=com.mysql.jdbc.Driver 7 | #jdbc.url=jdbc:mysql://localhost:3306/base-curd?autoReconnect=true 8 | 9 | jdbc.username=sa 10 | jdbc.password= 11 | 12 | jdbc.initial_size=10 13 | jdbc.min_idle=10 14 | jdbc.max_idle=30 15 | jdbc.max_active=100 16 | 17 | #hibernate settings 18 | 19 | #h2 dialect 20 | hibernate.dialect=org.hibernate.dialect.H2Dialect 21 | 22 | #mysql dialect 23 | #hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect 24 | 25 | hibernate.show_sql=true 26 | hibernate.format_sql=true 27 | 28 | #file upload path 29 | file.upload.path=C:\\base-curd\\upload_file\\ 30 | 31 | #email setting 32 | mail.host=smtp.gmail.com 33 | mail.username=base.curd@gmail.com 34 | mail.password=base-curd 35 | mail.default_encoding=UTF-8 36 | mail.exception.receive=base.curd.exception@gmail.com 37 | 38 | #spring thread pool setting 39 | thread.pool.core_pool_size=10 40 | thread.pool.max_pool_size=30 41 | thread.pool.queue_capacity=50 -------------------------------------------------------------------------------- /showcase/base-curd/src/main/resources/applicationContext-mail.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | true 16 | 17 | true 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 32 | 33 | 34 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/resources/email/operating-mail-template.ftl: -------------------------------------------------------------------------------- 1 |

操作记录清单

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
操作用户ip地址操作目标执行方法模块名称功能名称开始时间结束时间执行状态
${entity.username!""}${entity.ip!""}${entity.operatingTarget!""}${entity.method!""}${entity.module!""}${entity.function!""}${entity.startDate!""}${entity.endDate!""}${entity.stateName}
31 | 32 |

描述

33 | 34 | ${entity.remark!''} -------------------------------------------------------------------------------- /showcase/base-curd/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d [%t] %-5p [%c:%L] - %m%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | logs/base-curd.log 16 | 17 | logs/base-curd-%d{yyyy-MM-dd}.log 18 | 19 | 20 | %d [%t] %-5p [%c:%L] - %m%n 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/error-page/404.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | 3 | 4 | 5 | 6 | basic curd admin : 404 7 | 8 | 9 | 10 | 11 | 12 | resource/css/bootstrap.min.css" /> 13 | resource/css/bootstrap-theme.css" /> 14 | resource/css/layout.min.css" /> 15 | 19 | 20 | 21 |
22 | 23 |
24 | 25 |
26 |

404

27 |
28 | 29 |
30 |
31 |

32 |

找不到页面

33 |
34 |

你访问的页面不存在或已经被删除.

35 |

36 | 37 | 返回 38 | 39 |

40 |
41 |
42 | 43 |
44 | 45 |
46 | 47 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/error-page/500.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | 3 | 4 | 5 | 6 | basic curd admin : 500 7 | 8 | 9 | 10 | 11 | 12 | resource/css/bootstrap.min.css" /> 13 | resource/css/bootstrap-theme.css" /> 14 | resource/css/layout.min.css" /> 15 | 19 | 20 | 21 |
22 | 23 |
24 | 25 |
26 |

500

27 |
28 | 29 |
30 |
31 |

32 |

操作失败

33 |
34 |

服务器忙碌,请稍后再试。

35 |

36 | 37 | 返回 38 | 39 |

40 |
41 |
42 | 43 |
44 | 45 |
46 | 47 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/basic/default.html: -------------------------------------------------------------------------------- 1 | <#assign shiro=JspTaglibs["/WEB-INF/taglib/shiro.tld"] /> 2 | <#assign base="${request.contextPath}" /> 3 | 4 | 5 | 6 | 7 | 8 | basic curd admin : <@title/> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | <#if head?exists> 32 | <@head/> 33 | 34 | 35 | 36 | 37 | <@shiro.user> 38 | <#include "profile-setting.html" /> 39 | 40 | 41 |
42 | 43 |
44 | 45 |
46 | <@shiro.user> 47 | <#include "info.html" /> 48 | 49 |
50 | 51 |
52 |
53 |
54 |
55 | 56 | <@shiro.user> 57 | <#include "navbar.html" /> 58 | 59 | 60 | <@body/> 61 |
62 |
63 |
64 |
65 | 66 |
67 |
68 | 69 | 70 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/basic/info.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | 5 |
6 |
7 | 10 |
11 |
12 | 13 | 14 | 15 |
16 |
17 | 18 | 19 | 20 |
21 |
-------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/basic/navbar.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/exception/defaule-error.html: -------------------------------------------------------------------------------- 1 | <#include "*/basic/default.html"/> 2 | 3 | <#macro title> 4 | 500 5 | 6 | 7 | <#macro head> 8 | 16 | 17 | 18 | <#macro body> 19 | 20 |
21 | 22 |

23 |
24 | 25 | 26 |
27 |

操作失败

28 |
29 |

原因:<#if exception.class == 'class com.github.dactiv.showcase.service.ServiceException'>${exception.message}<#else>系统出现未知异常

30 |

31 | 34 | 37 |

38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/exception/unauthorized.html: -------------------------------------------------------------------------------- 1 | <#include "*/basic/default.html"/> 2 | 3 | <#macro title> 4 | 401 5 | 6 | 7 | <#macro body> 8 |
9 |

10 |

访问控制

11 |
12 |

你没有足够的权限做该操作.

13 |

14 | 15 | 返回 16 | 17 | 18 | 重新登录 19 | 20 |

21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/foundation/audit/operating-record/read.html: -------------------------------------------------------------------------------- 1 | <#include "*/basic/default.html"/> 2 | 3 | <#macro title> 4 | 操作记录信息 5 | 6 | 7 | <#macro body> 8 |
9 | 10 | 14 | 15 |
16 |
17 |

操作记录清单

18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
操作用户ip地址操作目标执行方法模块名称功能名称开始时间结束时间执行状态
${entity.username!""}${entity.ip!""}${entity.operatingTarget!""}${entity.method!""}${entity.module!""}${entity.function!""}${entity.startDate!""}${entity.endDate!""}${entity.stateName}
51 |
52 | 53 |
54 |
55 |

描述

56 |
57 |
58 | ${entity.remark!''} 59 |
60 |
61 |
62 | 63 | 70 | 71 |
72 | 73 |
74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/foundation/variable/data-dictionary/read.html: -------------------------------------------------------------------------------- 1 | <#include "*/basic/default.html"/> 2 | 3 | <#macro title> 4 | 编辑数据字典${entity.name!''} 5 | 6 | 7 | <#macro body> 8 |
9 | 10 | 14 | 15 |
16 |
17 |

数据字典管理

18 |
19 |
20 | 21 | 22 | 23 |
24 | 25 |
26 |
27 |
28 | 29 | 30 |
31 |
32 | 33 | 34 |
35 |
36 |
37 | 38 |
39 |
40 |
41 | 42 | 48 |
49 |
50 | 51 | 57 |
58 |
59 |
60 | 61 |
62 |
63 |
64 | 65 | 66 |
67 |
68 |
69 | 70 |
71 | 72 | 87 |
88 | 89 |
90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/foundation/variable/dictionary-category/read.html: -------------------------------------------------------------------------------- 1 | <#include "*/basic/default.html"/> 2 | 3 | <#macro title> 4 | 编辑字典类型${entity.name!''} 5 | 6 | 7 | <#macro body> 8 |
9 | 10 | 14 | 15 |
16 |
17 |

字典类型管理

18 |
19 |
20 | 21 | 22 | 23 |
24 | 25 |
26 |
27 |
28 | 29 | 30 |
31 |
32 | 33 | 34 |
35 |
36 |
37 | 38 |
39 |
40 |
41 | 42 | 48 |
49 |
50 |
51 | 52 |
53 |
54 |
55 | 56 | 57 |
58 |
59 |
60 | 61 |
62 | 63 | 78 |
79 | 80 |
81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/index.html: -------------------------------------------------------------------------------- 1 | <#include "*/basic/default.html"/> 2 | 3 | <#macro title> 4 | 首页 5 | 6 | 7 | <#macro body> 8 |
9 | 10 | 13 | 14 |

更新日志

15 |
16 | 17 |

1.0.0.RELEASE

18 |
19 | 20 |
    21 |
  • 22 |

    23 | 使用Bootstrap 3设计项目演示页面。 24 |

    25 |
  • 26 |
  • 27 |

    28 | 使用shiro来做系统的权限安全框架。 29 |

    30 |
  • 31 |
  • 32 |

    33 | 使用hibernate4来做持久化框架。 34 |

    35 |
  • 36 |
  • 37 |

    38 | 使用spring mvc框架来做mvc。 39 |

    40 |
  • 41 |
  • 42 |

    43 | 使用spring cache + ehcahce来做系统缓存管理。 44 |

    45 |
  • 46 |
  • 47 |

    48 | 使用selenium来做系统自动化测试。 49 |

    50 |
  • 51 |
  • 52 |

    53 | 使用spring profile来做系统化境管理。 54 |

    55 |
  • 56 |
57 | 58 |
59 | 60 |
61 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/WEB-INF/page/login.html: -------------------------------------------------------------------------------- 1 | <#include "*/basic/default.html"/> 2 | 3 | <#macro title> 4 | 用户登录 5 | 6 | 7 | <#macro head> 8 | 13 | 14 | 15 | <#macro body> 16 |
17 | 74 |
75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/css/layout.min.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-image: url("../image/bg.png"); 3 | } 4 | 5 | .main-container { 6 | margin: 50px 25px 25px; 7 | min-width: 800px; 8 | } 9 | 10 | .login-container { 11 | margin: 0 auto; 12 | padding: 7% 0; 13 | width: 400px; 14 | } 15 | 16 | .content-widget { 17 | background-color: #FFFFFF; 18 | border-left: 1px solid #BBBBBB; 19 | border-right: 1px solid #BBBBBB; 20 | border-bottom: 1px solid #BBBBBB; 21 | padding: 0 1px 1px; 22 | min-height: 400px; 23 | } 24 | #content-widget { 25 | padding-top:5px; 26 | background: #fefefe url(../image/grids.png); 27 | } 28 | .content-container { 29 | background-color: #FFFFFF; 30 | padding: 0px 10px 10px; 31 | background-image: url("../image/book-cover.png"); 32 | } 33 | 34 | .data-content { 35 | margin: 0px 15px; 36 | } 37 | 38 | .user-info { 39 | margin-left: 100px; 40 | } 41 | 42 | .user-info .name { 43 | color: #FEE392; 44 | display: block; 45 | font-size: 14px; 46 | font-weight: bold; 47 | } 48 | 49 | .user-info,.profile { 50 | display: inline-block; 51 | } 52 | 53 | 54 | .border-black{ 55 | border-color: #323232; 56 | box-shadow: inset 0 0 2px rgba(255,255,255,0.35),0 0 6px rgba(0,0,0,0.8); 57 | } 58 | 59 | .profile { 60 | margin-bottom: 20px; 61 | bottom: 0px; 62 | position: absolute; 63 | box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.5); 64 | height: 90px; 65 | } 66 | 67 | .heading-background{ 68 | box-shadow: inset 0 2px 0 rgba(255,255,255,0.15); 69 | background-image: url("../image/header-bg.png") !important; 70 | height: 70px; 71 | border-color: #323232 !important; 72 | color: #FFFFFF; 73 | position: relative; 74 | z-index: 1010; 75 | } 76 | 77 | .pictrue { 78 | margin: 0 auto 5px; 79 | width: 90px; 80 | } 81 | 82 | .ribbon { 83 | background: url(../image/ribbon.png) no-repeat center top; 84 | background-size: 73px 103px; 85 | width: 75px; 86 | height: 100px; 87 | float: left; 88 | text-align: center; 89 | margin-top: -15px; 90 | } 91 | 92 | .ribbon > a { 93 | line-height: 1; 94 | display: inline-block; 95 | width: 38px; 96 | height: 38px; 97 | line-height: 38px; 98 | color: #fff; 99 | font-size: 24px; 100 | margin-top: 18px; 101 | border: 1px solid transparent; 102 | border-radius: 500px; 103 | text-align: center; 104 | } 105 | 106 | .ribbon > a > span { 107 | margin-top: 5px; 108 | } 109 | 110 | .ribbon > a:hover { 111 | border-color: #800; 112 | box-shadow: inset 0 1px 0 rgba(255,255,255,0.2); 113 | } 114 | 115 | .server-exception { 116 | padding: 20px; 117 | width: 500px; 118 | margin: 0 auto; 119 | } 120 | 121 | .server-exception h1{ 122 | font-size: 100px; 123 | } 124 | -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/image/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/image/bg.png -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/image/book-cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/image/book-cover.png -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/image/empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/image/empty.png -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/image/grids.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/image/grids.png -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/image/header-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/image/header-bg.png -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/image/ie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/image/ie.png -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/image/portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/image/portrait.png -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/image/ribbon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/image/ribbon.png -------------------------------------------------------------------------------- /showcase/base-curd/src/main/webapp/resource/swf/FaustCplus.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/biliroy/base-framework/f0359f928cc6bacffb71d5c591b7261b639eca2f/showcase/base-curd/src/main/webapp/resource/swf/FaustCplus.swf -------------------------------------------------------------------------------- /showcase/base-curd/src/test/java/com/github/dactiv/showcase/test/CreateDataBaseTableByHibernateConfigFile.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.test; 2 | 3 | import org.hibernate.cfg.Configuration; 4 | import org.hibernate.cfg.ImprovedNamingStrategy; 5 | import org.hibernate.tool.EnversSchemaGenerator; 6 | import org.hibernate.tool.hbm2ddl.SchemaExport; 7 | 8 | /** 9 | * 10 | * 通过Hibernate配置文件创建生成表的sql语句到src/test/resources/data/h2/create-table.sql文件中, 11 | * 该类是对单元测试的模拟创建表起辅助作用 12 | * 13 | * @author maurice 14 | * 15 | */ 16 | public class CreateDataBaseTableByHibernateConfigFile { 17 | 18 | 19 | public static void main(String[] args) { 20 | Configuration configuration = new Configuration().configure().setNamingStrategy(new ImprovedNamingStrategy()); 21 | EnversSchemaGenerator generator = new EnversSchemaGenerator(configuration); 22 | SchemaExport export = generator.export(); 23 | 24 | export.setFormat(false); 25 | export.setOutputFile("src/test/resources/data/h2/create-table-new.sql"); 26 | export.create(true, false); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /showcase/base-curd/src/test/java/com/github/dactiv/showcase/test/LaunchJetty.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.test; 2 | 3 | import org.eclipse.jetty.server.Server; 4 | import com.github.dactiv.common.unit.JettyFactory; 5 | 6 | /** 7 | * 启动jetty服务,运行后通过http://localhost:8080/base-curd/来访问项目路径 8 | * 9 | * @author maurice 10 | * 11 | */ 12 | public class LaunchJetty { 13 | 14 | /** 15 | * 端口 16 | */ 17 | public static final int PORT = 8080; 18 | /** 19 | * 项目名称 20 | */ 21 | public static final String CONTEXT = "/base-curd"; 22 | 23 | public static final String[] TLD_JAR_NAMES = new String[] { "shiro-web" }; 24 | public static final String ACTIVE_PROFILE = "spring.profiles.active"; 25 | 26 | public static void main(String[] args) throws Exception { 27 | System.setProperty(ACTIVE_PROFILE, "dev"); 28 | Server server = JettyFactory.createServerInSource(PORT, CONTEXT); 29 | JettyFactory.setTldJarNames(server, TLD_JAR_NAMES); 30 | 31 | try { 32 | System.out.println("[HINT] Don't forget to set -XX:MaxPermSize=128m"); 33 | server.start(); 34 | System.out.println("Server running at http://localhost:" + PORT + CONTEXT); 35 | System.out.println("[HINT] Hit Enter to reload the application quickly"); 36 | 37 | // 等待用户输入回车重载应用. 38 | while (true) { 39 | char c = (char) System.in.read(); 40 | if (c == '\n') { 41 | JettyFactory.reloadContext(server); 42 | } 43 | } 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | System.exit(-1); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /showcase/base-curd/src/test/java/com/github/dactiv/showcase/test/founction/FunctionTestCaseSupport.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.test.founction; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.eclipse.jetty.server.Server; 6 | import com.github.dactiv.common.spring.SpringContextHolder; 7 | import com.github.dactiv.common.unit.JettyFactory; 8 | import com.github.dactiv.common.unit.selenium.Selenium2; 9 | import com.github.dactiv.common.unit.selenium.WebDriverFactory; 10 | import com.github.dactiv.showcase.test.LaunchJetty; 11 | import org.junit.AfterClass; 12 | import org.junit.BeforeClass; 13 | import org.openqa.selenium.By; 14 | import org.openqa.selenium.WebDriver; 15 | import org.springframework.core.io.DefaultResourceLoader; 16 | import org.springframework.core.io.ResourceLoader; 17 | import org.springframework.dao.DataAccessException; 18 | import org.springframework.jdbc.core.JdbcTemplate; 19 | import org.springframework.test.jdbc.JdbcTestUtils; 20 | 21 | /** 22 | * 使用自动化selenium做功能测试的基类 23 | * 24 | * @author vincnet 25 | * 26 | */ 27 | public class FunctionTestCaseSupport { 28 | 29 | //selenium settings, options include firefox,ie,chrome,remote:localhost:4444:firefox 30 | public static final String SELENIUM_DRIVER="firefox"; 31 | public static final String URL="http://localhost:8080/base-curd"; 32 | 33 | protected static DataSource dataSource; 34 | protected static Server jettyServer; 35 | protected static JdbcTemplate jdbcTemplate; 36 | protected static ResourceLoader resourceLoader = new DefaultResourceLoader(); 37 | protected static Selenium2 s; 38 | 39 | @BeforeClass 40 | public static void install() throws Exception { 41 | 42 | //如果jetty没启动,启动jetty 43 | if (jettyServer == null) { 44 | // 设定Spring的profile 45 | System.setProperty(LaunchJetty.ACTIVE_PROFILE, "test"); 46 | 47 | jettyServer = JettyFactory.createServerInSource(LaunchJetty.PORT, LaunchJetty.CONTEXT); 48 | JettyFactory.setTldJarNames(jettyServer, LaunchJetty.TLD_JAR_NAMES); 49 | System.out.println("[HINT] Don't forget to set -XX:MaxPermSize=128m"); 50 | jettyServer.start(); 51 | } 52 | //如果当前dataSource没初始化,初始化dataSource 53 | if (dataSource == null) { 54 | dataSource = SpringContextHolder.getBean(DataSource.class); 55 | jdbcTemplate = new JdbcTemplate(dataSource); 56 | } 57 | 58 | //如果selenium没初始化,初始化selenium 59 | if (s == null) { 60 | System.setProperty ( "webdriver.firefox.bin" , "E:/Firefox/firefox.exe" ); 61 | WebDriver driver = WebDriverFactory.createDriver(SELENIUM_DRIVER); 62 | s = new Selenium2(driver, URL); 63 | s.setStopAtShutdown(); 64 | } 65 | 66 | //载入新的数据 67 | executeScript(dataSource,"classpath:data/h2/cleanup-data.sql","classpath:data/h2/insert-data.sql"); 68 | 69 | //打开浏览器,并登录 70 | s.open("/"); 71 | s.click(By.xpath("//button[@type='submit']")); 72 | } 73 | 74 | @AfterClass 75 | public static void uninstall() { 76 | s.click(By.xpath("//a[@href='/base-curd/logout']")); 77 | } 78 | 79 | /** 80 | * 批量执行sql文件 81 | * 82 | * @param dataSource dataSource 83 | * @param sqlResourcePaths sql文件路径 84 | * 85 | * @throws DataAccessException 86 | */ 87 | public static void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException { 88 | 89 | for (String sqlResourcePath : sqlResourcePaths) { 90 | JdbcTestUtils.executeSqlScript(jdbcTemplate, resourceLoader, sqlResourcePath, true); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /showcase/base-curd/src/test/java/com/github/dactiv/showcase/test/manager/ManagerTestCaseSupport.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.test.manager; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.hibernate.SessionFactory; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.core.io.DefaultResourceLoader; 11 | import org.springframework.core.io.ResourceLoader; 12 | import org.springframework.dao.DataAccessException; 13 | import org.springframework.jdbc.core.JdbcTemplate; 14 | import org.springframework.test.context.ActiveProfiles; 15 | import org.springframework.test.context.ContextConfiguration; 16 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 17 | import org.springframework.test.jdbc.JdbcTestUtils; 18 | 19 | /** 20 | * 业务单元测试基类 21 | * 22 | * @author maurice 23 | * 24 | */ 25 | @ActiveProfiles("test") 26 | @RunWith(SpringJUnit4ClassRunner.class) 27 | @ContextConfiguration("/applicationContext-core.xml") 28 | public class ManagerTestCaseSupport { 29 | 30 | private DataSource dataSource; 31 | 32 | private JdbcTemplate jdbcTemplate; 33 | private ResourceLoader resourceLoader = new DefaultResourceLoader(); 34 | 35 | private SessionFactory sessionFactory; 36 | 37 | @Autowired 38 | public void setDataSource(DataSource dataSource) throws Exception { 39 | this.dataSource = dataSource; 40 | this.jdbcTemplate = new JdbcTemplate(dataSource); 41 | } 42 | 43 | @Autowired 44 | public void setSessionFactory(SessionFactory sessionFactory) { 45 | this.sessionFactory = sessionFactory; 46 | } 47 | 48 | public SessionFactory getSessionFactory() { 49 | return sessionFactory; 50 | } 51 | 52 | /** 53 | * 通过表名计算出表中的总记录数 54 | * 55 | * @param tableName 表名 56 | * 57 | * @return int 58 | */ 59 | protected int countRowsInTable(String tableName) { 60 | return jdbcTemplate.queryForObject("SELECT COUNT(0) FROM " + tableName,Integer.class); 61 | } 62 | 63 | /** 64 | * 65 | * 每个单元测试用例开始先把模拟数据加载到dataSource中 66 | * 67 | * @throws Exception 68 | */ 69 | @Before 70 | public void install() throws Exception { 71 | executeScript(dataSource,"classpath:data/h2/cleanup-data.sql","classpath:data/h2/insert-data.sql"); 72 | } 73 | 74 | /** 75 | * 批量执行sql文件 76 | * 77 | * @param dataSource dataSource 78 | * @param sqlResourcePaths sql文件路径 79 | * 80 | * @throws DataAccessException 81 | */ 82 | public void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException { 83 | 84 | for (String sqlResourcePath : sqlResourcePaths) { 85 | JdbcTestUtils.executeSqlScript(jdbcTemplate, resourceLoader, sqlResourcePath, true); 86 | } 87 | } 88 | 89 | @Test 90 | public void emptyTestMethod() { 91 | 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /showcase/base-curd/src/test/java/com/github/dactiv/showcase/test/manager/foundation/audit/TestOperatingRecordManager.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.test.manager.foundation.audit; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.Date; 6 | 7 | import com.github.dactiv.showcase.common.enumeration.entity.OperatingState; 8 | import com.github.dactiv.showcase.entity.foundation.audit.OperatingRecord; 9 | import com.github.dactiv.showcase.service.foundation.SystemAuditManager; 10 | import com.github.dactiv.showcase.test.manager.ManagerTestCaseSupport; 11 | import org.junit.Test; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.transaction.annotation.Transactional; 14 | 15 | /** 16 | * 测试操作记录业务逻辑 17 | * 18 | * @author maurice 19 | * 20 | */ 21 | public class TestOperatingRecordManager extends ManagerTestCaseSupport{ 22 | 23 | @Autowired 24 | private SystemAuditManager systemAuditManager; 25 | 26 | @Test 27 | @Transactional 28 | public void testInsertOperatingRecord() { 29 | OperatingRecord or = new OperatingRecord(); 30 | 31 | or.setStartDate(new Date()); 32 | or.setIp("127.0.0.1"); 33 | or.setMethod("com.github.dactiv.showcase.test.manager.foundation.audit.OperatingRecordManager.testSaveOperatingRecord()"); 34 | or.setOperatingTarget("account/user/view"); 35 | or.setState(OperatingState.Success.getValue()); 36 | 37 | or.setFkUserId("SJDK3849CKMS3849DJCK2039ZMSK0026"); 38 | or.setUsername("admin"); 39 | or.setEndDate(new Date()); 40 | 41 | int beforeRow = countRowsInTable("TB_OPERATING_RECORD"); 42 | systemAuditManager.insertOperatingRecord(or); 43 | getSessionFactory().getCurrentSession().flush(); 44 | int afterRow = countRowsInTable("TB_OPERATING_RECORD"); 45 | 46 | assertEquals(afterRow, beforeRow + 1); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /showcase/base-curd/src/test/java/com/github/dactiv/showcase/test/manager/foundation/variable/TestDataDictionaryManager.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.test.manager.foundation.variable; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.apache.commons.collections.CollectionUtils; 9 | import com.github.dactiv.common.type.FieldType; 10 | import com.github.dactiv.showcase.common.enumeration.SystemDictionaryCode; 11 | import com.github.dactiv.showcase.entity.foundation.variable.DataDictionary; 12 | import com.github.dactiv.showcase.entity.foundation.variable.DictionaryCategory; 13 | import com.github.dactiv.showcase.service.foundation.SystemVariableManager; 14 | import com.github.dactiv.showcase.test.manager.ManagerTestCaseSupport; 15 | import org.junit.Test; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | 18 | import com.google.common.collect.Lists; 19 | 20 | /** 21 | * 测试数据字典管理所有方法 22 | * 23 | * @author maurice 24 | * 25 | */ 26 | public class TestDataDictionaryManager extends ManagerTestCaseSupport{ 27 | 28 | @Autowired 29 | private SystemVariableManager systemVariableManager; 30 | 31 | @Test 32 | public void testGetDataDictionariesByCategoryCode() { 33 | List list = Lists.newArrayList(); 34 | list = systemVariableManager.getDataDictionariesByCategoryCode(SystemDictionaryCode.State); 35 | assertEquals(list.size(),3); 36 | list = systemVariableManager.getDataDictionariesByCategoryCode(SystemDictionaryCode.State, "1"); 37 | assertEquals(list.size(),2); 38 | list = systemVariableManager.getDataDictionariesByCategoryCode(SystemDictionaryCode.State, "1","2","3"); 39 | assertEquals(list.size(),0); 40 | 41 | } 42 | 43 | @Test 44 | public void testDeleteDataDictionary() { 45 | 46 | List ids = new ArrayList(); 47 | CollectionUtils.addAll(ids, new String[]{"402881e437d47b250137d481b6920001","402881e437d47b250137d481dda30002"}); 48 | 49 | int beforeRow = countRowsInTable("TB_DATA_DICTIONARY"); 50 | systemVariableManager.deleteDataDictionary(ids); 51 | int afterRow = countRowsInTable("TB_DATA_DICTIONARY"); 52 | 53 | assertEquals(afterRow, beforeRow - 2); 54 | } 55 | 56 | @Test 57 | public void testSaveDataDictionary() { 58 | 59 | DictionaryCategory category = systemVariableManager.getDictionaryCategory("402881e437d467d80137d46fc0e50001"); 60 | 61 | DataDictionary dataDictionary = new DataDictionary(); 62 | dataDictionary.setCategory(category); 63 | dataDictionary.setName("test"); 64 | dataDictionary.setValue("4"); 65 | dataDictionary.setType(FieldType.I.toString()); 66 | dataDictionary.setRemark("*"); 67 | 68 | int beforeRow = countRowsInTable("TB_DATA_DICTIONARY"); 69 | systemVariableManager.saveDataDictionary(dataDictionary); 70 | int afterRow = countRowsInTable("TB_DATA_DICTIONARY"); 71 | 72 | assertEquals(afterRow, beforeRow + 1); 73 | 74 | } 75 | 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /showcase/base-curd/src/test/java/com/github/dactiv/showcase/test/manager/foundation/variable/TestDictionaryCategoryManager.java: -------------------------------------------------------------------------------- 1 | package com.github.dactiv.showcase.test.manager.foundation.variable; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import com.github.dactiv.showcase.entity.foundation.variable.DictionaryCategory; 9 | import com.github.dactiv.showcase.service.foundation.SystemVariableManager; 10 | import com.github.dactiv.showcase.test.manager.ManagerTestCaseSupport; 11 | import org.junit.Test; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | 14 | /** 15 | * 测试字典类别管理所有方法 16 | * 17 | * @author maurice 18 | * 19 | */ 20 | public class TestDictionaryCategoryManager extends ManagerTestCaseSupport { 21 | 22 | @Autowired 23 | private SystemVariableManager systemVariableManager; 24 | 25 | @Test 26 | public void testSaveDictionaryCategory() { 27 | DictionaryCategory category = new DictionaryCategory(); 28 | category.setCode("test"); 29 | category.setName("测试"); 30 | category.setRemark("*"); 31 | 32 | int beforeRow = countRowsInTable("TB_DICTIONARY_CATEGORY"); 33 | systemVariableManager.saveDictionaryCategory(category); 34 | int afterRow = countRowsInTable("TB_DICTIONARY_CATEGORY"); 35 | 36 | assertEquals(afterRow, beforeRow + 1); 37 | } 38 | 39 | @Test 40 | public void testDeleteDictionaryCategory() { 41 | 42 | int beforeRow = countRowsInTable("TB_DICTIONARY_CATEGORY"); 43 | List ids = new ArrayList(); 44 | ids.add("402881e437d47b250137d485274b0005"); 45 | systemVariableManager.deleteDictionaryCategory(ids); 46 | int afterRow = countRowsInTable("TB_DICTIONARY_CATEGORY"); 47 | 48 | assertEquals(beforeRow, afterRow + 1); 49 | } 50 | 51 | @Test 52 | public void testGetAllDictionaryCategories() { 53 | List result = systemVariableManager.getDictionaryCategories(); 54 | assertEquals(5, result.size()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /showcase/base-curd/src/test/resources/application.test.properties: -------------------------------------------------------------------------------- 1 | #-------h2 version database settings-------# 2 | jdbc.driver=org.h2.Driver 3 | jdbc.url=jdbc:h2:file:~/.h2/base-curd;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1 4 | 5 | #-------mysql version database settings-------# 6 | #jdbc.driver=com.mysql.jdbc.Driver 7 | #jdbc.url=jdbc:mysql://localhost:3306/base-curd?autoReconnect=true 8 | 9 | jdbc.username=sa 10 | jdbc.password= 11 | 12 | jdbc.initial_size=10 13 | jdbc.min_idle=10 14 | jdbc.max_idle=30 15 | jdbc.max_active=100 16 | 17 | #hibernate settings 18 | 19 | #h2 dialect 20 | hibernate.dialect=org.hibernate.dialect.H2Dialect 21 | 22 | #mysql dialect 23 | #hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect 24 | 25 | hibernate.show_sql=true 26 | hibernate.format_sql=true 27 | 28 | #file upload path 29 | file.upload.path=C:\\base-curd\\upload_file\\ 30 | 31 | #email setting 32 | mail.host=smtp.gmail.com 33 | mail.username=base.curd@gmail.com 34 | mail.password=base-curd 35 | mail.default_encoding=UTF-8 36 | mail.exception.receive=base.curd.exception@gmail.com 37 | 38 | #spring thread pool setting 39 | thread.pool.core_pool_size=10 40 | thread.pool.max_pool_size=30 41 | thread.pool.queue_capacity=50 -------------------------------------------------------------------------------- /showcase/base-curd/src/test/resources/data/h2/cleanup-data.sql: -------------------------------------------------------------------------------- 1 | 2 | delete from TB_DATA_DICTIONARY; 3 | delete from TB_DICTIONARY_CATEGORY; 4 | 5 | delete from TB_GROUP_RESOURCE; 6 | delete from TB_GROUP_USER; 7 | 8 | delete from TB_GROUP; 9 | delete from TB_RESOURCE; 10 | delete from TB_USER; 11 | 12 | delete from TB_OPERATING_RECORD; -------------------------------------------------------------------------------- /showcase/base-curd/src/test/resources/data/h2/create-table.sql: -------------------------------------------------------------------------------- 1 | --删除所有表 2 | drop table TB_DATA_DICTIONARY if exists; 3 | drop table TB_DICTIONARY_CATEGORY if exists; 4 | drop table TB_GROUP if exists; 5 | drop table TB_GROUP_RESOURCE if exists; 6 | drop table TB_GROUP_USER if exists; 7 | drop table TB_RESOURCE if exists; 8 | drop table TB_USER if exists; 9 | drop table TB_OPERATING_RECORD if exists; 10 | 11 | --创建系统字典表 12 | create table TB_DATA_DICTIONARY (id varchar(32) not null, name varchar(256) not null, remark varchar(512), type varchar(1) not null, value varchar(32) not null, fk_category_id varchar(32) not null, primary key (id)); 13 | create table TB_DICTIONARY_CATEGORY (id varchar(32) not null, code varchar(128) not null, name varchar(256) not null, remark varchar(512), fk_parent_id varchar(32), primary key (id)); 14 | 15 | --创建权限表 16 | create table TB_GROUP (id varchar(32) not null, name varchar(32) not null, remark varchar(512), state integer not null, type varchar(2) not null, fk_parent_id varchar(32), role varchar(64), value varchar(256), primary key (id)); 17 | create table TB_GROUP_RESOURCE (fk_resource_id varchar(32) not null, fk_group_id varchar(32) not null); 18 | create table TB_GROUP_USER (fk_group_id varchar(32) not null, fk_user_id varchar(32) not null); 19 | create table TB_RESOURCE (id varchar(32) not null, permission varchar(64), remark varchar(512), sort integer not null, name varchar(32) not null, type varchar(2) not null, value varchar(256), fk_parent_id varchar(32), icon varchar(32), leaf boolean, primary key (id)); 20 | create table TB_USER (id varchar(32) not null, email varchar(128), password varchar(32) not null, portrait varchar(256), realname varchar(64) not null, state integer not null, username varchar(32) not null, primary key (id)); 21 | 22 | --创建审计表 23 | create table TB_OPERATING_RECORD (id varchar(32) not null, end_date timestamp not null, fk_user_id varchar(32), operating_target varchar(512) not null, start_date timestamp not null, username varchar(32), function varchar(128), ip varchar(64) not null, method varchar(256) not null, module varchar(128), remark clob, state integer not null, primary key (id)); 24 | 25 | --创建所有表关联 26 | alter table TB_DICTIONARY_CATEGORY add constraint UK_9qkei4dxobl1lm4oa0ys8c3nr unique (code); 27 | alter table TB_GROUP add constraint UK_byw2jrrrxrueqimkmgj3o842j unique (name); 28 | alter table TB_RESOURCE add constraint UK_aunvlvm32xb4e6590jc9oooq unique (name); 29 | alter table TB_USER add constraint UK_4wv83hfajry5tdoamn8wsqa6x unique (username); 30 | alter table TB_DATA_DICTIONARY add constraint FK_layhfd1butuigsscgucmp2okd foreign key (fk_category_id) references TB_DICTIONARY_CATEGORY; 31 | alter table TB_DICTIONARY_CATEGORY add constraint FK_bernf41kympxy2kjl4vbq5q44 foreign key (fk_parent_id) references TB_DICTIONARY_CATEGORY; 32 | alter table TB_GROUP add constraint FK_idve4hc50mytxm181wl1knw28 foreign key (fk_parent_id) references tb_group; 33 | alter table TB_GROUP_RESOURCE add constraint FK_q82fpmfh128qxoeyymrkg71e2 foreign key (fk_group_id) references TB_GROUP; 34 | alter table TB_GROUP_RESOURCE add constraint FK_3tjs4wt3vvoibo1fvcvog5srd foreign key (fk_resource_id) references TB_RESOURCE; 35 | alter table TB_GROUP_USER add constraint FK_7k068ltfepa1q75qtmvxuawk foreign key (fk_user_id) references TB_USER; 36 | alter table TB_GROUP_USER add constraint FK_rgmkki7dggfag6ow6eivljmwv foreign key (fk_group_id) references TB_GROUP; 37 | alter table TB_RESOURCE add constraint FK_k2heqvi9muk4cjyyd53r9y37x foreign key (fk_parent_id) references TB_RESOURCE; -------------------------------------------------------------------------------- /showcase/base-curd/src/test/resources/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 29 | 30 | 31 | 32 | 33 | com.mysql.jdbc.Driver 34 | 35 | root 36 | root 37 | 38 | org.hibernate.dialect.MySQL5InnoDBDialect 39 | 40 | 41 | jdbc:mysql://localhost:3306/base-curd?autoReconnect=true 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | --------------------------------------------------------------------------------