├── .gitignore ├── DatabaseDialects.xls ├── LICENSE ├── README.md ├── README_ENG.md ├── command.bat ├── core ├── LICENSE ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── github │ │ └── drinkjava2 │ │ ├── jbeanbox │ │ ├── ClassScanner.java │ │ └── NameMatchUtil.java │ │ ├── jdialects │ │ ├── ArrayUtils.java │ │ ├── ClassCacheUtils.java │ │ ├── DDLCreateUtils.java │ │ ├── DDLDropUtils.java │ │ ├── DDLFeatures.java │ │ ├── DDLFormatter.java │ │ ├── DebugUtils.java │ │ ├── Dialect.java │ │ ├── DialectException.java │ │ ├── DialectFunctionTemplate.java │ │ ├── DialectFunctionTranslator.java │ │ ├── DialectFunctionUtils.java │ │ ├── DialectPaginationTemplate.java │ │ ├── DialectType.java │ │ ├── DialectTypeMappingTemplate.java │ │ ├── GuessDialectUtils.java │ │ ├── Java8DateUtils.java │ │ ├── JdbcUtil.java │ │ ├── NamingConversion.java │ │ ├── PackageInfo.java │ │ ├── ReservedDBWords.java │ │ ├── SqlFormatter.java │ │ ├── StrUtils.java │ │ ├── TableModelUtils.java │ │ ├── TableModelUtilsOfDb.java │ │ ├── TableModelUtilsOfEntity.java │ │ ├── TableModelUtilsOfExcel.java │ │ ├── TableModelUtilsOfJavaSrc.java │ │ ├── Type.java │ │ ├── TypeUtils.java │ │ ├── annotation │ │ │ ├── jdia │ │ │ │ ├── AutoId.java │ │ │ │ ├── COLUMN.java │ │ │ │ ├── CreateTimestamp.java │ │ │ │ ├── CreatedBy.java │ │ │ │ ├── FKey.java │ │ │ │ ├── FKey1.java │ │ │ │ ├── FKey2.java │ │ │ │ ├── FKey3.java │ │ │ │ ├── IdentityId.java │ │ │ │ ├── LastModifiedBy.java │ │ │ │ ├── PKey.java │ │ │ │ ├── ShardDatabase.java │ │ │ │ ├── ShardTable.java │ │ │ │ ├── SingleFKey.java │ │ │ │ ├── SingleIndex.java │ │ │ │ ├── SingleUnique.java │ │ │ │ ├── Snowflake.java │ │ │ │ ├── TimeStampId.java │ │ │ │ ├── UUID.java │ │ │ │ ├── UUID25.java │ │ │ │ ├── UUID26.java │ │ │ │ ├── UUID32.java │ │ │ │ ├── UUID36.java │ │ │ │ ├── UUIDAny.java │ │ │ │ └── UpdateTimestamp.java │ │ │ └── jpa │ │ │ │ ├── Column.java │ │ │ │ ├── Convert.java │ │ │ │ ├── Entity.java │ │ │ │ ├── EnumType.java │ │ │ │ ├── Enumerated.java │ │ │ │ ├── GeneratedValue.java │ │ │ │ ├── GenerationType.java │ │ │ │ ├── Id.java │ │ │ │ ├── Index.java │ │ │ │ ├── SequenceGenerator.java │ │ │ │ ├── Table.java │ │ │ │ ├── TableGenerator.java │ │ │ │ ├── Temporal.java │ │ │ │ ├── TemporalType.java │ │ │ │ ├── Transient.java │ │ │ │ ├── UniqueConstraint.java │ │ │ │ └── Version.java │ │ ├── converter │ │ │ ├── BasicJavaConverter.java │ │ │ ├── BasicJavaToJdbcConverter.java │ │ │ ├── BasicJdbcToJavaConverter.java │ │ │ ├── JavaConverter.java │ │ │ ├── JavaToJdbcConverter.java │ │ │ └── JdbcToJavaConverter.java │ │ ├── id │ │ │ ├── AutoIdGenerator.java │ │ │ ├── IdGenerator.java │ │ │ ├── IdentityIdGenerator.java │ │ │ ├── SequenceIdGenerator.java │ │ │ ├── SnowflakeCreator.java │ │ │ ├── SnowflakeGenerator.java │ │ │ ├── SortedUUIDGenerator.java │ │ │ ├── TableIdGenerator.java │ │ │ ├── TimeStampIdGenerator.java │ │ │ ├── UUID25Generator.java │ │ │ ├── UUID26Generator.java │ │ │ ├── UUID32Generator.java │ │ │ ├── UUID36Generator.java │ │ │ ├── UUIDAnyGenerator.java │ │ │ └── UUIDGenerator.java │ │ ├── model │ │ │ ├── ColumnModel.java │ │ │ ├── FKeyModel.java │ │ │ ├── IndexModel.java │ │ │ ├── TableModel.java │ │ │ └── UniqueModel.java │ │ └── springsrc │ │ │ ├── PackageInfo.java │ │ │ └── utils │ │ │ ├── Assert.java │ │ │ ├── ClassUtils.java │ │ │ ├── CollectionUtils.java │ │ │ ├── ConcurrentReferenceHashMap.java │ │ │ ├── ObjectUtils.java │ │ │ ├── ReflectionUtils.java │ │ │ └── StringUtils.java │ │ └── jlogs │ │ ├── ConsoleLog.java │ │ ├── EmptyLog.java │ │ ├── Log.java │ │ ├── LogFactory.java │ │ └── SimpleSLF4JLog.java │ └── test │ ├── java │ └── Readme.java │ └── resources │ ├── common-logging.properties │ └── log4j.properties ├── demo ├── demo-jsqlbox │ ├── maven_clean.bat │ ├── maven_eclipse_clean.bat │ ├── maven_eclipse_eclipse.bat │ ├── maven_test.bat │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── drinkjava2 │ │ │ └── demo │ │ │ └── TestDemo.java │ │ └── resources │ │ ├── common-logging.properties │ │ └── log4j.properties ├── demo-mybatis │ ├── maven_clean.bat │ ├── maven_eclipse_clean.bat │ ├── maven_eclipse_eclipse.bat │ ├── maven_test.bat │ ├── pom.xml │ └── src │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── drinkjava2 │ │ │ └── demo │ │ │ └── TestDemo.java │ │ └── resources │ │ ├── common-logging.properties │ │ └── log4j.properties └── demo-pure-jdbc │ ├── maven_clean.bat │ ├── maven_eclipse_clean.bat │ ├── maven_eclipse_eclipse.bat │ ├── maven_test.bat │ ├── pom.xml │ └── src │ └── test │ ├── java │ └── com │ │ └── github │ │ └── drinkjava2 │ │ └── demo │ │ └── TestDemo.java │ └── resources │ ├── common-logging.properties │ └── log4j.properties └── jdialects-logo.png /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | target/ 3 | bin/ 4 | .project 5 | .classpath 6 | .settings/ 7 | *~ 8 | *.orig 9 | *.new 10 | .idea/ 11 | *.iml 12 | *.ipr 13 | test/**/build/ 14 | examples/**/build/ -------------------------------------------------------------------------------- /DatabaseDialects.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drinkjava2/jDialects/e08cc354c2b3be6f4a710a8c3659d8c0b2609914/DatabaseDialects.xls -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | English instruction see "README_ENG.md" 4 | 5 |
6 |
7 |
8 |
9 |
10 |
13 | 一个通用数据库方言工具 14 |
15 | 16 | # 简介 | Intro 17 | 18 | jDialects支持多达80多种数据库方言的DDL创建、实体源码生成、分页、函数变换、类型变换及主要的JPA注解解析功能。 19 | 它通常与JDBC工具组合使用,也可以作为其它Dao工具(如jSqlBox)的一个组成部分。 20 | 21 | # 优点 | Advantages 22 | 23 | - **无侵入**:jDialects工作原理基于对SQL文本进行变换,不会对您现有的持久层工具产生任何影响。 24 | - **依赖少**:仅依赖单个jar文件, 大小约280k。 25 | - **从Annotation创建DDL**:提供对一些主要的JPA注解的支持 26 | - **从Java方法创建DDL**:提供Java方法配置来创建DDL,同样的语法也可以在运行期修改配置。 27 | - **从数据库生成实体类源码**:可以读取数据库结构,生成注解风格的实体类POJO或ActiveRecord实体类源码 28 | - **主键生成器**:提供十种主键生成器,和一个分布式主键生成器。 29 | - **分页**:提供跨数据库的分页方法。 30 | - **函数变换**:对不同的数据库解析成对应方言的函数,尽量做到一次SQL到处运行。 31 | - **类型变换**:对不同的数据库字段类型,提供与Java类型的互相变换。 32 | - **保留字检查**:提供数据库保留字检查功能。 33 | 34 | # 文档 | Documentation 35 | 36 | [中文](https://gitee.com/drinkjava2/jdialects/wikis/pages) | [English](https://gitee.com/drinkjava2/jdialects/wiki) 37 | 38 | [JavaDoc](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jdialects%22) 39 | 40 | # 应用示例 | Demo 41 | 42 | [在纯JDBC中使用](https://gitee.com/drinkjava2/jdialects/wikis/pages?title=8.1-%E5%9C%A8%E7%BA%AFJDBC%E9%A1%B9%E7%9B%AE%E4%B8%AD%E4%BD%BF%E7%94%A8&parent=%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C) 43 | 44 | [在jSqlBox中使用](https://gitee.com/drinkjava2/jdialects/wikis/pages?title=8.2-%E5%9C%A8jSqlBox%E9%A1%B9%E7%9B%AE%E4%B8%AD%E4%BD%BF%E7%94%A8&parent=%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C) 45 | 46 | [在MyBatis中使用](https://gitee.com/drinkjava2/jdialects/wikis/pages?title=8.3-%E5%9C%A8MyBatis%E4%B8%AD%E4%BD%BF%E7%94%A8&parent=%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C) 47 | 48 | # 下载地址 | Download 49 | 50 | [点此去下载](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jdialects%22) 51 | 或在项目pom.xml中添加: 52 | ```xml 53 |
2 |
3 |
4 |
5 |
8 | A Database Dialect Tool 9 |
10 | 11 | # Introduction 12 | 13 | jDialects supports DDL creation, paging, function transformation, type conversion and major JPA annotation parsing functions for up to 80 database dialects. 14 | It is usually used in combination with JDBC tools and as part of other Dao tools such as jSqlBox. 15 | jDialects requires JDK1.6+ 16 | 17 | # Advantages 18 | - **No intrusion**: jDialects works based on transforming SQL text without any impact on your existing persistence layer tools. 19 | - ** Less dependency**: Only rely on a single jar file, about 280k in size. 20 | - **Create DDL from Annotation**: Support build DDL from major JPA annotations 21 | - **Create DDL from Java methods**: Provide Java method configuration to create DDL, the same Java methods can also used at runtime. 22 | - **Primary Key Generator**: Provides ten primary key generators and supports custom primary key generators. A distributed primary key generator is also provided. 23 | - **Paging**: Provides a cross-database pagination method. 24 | - **Function transformation**: Parse different databases' functions corresponding dialects. 25 | - ** type conversion**: Provides mutual transformation with Java types for different database data types. 26 | - **Reserved Word Check**: Provides database reserved word checking. 27 | 28 | # Documentation 29 | 30 | [Chinese](https://gitee.com/drinkjava2/jdialects/wikis/pages) | [English](https://gitee.com/drinkjava2/jdialects/wiki) 31 | 32 | [JavaDoc](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jdialects%22) 33 | 34 | # Demo 35 | 36 | [For Pure JDBC](https://github.com/drinkjava2/jDialects/tree/master/demo/demo-pure-jdbc) 37 | 38 | [For jSqlBox](https://github.com/drinkjava2/jDialects/tree/master/demo/demo-jsqlbox) 39 | 40 | [For MyBatis](https://github.com/drinkjava2/jDialects/tree/master/demo/demo-mybatis) 41 | 42 | # Download 43 | 44 | [Download here](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jdialects%22) 45 | Or put below in pom.xml: 46 | ```xml 47 |26 | * Template can be: 27 | * "*": standard SQL function, identical to abc($Params) 28 | * "abc($Params)": template with special parameter format: 29 | "$P1, $P2, $P3, $P4, $P5, $P6..."="$Params" 30 | "$P1,$P2,$P3,$P4,$P5,$P6..."="$Compact_Params" 31 | "$P1||$P2||$P3||$P4||$P5||$P6..."="$Lined_Params" 32 | "$P1+$P2+$P3+$P4+$P5+$P6..."="$Add_Params"); 33 | "$P1 in $P2 in $P3 in $P4 in $P5 in $P6..."="$IN_Params" 34 | "$P1%pattern$P2%pattern$P3%pattern$P4%pattern$P5%pattern$P6..."="$Pattern_Params" 35 | "11%startswith$P2%startswith$P3%startswith$P4%startswith$P5%startswith$P6..."= "$Startswith_Params"); 36 | "nvl($P1, nvl($P2, nvl($P3, nvl($P4, nvl($P5, $P6...)))))"="$NVL_Params"); 37 | * 38 | * "0=abc()": function do not support parameter 39 | * "1=abc($P1)": function only support 1 parameter 40 | * "2=abc($P1,$P2)": function only support 2 parameters 41 | * "0=abc()|1=abc($P1)|3=abc($P1,$P2,$P3)": function support 0 or 1 or 3 parameters 42 | * 43 | *44 | * 45 | * @param functionName function name 46 | * @param args function parameters 47 | * @return A SQL function piece 48 | */ 49 | protected static String render(Dialect d, String functionName, String... args) { 50 | String template = d.functions.get(functionName.toLowerCase()); 51 | DialectException.assureNotEmpty(template, "Dialect \"" + d + "\" does not support \"" + functionName 52 | + "\" function, a full list of supported functions of this dialect can see \"DatabaseDialects.xls\""); 53 | if ("*".equals(template)) 54 | template = functionName + "($Params)"; 55 | char c = template.charAt(1); 56 | if (c != '=') { 57 | if (template.indexOf("$Params") >= 0) { 58 | return StrUtils.replace(template, "$Params", StrUtils.arrayToString(args, ", ")); 59 | } 60 | if (template.indexOf("$Compact_Params") >= 0) { 61 | return StrUtils.replace(template, "$Compact_Params", StrUtils.arrayToString(args, ",")); 62 | } 63 | if (template.indexOf("$Lined_Params") >= 0) { 64 | return StrUtils.replace(template, "$Lined_Params", StrUtils.arrayToString(args, "||")); 65 | } 66 | if (template.indexOf("$Add_Params") >= 0) { 67 | return StrUtils.replace(template, "$Add_Params", StrUtils.arrayToString(args, "+")); 68 | } 69 | if (template.indexOf("$IN_Params") >= 0) { 70 | return StrUtils.replace(template, "$IN_Params", StrUtils.arrayToString(args, " in ")); 71 | } 72 | if (template.indexOf("$Pattern_Params") >= 0) { 73 | return StrUtils.replace(template, "$Pattern_Params", StrUtils.arrayToString(args, "%pattern")); 74 | } 75 | if (template.indexOf("$Startswith_Params") >= 0) { 76 | return StrUtils.replace(template, "$Startswith_Params", StrUtils.arrayToString(args, "%startswith")); 77 | } 78 | if (template.indexOf("$NVL_Params") >= 0) { 79 | if (args == null || args.length < 2) 80 | DialectException.throwEX("Nvl function require at least 2 parameters"); 81 | else { 82 | String s = "nvl(" + args[args.length - 2] + ", " + args[args.length - 1] + ")"; 83 | for (int i = args.length - 3; i > -1; i--) 84 | s = "nvl(" + args[i] + ", " + s + ")"; 85 | return StrUtils.replace(template, "$NVL_Params", s); 86 | } 87 | } 88 | return (String) DialectException.throwEX("jDialect found a template bug error, please submit this bug"); 89 | } else { 90 | int argsCount = 0; 91 | if (args != null) 92 | argsCount = args.length; 93 | String searchStr = Integer.toString(argsCount) + "="; 94 | if (template.indexOf(searchStr) < 0) 95 | DialectException.throwEX("Dialect " + d + "'s function \"" + functionName + "\" only support " 96 | + allowedParameterQTY(template) + " parameters"); 97 | String result = StrUtils.substringBetween(template + "|", searchStr, "|"); 98 | for (int i = 0; args != null && i < args.length; i++) { 99 | result = StrUtils.replace(result, "$P" + (i + 1), "" + args[i]); 100 | } 101 | return result; 102 | } 103 | } 104 | 105 | private static String allowedParameterQTY(String template) { 106 | StringBuilder sb = new StringBuilder(); 107 | for (int i = 0; i < 5; i++) { 108 | if (template.indexOf(Integer.toString(i) + "=") >= 0) 109 | sb.append(Integer.toString(i)).append(" or "); 110 | } 111 | if (sb.length() > 0) 112 | sb.setLength(sb.length() - 4); 113 | return sb.toString(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/DialectType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects; 13 | 14 | /** 15 | * DialectType is a enum list all dialects, if customized dialect, use 16 | * "Customized" type. 17 | * 18 | * @author Yong Zhu 19 | * @since 1.7.0 20 | */ 21 | @SuppressWarnings("all") 22 | public enum DialectType { //这个类没啥用,主要用于方便使用case遍历 23 | Customized, // 24 | DerbyDialect, OracleDialect, Oracle9Dialect, DamengDialect, GBaseDialect, AccessDialect, CobolDialect, DbfDialect, ExcelDialect, ParadoxDialect, SQLiteDialect, TextDialect, XMLDialect, Cache71Dialect, CUBRIDDialect, DataDirectOracle9Dialect, DB2390Dialect, DB2390V8Dialect, DB2400Dialect, DB297Dialect, DB2Dialect, DerbyTenFiveDialect, DerbyTenSevenDialect, DerbyTenSixDialect, FirebirdDialect, FrontBaseDialect, H2Dialect, HANAColumnStoreDialect, HANARowStoreDialect, HSQLDialect, Informix10Dialect, InformixDialect, Ingres10Dialect, Ingres9Dialect, IngresDialect, InterbaseDialect, JDataStoreDialect, MariaDB102Dialect, MariaDB103Dialect, MariaDB10Dialect, MariaDB53Dialect, MariaDBDialect, MckoiDialect, MimerSQLDialect, MySQL55Dialect, MySQL57Dialect, MySQL57InnoDBDialect, MySQL5Dialect, MySQL5InnoDBDialect, MySQL8Dialect, MySQLDialect, MySQLInnoDBDialect, MySQLMyISAMDialect, Oracle10gDialect, Oracle12cDialect, Oracle8iDialect, Oracle9iDialect, PointbaseDialect, PostgresPlusDialect, PostgreSQL81Dialect, PostgreSQL82Dialect, PostgreSQL91Dialect, PostgreSQL92Dialect, PostgreSQL93Dialect, PostgreSQL94Dialect, PostgreSQL95Dialect, PostgreSQL9Dialect, PostgreSQLDialect, ProgressDialect, RDMSOS2200Dialect, SAPDBDialect, SQLServer2005Dialect, SQLServer2008Dialect, SQLServer2012Dialect, SQLServerDialect, Sybase11Dialect, SybaseAnywhereDialect, SybaseASE157Dialect, SybaseASE15Dialect, SybaseDialect, Teradata14Dialect, TeradataDialect, TimesTenDialect; 25 | 26 | public static DialectType getDialectType(Dialect d) { 27 | DialectType diaType = null; 28 | try { 29 | diaType = DialectType.valueOf(d.getName()); 30 | } catch (Exception e) { 31 | diaType = DialectType.Customized; 32 | } 33 | return diaType; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/Java8DateUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects; 13 | 14 | /*- JAVA8_BEGIN */ 15 | import java.sql.Timestamp; 16 | import java.time.Instant; 17 | import java.time.LocalDate; 18 | import java.time.LocalDateTime; 19 | import java.time.LocalTime; 20 | import java.time.OffsetDateTime; 21 | import java.time.OffsetTime; 22 | import java.time.ZoneId; 23 | import java.time.ZonedDateTime; 24 | import java.util.Date; 25 | 26 | public abstract class Java8DateUtils {// NOSONAR 27 | 28 | private static final ZoneId zoneId = ZoneId.systemDefault(); 29 | 30 | public static LocalDate date2LocalDate(java.util.Date date) { 31 | Instant instant = new Date(date.getTime()).toInstant(); 32 | return instant.atZone(zoneId).toLocalDate(); 33 | } 34 | 35 | public static LocalDateTime date2LocalDateTime(Date date) { 36 | Instant instant = date.toInstant(); 37 | return instant.atZone(zoneId).toLocalDateTime(); 38 | } 39 | 40 | public static Date localDate2Date(LocalDate localDate) { 41 | ZonedDateTime zdt = localDate.atStartOfDay(zoneId); 42 | return Date.from(zdt.toInstant()); 43 | } 44 | 45 | public static Date localDateTime2Date(LocalDateTime localDateTime) { 46 | ZonedDateTime zdt = localDateTime.atZone(zoneId); 47 | return new Date(Date.from(zdt.toInstant()).getTime()); 48 | } 49 | 50 | // below to conver java8 date types to sql type 51 | 52 | public static java.sql.Date localDate2SqlDate(LocalDate localDate) { 53 | ZonedDateTime zdt = localDate.atStartOfDay(zoneId); 54 | return new java.sql.Date(Date.from(zdt.toInstant()).getTime()); 55 | } 56 | 57 | public static java.sql.Time localTime2SqlTime(LocalTime localTime) { 58 | return java.sql.Time.valueOf(localTime); 59 | } 60 | 61 | public static java.sql.Time offsetTime2SqlTime(OffsetTime offsetTime) { 62 | return java.sql.Time.valueOf(offsetTime.toLocalTime()); 63 | } 64 | 65 | public static java.sql.Timestamp instant2SqlTimestamp(Instant instant) { 66 | return new java.sql.Timestamp(Date.from(instant).getTime()); 67 | } 68 | 69 | public static java.sql.Timestamp localDateTime2SqlTimestamp(LocalDateTime localDateTime) { 70 | return Timestamp.valueOf(localDateTime); 71 | } 72 | 73 | public static java.sql.Timestamp offsetDateTime2SqlTimestamp(OffsetDateTime offsetDateTime) { 74 | return Timestamp.valueOf(offsetDateTime.toLocalDateTime()); 75 | } 76 | 77 | public static java.sql.Timestamp zonedDateTime2SqlTimestamp(ZonedDateTime zonedDateTime) { 78 | return Timestamp.valueOf(zonedDateTime.toLocalDateTime()); 79 | } 80 | 81 | // below to conver sql date types to java8 types 82 | public static LocalDate sqlDate2localDate(java.sql.Date date) { 83 | Instant instant = new Date(date.getTime()).toInstant(); 84 | return instant.atZone(zoneId).toLocalDate(); 85 | } 86 | 87 | public static LocalDateTime sqlDate2localDateTime(java.sql.Date date) { 88 | Instant instant = new Date(date.getTime()).toInstant(); 89 | return instant.atZone(zoneId).toLocalDateTime(); 90 | } 91 | 92 | public static LocalTime sqlTime2LocalTime(java.sql.Time time) { 93 | return time.toLocalTime(); 94 | } 95 | 96 | // extra 97 | public static LocalDateTime sqlTime2LocalDateTime(java.sql.Time time) { 98 | Instant instant = new Date(time.getTime()).toInstant(); 99 | return instant.atZone(zoneId).toLocalDateTime(); 100 | } 101 | 102 | public static OffsetTime sqlTime2OffsetTime(java.sql.Time time) { 103 | Instant instant = new Date(time.getTime()).toInstant(); 104 | return OffsetTime.ofInstant(instant, zoneId); 105 | } 106 | 107 | public static OffsetTime sqlTimestamp2OffsetTime(Timestamp t) { 108 | return OffsetTime.ofInstant(t.toInstant(), zoneId); 109 | } 110 | 111 | public static Instant sqlTimestamp2instant(Timestamp t) { 112 | return t.toInstant(); 113 | } 114 | 115 | public static LocalDateTime sqlTimestamp2LocalDateTime(Timestamp t) { 116 | return t.toLocalDateTime(); 117 | } 118 | 119 | public static OffsetDateTime sqlTimestamp2OffsetDateTime(Timestamp t) { 120 | return OffsetDateTime.ofInstant(t.toInstant(), zoneId); 121 | } 122 | 123 | public static ZonedDateTime sqlTimestamp2ZonedDateTime(Timestamp t) { 124 | return ZonedDateTime.ofInstant(t.toInstant(), zoneId); 125 | } 126 | 127 | public static LocalDate sqlTimestamp2LocalDate(Timestamp t) { 128 | Instant instant = new Date(t.getTime()).toInstant(); 129 | return instant.atZone(zoneId).toLocalDate(); 130 | } 131 | 132 | public static LocalTime sqlTimestamp2LocalTime(Timestamp t) { 133 | Instant instant = new Date(t.getTime()).toInstant(); 134 | return instant.atZone(zoneId).toLocalTime(); 135 | } 136 | } 137 | /* JAVA8_END */ -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/JdbcUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016 Yong Zhu. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package com.github.drinkjava2.jdialects; 17 | 18 | import java.sql.Connection; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | 23 | import javax.sql.DataSource; 24 | 25 | /** 26 | * A tiny pure JDBC tool to access database 27 | * 28 | * 29 | * @author Yong Zhu 30 | * @version 1.0.0 31 | */ 32 | public abstract class JdbcUtil {//NOSONAR 33 | 34 | /** 35 | * Return sql query result object in first row first column 36 | * @param Connection 37 | * @param sql 38 | * @param params 39 | * @return object in first row first column 40 | */ 41 | @SuppressWarnings("unchecked") 42 | public static
18 | * For example: 19 | * //OrderDetail.class map to OrderDetail database table, entity field OrderPrice map to OrderPrice column 20 | * Dialect.setGlobalNamingRule(NamingRule.NONE); 21 | * 22 | * //OrderDetail.class map to order_detail database table, entity field OrderPrice map to order_price column 23 | * Dialect.setGlobalNamingRule(NamingRule.LOWER_CASE_UNDERSCORE); // 24 | * 25 | * //OrderDetail.class map to ORDER_DETAIL database table, entity field OrderPrice map to ORDER_PRICE column 26 | * Dialect.setGlobalNamingRule(NamingRule.UPPER_CASE_UNDERSCORE); 27 | *28 | * 29 | * @author Yong 30 | * @since 5.0.10 31 | */ 32 | public interface NamingConversion { 33 | 34 | /** Get table name from entity class */ 35 | public String getTableName(Class> clazz); 36 | 37 | /** Get column name from entity field */ 38 | public String getColumnName(String entityField); 39 | 40 | public static final NamingConversion NONE = null; 41 | public static final NamingConversion LOWER_CASE_UNDERSCORE = new LowerCaseUnderscoreConversion(); 42 | public static final NamingConversion UPPER_CASE_UNDERSCORE = new UpperCaseUnderscoreConversion(); 43 | 44 | 45 | public static class LowerCaseUnderscoreConversion implements NamingConversion { 46 | @Override 47 | public String getTableName(Class> clazz) { 48 | return StrUtils.camelToLowerCaseUnderScore(clazz.getSimpleName()); 49 | } 50 | 51 | @Override 52 | public String getColumnName(String entityField) { 53 | return StrUtils.camelToLowerCaseUnderScore(entityField); 54 | } 55 | } 56 | 57 | public static class UpperCaseUnderscoreConversion implements NamingConversion { 58 | @Override 59 | public String getTableName(Class> clazz) { 60 | return StrUtils.camelToLowerCaseUnderScore(clazz.getSimpleName()).toUpperCase(); 61 | } 62 | 63 | @Override 64 | public String getColumnName(String entityField) { 65 | return StrUtils.camelToLowerCaseUnderScore(entityField).toUpperCase(); 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/PackageInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects; 13 | 14 | /** 15 | * jDialect is a separate project has its own Maven central releases. 16 | */ 17 | public class PackageInfo {// NOSONAR 18 | 19 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/SqlFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects; 13 | 14 | import java.util.HashSet; 15 | import java.util.Set; 16 | 17 | /** 18 | * @author Yong Zhu 19 | * @since 2.0.4 20 | */ 21 | public class SqlFormatter { 22 | private static final Set
UniqueConstraint
annotation at the table level and is useful for
40 | * when the unique key constraint corresponds to only a single column. This
41 | * constraint applies in addition to any constraint entailed by primary key
42 | * mapping and to constraints specified at the table level.
43 | */
44 | boolean unique() default false;
45 |
46 | /**
47 | * (Optional) Whether the database column is nullable.
48 | */
49 | boolean nullable() default true;
50 |
51 | /**
52 | * (Optional) Whether the column is included in SQL INSERT statements generated
53 | * by the persistence provider.
54 | */
55 | boolean insertable() default true;
56 |
57 | /**
58 | * (Optional) Whether the column is included in SQL UPDATE statements generated
59 | * by the persistence provider.
60 | */
61 | boolean updatable() default true;
62 |
63 | /**
64 | * (Optional) The SQL fragment that is used when generating the DDL for the
65 | * column.
66 | * 67 | * Defaults to the generated SQL to create a column of the inferred type. 68 | */ 69 | String columnDefinition() default ""; 70 | 71 | /** 72 | * (Optional) The name of the table that contains the column. If absent the 73 | * column is assumed to be in the primary table. 74 | */ 75 | String table() default ""; 76 | 77 | /** 78 | * (Optional) The column length. (Applies only if a string-valued column is 79 | * used.) 80 | */ 81 | int length() default 255; 82 | 83 | /** 84 | * (Optional) The precision for a decimal (exact numeric) column. (Applies only 85 | * if a decimal column is used.) Value must be set by developer if used when 86 | * generating the DDL for the column. 87 | */ 88 | int precision() default 0; 89 | 90 | /** 91 | * (Optional) The scale for a decimal (exact numeric) column. (Applies only if a 92 | * decimal column is used.) 93 | */ 94 | int scale() default 0; 95 | 96 | /** (Optional)The comment String, usage: @Column(comment="abc"); */ 97 | String comment() default ""; 98 | 99 | /** (Optional)The Tail String, usage: @Column(tail="default now()"); */ 100 | String tail() default ""; 101 | 102 | /** (Optional)When insert bean will write current timestamp value */ 103 | boolean createTimestamp() default false; 104 | 105 | /** (Optional)When update bean will update current timestamp value */ 106 | boolean updateTimestamp() default false; 107 | 108 | /** 109 | * (Optional)When insert bean will write current userId, usage: 110 | * 111 | *
112 | * 1. Write a class which have a getCurrentAuditor method 113 | * 2. Call JBEANBOX.bind("AuditorAware", XxxClass.class) to bind it 114 | * 115 | * For example: 116 | * public class XxxxUserAuditor{ 117 | * public Object getCurrentAuditor() { 118 | * return XxxxSecurityTool.getUserXxxxId(); 119 | * } 120 | * } 121 | * 122 | * JBEANBOX.bind("AuditorAware", XxxxUserAuditor.class); 123 | *124 | */ 125 | boolean createdBy() default false; 126 | 127 | /** (Optional)When update bean will write current userId, usage see createdBy */ 128 | boolean lastModifiedBy() default false; 129 | } 130 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/CreateTimestamp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * Mark a CreateTimestamp column, explained by ORM tool 22 | * 23 | * @author Yong Zhu 24 | * @since 4.0.2 25 | */ 26 | @Target({ FIELD }) 27 | @Retention(RUNTIME) 28 | 29 | public @interface CreateTimestamp { 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/CreatedBy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * Mark a CreatedBy column, explained by ORM tool 22 | * 23 | * @author Yong Zhu 24 | * @since 4.0.2 25 | */ 26 | @Target({ FIELD }) 27 | @Retention(RUNTIME) 28 | 29 | public @interface CreatedBy { 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/FKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.TYPE; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * Specifies the foreign key 22 | * 23 | *
24 | * Example: 25 | * 26 | * @FKey(name = "fkey1", ddl = true, columns = { "field1", "field2" }, refs = { "Entity1", "field1", "field2" }) 27 | * public class SomeClass() 28 | *29 | * 30 | * @since jDialects 1.0.5 31 | */ 32 | @Target(TYPE) 33 | @Retention(RUNTIME) 34 | public @interface FKey { 35 | /** 36 | * (Optional) The name of the foreign key. 37 | */ 38 | String name() default ""; 39 | 40 | /** 41 | * Columns in this table 42 | */ 43 | String[] columns() default {}; 44 | 45 | /** 46 | * Referenced table name and columns, first is table name, followed by column 47 | * names, like "table1, col1, col2..." 48 | */ 49 | String[] refs() default {}; 50 | 51 | /** 52 | * if ddl set to false, will not output DDL when call TableModelUtils's 53 | * entity2Model() and oneEntity2Model methods 54 | */ 55 | boolean ddl() default true; 56 | } 57 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/FKey1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.TYPE; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | 21 | /** 22 | * Specifies the foreign key 23 | 24 | *
25 | * Example: 26 | * 27 | * @FKey1(name="fk_1", columns="field1,field2", ref="OtherTable, field1, field2") 28 | * public class SomeClass() 29 | *30 | * 31 | * @since jDialects 1.0.5 32 | */ 33 | @Target(TYPE) 34 | @Retention(RUNTIME) 35 | public @interface FKey1 { 36 | /** 37 | * (Optional) The name of the foreign key. 38 | */ 39 | String name() default ""; 40 | 41 | 42 | /** 43 | * Columns in this table 44 | */ 45 | String[] columns() default {}; 46 | 47 | /** 48 | * Referenced table name and columns, first is table name, followed by column 49 | * names, like "table1, col1, col2..." 50 | */ 51 | String[] refs() default {}; 52 | 53 | /** 54 | * if ddl set to false, will not output DDL when call TableModelUtils's 55 | * entity2Model() and oneEntity2Model methods 56 | */ 57 | boolean ddl() default true; 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/FKey2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.TYPE; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | 21 | /** 22 | * Specifies the foreign key 23 | 24 | *
25 | * Example: 26 | * 27 | * @FKey2(name="fk_1", columns="field1,field2", ref="OtherTable, field1, field2") 28 | * public class SomeClass() 29 | *30 | * 31 | * @since jDialects 1.0.5 32 | */ 33 | @Target(TYPE) 34 | @Retention(RUNTIME) 35 | public @interface FKey2 { 36 | /** 37 | * (Optional) The name of the foreign key. 38 | */ 39 | String name() default ""; 40 | 41 | 42 | /** 43 | * Columns in this table 44 | */ 45 | String[] columns() default {}; 46 | 47 | /** 48 | * Referenced table name and columns, first is table name, followed by column 49 | * names, like "table1, col1, col2..." 50 | */ 51 | String[] refs() default {}; 52 | 53 | /** 54 | * if ddl set to false, will not output DDL when call TableModelUtils's 55 | * entity2Model() and oneEntity2Model methods 56 | */ 57 | boolean ddl() default true; 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/FKey3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.TYPE; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | 21 | /** 22 | * Specifies the foreign key 23 | 24 | *
25 | * Example: 26 | * 27 | * @FKey3(name="fk_1", columns="field1,field2", ref="OtherTable, field1, field2") 28 | * public class SomeClass() 29 | *30 | * 31 | * @since jDialects 1.0.5 32 | */ 33 | @Target(TYPE) 34 | @Retention(RUNTIME) 35 | public @interface FKey3 { 36 | /** 37 | * (Optional) The name of the foreign key. 38 | */ 39 | String name() default ""; 40 | 41 | 42 | /** 43 | * Columns in this table 44 | */ 45 | String[] columns() default {}; 46 | 47 | /** 48 | * Referenced table name and columns, first is table name, followed by column 49 | * names, like "table1, col1, col2..." 50 | */ 51 | String[] refs() default {}; 52 | 53 | /** 54 | * if ddl set to false, will not output DDL when call TableModelUtils's 55 | * entity2Model() and oneEntity2Model methods 56 | */ 57 | boolean ddl() default true; 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/IdentityId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 15 | import static java.lang.annotation.ElementType.FIELD; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * A shortcut annotation equal to 22 | * @GenertedValue(strategy=GenerationType.IDENTITY) 23 | */ 24 | @Target(FIELD) 25 | @Retention(RUNTIME) 26 | public @interface IdentityId { 27 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/LastModifiedBy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * Mark a LastModifiedBy column, explained by ORM tool 22 | * 23 | * @author Yong Zhu 24 | * @since 4.0.2 25 | */ 26 | @Target({ FIELD }) 27 | @Retention(RUNTIME) 28 | 29 | public @interface LastModifiedBy { 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/PKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import java.lang.annotation.Target; 15 | 16 | import com.github.drinkjava2.jdialects.annotation.jpa.Column; 17 | import com.github.drinkjava2.jdialects.annotation.jpa.GeneratedValue; 18 | 19 | import java.lang.annotation.Retention; 20 | import static java.lang.annotation.ElementType.FIELD; 21 | import static java.lang.annotation.ElementType.METHOD; 22 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 23 | 24 | /** 25 | * Specifies the primary key of an entity. 26 | * The field or property to which the
PKey
annotation is applied
27 | * should be one of the following types: any Java primitive type;
28 | * any primitive wrapper type;
29 | * String
;
30 | * java.util.Date
;
31 | * java.sql.Date
;
32 | * java.math.BigDecimal
;
33 | * java.math.BigInteger
.
34 | *
35 | * The mapped column for the primary key of the entity is assumed
36 | * to be the primary key of the primary table. If no Column
annotation
37 | * is specified, the primary key column name is assumed to be the name
38 | * of the primary key property or field.
39 | *
40 | *
41 | * Example: 42 | * 43 | * @Pkey 44 | * public Long getId() { return id; } 45 | *46 | * 47 | * @see Column 48 | * @see GeneratedValue 49 | * 50 | */ 51 | @Target({METHOD, FIELD}) 52 | @Retention(RUNTIME) 53 | 54 | public @interface PKey {} 55 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/ShardDatabase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.Target; 18 | 19 | /** 20 | * To mark this column is a ShardDatabase column, one table only allow 1 column 21 | * be marked as ShardDatabase column 22 | * 23 | * @author Yong Zhu 24 | * @since 1.0.5 25 | */ 26 | 27 | @Target(FIELD) 28 | @Retention(RUNTIME) 29 | public @interface ShardDatabase { 30 | String[] value(); 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/ShardTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.Target; 18 | 19 | /** 20 | * To mark this column is a shardTable column, one table only allow 1 column be 21 | * marked as shardiTable column 22 | * 23 | * @author Yong Zhu 24 | * @since 1.0.5 25 | */ 26 | 27 | @Target(FIELD) 28 | @Retention(RUNTIME) 29 | public @interface ShardTable { 30 | String[] value(); 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/SingleFKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 15 | import static java.lang.annotation.ElementType.FIELD; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | 21 | /** 22 | * A shortcut annotation of FKey, only for one column 23 | */ 24 | @Target(FIELD) 25 | @Retention(RUNTIME) 26 | public @interface SingleFKey { 27 | /** 28 | * (Optional) The name of the foreign key. 29 | */ 30 | String name() default ""; 31 | 32 | /** 33 | * Referenced table name and columns, first is table name, followed by column 34 | * names, like "table1, col1, col2..." 35 | */ 36 | String[] refs() default {}; 37 | 38 | /** 39 | * if ddl set to false, will not output DDL when call TableModelUtils's 40 | * entity2Model() and oneEntity2Model methods 41 | */ 42 | boolean ddl() default true; 43 | } 44 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/SingleIndex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.Target; 18 | 19 | /** 20 | * A shortcut annotation of Index, only for one column 21 | */ 22 | @Target(FIELD) 23 | @Retention(RUNTIME) 24 | public @interface SingleIndex { 25 | 26 | /** 27 | * (Optional) The name of the index; defaults to a provider-generated name. 28 | */ 29 | String name() default ""; 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/SingleUnique.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.Target; 18 | 19 | 20 | /** 21 | * A shortcut annotation of Unique, only for one column 22 | * 23 | * @author Yong Zhu 24 | * @since 1.0.5 25 | */ 26 | 27 | @Target(FIELD) 28 | @Retention(RUNTIME) 29 | public @interface SingleUnique { 30 | 31 | /** 32 | * (Optional) The name of the index; defaults to a provider-generated name. 33 | */ 34 | String name() default ""; 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/Snowflake.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 15 | import static java.lang.annotation.ElementType.FIELD; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * Mark a Long type column value build by using SnowFlake algorithm from twitter 22 | *
32 | * Example: 33 | * 34 | * @UUIDAny(name="uuid_100", length=100) 35 | *36 | * 37 | * @since Java Persistence 1.0 38 | */ 39 | @Target({TYPE, FIELD}) 40 | @Retention(RUNTIME) 41 | public @interface UUIDAny { 42 | /** 43 | * (Required) A unique generator name that can be referenced by one or more 44 | * classes to be the generator for primary key values. 45 | */ 46 | String name(); 47 | 48 | /** 49 | * The length of the UUID 50 | */ 51 | int length() default 20; 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jdia/UpdateTimestamp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jdia; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * Mark a UpdateTimestamp column, explained by ORM tool 22 | * 23 | * @author Yong Zhu 24 | * @since 4.0.2 25 | */ 26 | @Target({ FIELD }) 27 | @Retention(RUNTIME) 28 | 29 | public @interface UpdateTimestamp { 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Column.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jpa; 13 | 14 | import java.lang.annotation.Target; 15 | import java.lang.annotation.Retention; 16 | import static java.lang.annotation.ElementType.METHOD; 17 | import static java.lang.annotation.ElementType.FIELD; 18 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 19 | 20 | /** 21 | * Specifies the mapped column for a persistent property or field. 22 | * If no
Column
annotation is specified, the default values apply.
23 | *
24 | * 44 | * 45 | * 46 | * @since Java Persistence 1.0 47 | */ 48 | @Target({METHOD, FIELD}) 49 | @Retention(RUNTIME) 50 | public @interface Column { 51 | 52 | /** 53 | * (Optional) The name of the column. Defaults to 54 | * the property or field name. 55 | */ 56 | String name() default ""; 57 | 58 | /** 59 | * (Optional) Whether the column is a unique key. This is a 60 | * shortcut for the25 | * Example 1: 26 | * 27 | * @Column(name="DESC", nullable=false, length=512) 28 | * public String getDescription() { return description; } 29 | * 30 | * Example 2: 31 | * 32 | * @Column(name="DESC", 33 | * columnDefinition="CLOB NOT NULL", 34 | * table="EMP_DETAIL") 35 | * @Lob 36 | * public String getDescription() { return description; } 37 | * 38 | * Example 3: 39 | * 40 | * @Column(name="ORDER_COST", updatable=false, precision=12, scale=2) 41 | * public BigDecimal getCost() { return cost; } 42 | * 43 | *
UniqueConstraint
annotation at the table
61 | * level and is useful for when the unique key constraint
62 | * corresponds to only a single column. This constraint applies
63 | * in addition to any constraint entailed by primary key mapping and
64 | * to constraints specified at the table level.
65 | */
66 | boolean unique() default false;
67 |
68 | /**
69 | * (Optional) Whether the database column is nullable.
70 | */
71 | boolean nullable() default true;
72 |
73 | /**
74 | * (Optional) Whether the column is included in SQL INSERT
75 | * statements generated by the persistence provider.
76 | */
77 | boolean insertable() default true;
78 |
79 | /**
80 | * (Optional) Whether the column is included in SQL UPDATE
81 | * statements generated by the persistence provider.
82 | */
83 | boolean updatable() default true;
84 |
85 | /**
86 | * (Optional) The SQL fragment that is used when
87 | * generating the DDL for the column.
88 | * Defaults to the generated SQL to create a 89 | * column of the inferred type. 90 | */ 91 | String columnDefinition() default ""; 92 | 93 | /** 94 | * (Optional) The name of the table that contains the column. 95 | * If absent the column is assumed to be in the primary table. 96 | */ 97 | String table() default ""; 98 | 99 | /** 100 | * (Optional) The column length. (Applies only if a 101 | * string-valued column is used.) 102 | */ 103 | int length() default 255; 104 | 105 | /** 106 | * (Optional) The precision for a decimal (exact numeric) 107 | * column. (Applies only if a decimal column is used.) 108 | * Value must be set by developer if used when generating 109 | * the DDL for the column. 110 | */ 111 | int precision() default 0; 112 | 113 | /** 114 | * (Optional) The scale for a decimal (exact numeric) column. 115 | * (Applies only if a decimal column is used.) 116 | */ 117 | int scale() default 0; 118 | } 119 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Convert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jpa; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The value of this Convert annotation point to a class, the implementation of 22 | * this class will used to convert field value to database column value, and 23 | * column value to database, for example: 24 | * 25 | *
26 | * @Convert(XxxDateConverter.class) 27 | * private Date date;// Tell ORM Tool use XxxDateConverter to do the convert 28 | * 29 | * @Convert(XxxEnumTranslator.class) 30 | * private Enum some1;// Tell ORM Tool use XxxEnumTranslator to do the convert 31 | * 32 | * @Convert() 33 | * private Enum some2; // Tell ORM Tool decide how to do the convert by ORM tool itself 34 | * 35 | *36 | */ 37 | @Target(FIELD) 38 | @Retention(RUNTIME) 39 | public @interface Convert { 40 | Class> value() default void.class; 41 | 42 | /** 43 | * Specifies the converter to be applied. A value for this element must be 44 | * specified if multiple converters would otherwise apply. 45 | */ 46 | Class> converter() default void.class;// equal to value, for compatible to JPA only 47 | 48 | /** 49 | * The
attributeName
element must be specified unless the
50 | * Convert
annotation is on an attribute of basic type or on an
51 | * element collection of basic type. In these cases, the
52 | * attributeName
element must not be specified.
53 | */
54 | String attributeName() default ""; // ignored, for compatible to JPA only
55 |
56 | /**
57 | * Used to disable an auto-apply or inherited converter. If disableConversion is
58 | * true, the converter
element should not be specified.
59 | */
60 | boolean disableConversion() default false; // for compatible to JPA only
61 | }
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Entity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
7 | * applicable law or agreed to in writing, software distributed under the
8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9 | * OF ANY KIND, either express or implied. See the License for the specific
10 | * language governing permissions and limitations under the License.
11 | */
12 | package com.github.drinkjava2.jdialects.annotation.jpa;
13 |
14 | import java.lang.annotation.Target;
15 | import java.lang.annotation.Retention;
16 | import java.lang.annotation.Documented;
17 | import static java.lang.annotation.ElementType.TYPE;
18 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
19 |
20 | /**
21 | * Specifies that the class is an entity. This annotation is applied to the
22 | * entity class.
23 | *
24 | * @since Java Persistence 1.0
25 | */
26 | @Documented
27 | @Target(TYPE)
28 | @Retention(RUNTIME)
29 | public @interface Entity {
30 |
31 | /**
32 | * (Optional) The entity name. Defaults to the unqualified
33 | * name of the entity class. This name is used to refer to the
34 | * entity in queries. The name must not be a reserved literal
35 | * in the Java Persistence query language.
36 | */
37 | String name() default "";
38 | }
39 |
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/EnumType.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved.
3 | *
4 | * This program and the accompanying materials are made available under the
5 | * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
6 | * which accompanies this distribution.
7 | * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
8 | * and the Eclipse Distribution License is available at
9 | * http://www.eclipse.org/org/documents/edl-v10.php.
10 | *
11 | * Contributors:
12 | * Linda DeMichiel - Java Persistence 2.1
13 | * Linda DeMichiel - Java Persistence 2.0
14 | *
15 | ******************************************************************************/
16 | package com.github.drinkjava2.jdialects.annotation.jpa;
17 |
18 | /**
19 | * Defines mapping for enumerated types. The constants of this
20 | * enumerated type specify how a persistent property or
21 | * field of an enumerated type should be persisted.
22 | *
23 | * @since Java Persistence 1.0
24 | */
25 | public enum EnumType {
26 | /** Persist enumerated type property or field as an integer. */
27 | ORDINAL,
28 |
29 | /** Persist enumerated type property or field as a string. */
30 | STRING
31 | }
32 |
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Enumerated.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008 - 2014 Oracle Corporation. All rights reserved.
3 | *
4 | * This program and the accompanying materials are made available under the
5 | * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
6 | * which accompanies this distribution.
7 | * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
8 | * and the Eclipse Distribution License is available at
9 | * http://www.eclipse.org/org/documents/edl-v10.php.
10 | *
11 | * Contributors:
12 | * Linda DeMichiel - Java Persistence 2.1
13 | * Linda DeMichiel - Java Persistence 2.0
14 | *
15 | ******************************************************************************/
16 | package com.github.drinkjava2.jdialects.annotation.jpa;
17 |
18 | import static java.lang.annotation.ElementType.FIELD;
19 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
20 |
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * Specifies that a persistent property or field should be persisted as a
26 | * enumerated type. The Enumerated
annotation may be used in
27 | * conjunction with the Basic
annotation, or in conjunction with
28 | * the ElementCollection
annotation when the element collection
29 | * value is of basic type. If the enumerated type is not specified or the
30 | * Enumerated
annotation is not used, the EnumType
31 | * value is assumed to be ORDINAL
.
32 | *
33 | * 34 | * Example: 35 | * 36 | * public enum EmployeeStatus {FULL_TIME, PART_TIME, CONTRACT} 37 | * 38 | * public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE} 39 | * 40 | * @Entity public class Employee { 41 | * public EmployeeStatus getStatus() {...} 42 | * ... 43 | * @Enumerated(STRING) 44 | * public SalaryRate getPayScale() {...} 45 | * ... 46 | * } 47 | *48 | * 49 | * @see Basic 50 | * @see ElementCollection 51 | * 52 | * @since Java Persistence 1.0 53 | */ 54 | @Target({ FIELD }) 55 | @Retention(RUNTIME) 56 | public @interface Enumerated { 57 | 58 | /** (Optional) The type used in mapping an enum type. */ 59 | EnumType value() default EnumType.ORDINAL; 60 | } 61 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/GeneratedValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jpa; 13 | 14 | import static com.github.drinkjava2.jdialects.annotation.jpa.GenerationType.AUTO; 15 | import static java.lang.annotation.ElementType.FIELD; 16 | import static java.lang.annotation.ElementType.METHOD; 17 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 18 | 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | /** 23 | * Provides for the specification of generation strategies for the 24 | * values of primary keys. 25 | * 26 | *
The GeneratedValue
annotation
27 | * may be applied to a primary key property or field of an entity or
28 | * mapped superclass in conjunction with the {@link Id} annotation.
29 | * The use of the GeneratedValue
annotation is only
30 | * required to be supported for simple primary keys. Use of the
31 | * GeneratedValue
annotation is not supported for derived
32 | * primary keys.
33 | *
34 | *
35 | * 36 | * Example 1: 37 | * 38 | * @Id 39 | * @GeneratedValue(strategy=SEQUENCE, generator="CUST_SEQ") 40 | * @Column(name="CUST_ID") 41 | * public Long getId() { return id; } 42 | * 43 | * Example 2: 44 | * 45 | * @Id 46 | * @GeneratedValue(strategy=TABLE, generator="CUST_GEN") 47 | * @Column(name="CUST_ID") 48 | * Long id; 49 | *50 | * 51 | * @see Id 52 | * @see TableGenerator 53 | * @see SequenceGenerator 54 | * 55 | * @since Java Persistence 1.0 56 | */ 57 | @Target({METHOD, FIELD}) 58 | @Retention(RUNTIME) 59 | 60 | public @interface GeneratedValue { 61 | 62 | /** 63 | * (Optional) The primary key generation strategy 64 | * that the persistence provider must use to 65 | * generate the annotated entity primary key. 66 | */ 67 | GenerationType strategy() default AUTO; 68 | 69 | /** 70 | * (Optional) The name of the primary key generator 71 | * to use as specified in the {@link SequenceGenerator} 72 | * or {@link TableGenerator} annotation. 73 | *
Defaults to the id generator supplied by persistence provider.
74 | */
75 | String generator() default "";
76 | }
77 |
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/GenerationType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
7 | * applicable law or agreed to in writing, software distributed under the
8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9 | * OF ANY KIND, either express or implied. See the License for the specific
10 | * language governing permissions and limitations under the License.
11 | */
12 | package com.github.drinkjava2.jdialects.annotation.jpa;
13 |
14 | /**
15 | * Defines the types of primary key generation strategies.
16 | *
17 | * @see GeneratedValue
18 | *
19 | * @since Java Persistence 1.0
20 | */
21 | public enum GenerationType {
22 |
23 | /**
24 | * Indicates that the persistence provider must assign primary keys for the
25 | * entity using an underlying database table to ensure uniqueness.
26 | */
27 | TABLE,
28 |
29 | /**
30 | * Indicates that the persistence provider must assign primary keys for the
31 | * entity using a database sequence.
32 | */
33 | SEQUENCE,
34 |
35 | /**
36 | * Indicates that the persistence provider must assign primary keys for the
37 | * entity using a database identity column.
38 | */
39 | IDENTITY,
40 |
41 | /**
42 | * Indicates that the persistence provider should pick an appropriate
43 | * strategy for the particular database. The AUTO
generation
44 | * strategy may expect a database resource to exist, or it may attempt to
45 | * create one. A vendor may provide documentation on how to create such
46 | * resources in the event that it does not support schema generation or
47 | * cannot create the schema resource at runtime.
48 | */
49 | AUTO,
50 |
51 | /** A 32 character length UUID */
52 | UUID,
53 |
54 | /** A 25 character length UUID */
55 | UUID25,
56 |
57 | /** A 26 character length UUID */
58 | UUID26,
59 |
60 | /** A 32 character length UUID */
61 | UUID32,
62 |
63 | /** A 36 character length UUID */
64 | UUID36,
65 |
66 | /** A Any length UUID */
67 | UUID_ANY,
68 |
69 | /** A sorted UUID */
70 | SORTED_UUID,
71 |
72 | /** A TimeStamp */
73 | TIMESTAMP,
74 |
75 | /** A Snowflake ID */
76 | SNOWFLAKE,
77 |
78 | /** Unknow or Customized IdGenerators */
79 | OTHER
80 | }
81 |
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Id.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
7 | * applicable law or agreed to in writing, software distributed under the
8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9 | * OF ANY KIND, either express or implied. See the License for the specific
10 | * language governing permissions and limitations under the License.
11 | */
12 | package com.github.drinkjava2.jdialects.annotation.jpa;
13 |
14 | import java.lang.annotation.Target;
15 | import java.lang.annotation.Retention;
16 | import static java.lang.annotation.ElementType.FIELD;
17 | import static java.lang.annotation.ElementType.METHOD;
18 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
19 |
20 | /**
21 | * Specifies the primary key of an entity.
22 | * The field or property to which the Id
annotation is applied
23 | * should be one of the following types: any Java primitive type;
24 | * any primitive wrapper type;
25 | * String
;
26 | * java.util.Date
;
27 | * java.sql.Date
;
28 | * java.math.BigDecimal
;
29 | * java.math.BigInteger
.
30 | *
31 | *
The mapped column for the primary key of the entity is assumed
32 | * to be the primary key of the primary table. If no Column
annotation
33 | * is specified, the primary key column name is assumed to be the name
34 | * of the primary key property or field.
35 | *
36 | *
37 | * Example: 38 | * 39 | * @Id 40 | * public Long getId() { return id; } 41 | *42 | * 43 | * @see Column 44 | * @see GeneratedValue 45 | * 46 | * @since Java Persistence 1.0 47 | */ 48 | @Target({METHOD, FIELD}) 49 | @Retention(RUNTIME) 50 | 51 | public @interface Id {} 52 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Index.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jpa; 13 | 14 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 15 | import java.lang.annotation.Retention; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * Used in schema generation to specify creation of an index. 20 | *
21 | * Note that it is not necessary to specify an index for a primary key, 22 | * as the primary key index will be created automatically. 23 | * 24 | *
25 | * The syntax of the columnList
element is a
26 | * column_list
, as follows:
27 | *
28 | *
29 | * column::= index_column [,index_column]* 30 | * index_column::= column_name [ASC | DESC] 31 | *32 | * 33 | *
If ASC
or DESC
is not specified,
34 | * ASC
(ascending order) is assumed.
35 | *
36 | * @see Table
37 | * @see SecondaryTable
38 | * @see CollectionTable
39 | * @see JoinTable
40 | * @see TableIdGeneratorTest
41 | *
42 | * @since Java Persistence 2.1
43 | *
44 | */
45 | @Target({})
46 | @Retention(RUNTIME)
47 | public @interface Index {
48 |
49 | /**
50 | * (Optional) The name of the index; defaults to a provider-generated name.
51 | */
52 | String name() default "";
53 |
54 | /**
55 | * (Required) The names of the columns to be included in the index,
56 | * in order.
57 | */
58 | String columnList();
59 |
60 | /**
61 | * (Optional) Whether the index is unique.
62 | */
63 | boolean unique() default false;
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/SequenceGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
7 | * applicable law or agreed to in writing, software distributed under the
8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9 | * OF ANY KIND, either express or implied. See the License for the specific
10 | * language governing permissions and limitations under the License.
11 | */
12 | package com.github.drinkjava2.jdialects.annotation.jpa;
13 |
14 | import static java.lang.annotation.ElementType.FIELD;
15 | import static java.lang.annotation.ElementType.TYPE;
16 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
17 |
18 | import java.lang.annotation.Retention;
19 | import java.lang.annotation.Target;
20 |
21 | /**
22 | * Defines a primary key generator that may be referenced by name when
23 | * a generator element is specified for the {@link GeneratedValue}
24 | * annotation. A sequence generator may be specified on the entity
25 | * class or on the primary key field or property. The scope of the
26 | * generator name is global to the persistence unit (across all
27 | * generator types).
28 | *
29 | *
30 | * Example: 31 | * 32 | * @SequenceGenerator(name="EMP_SEQ", allocationSize=25) 33 | *34 | * 35 | * @since Java Persistence 1.0 36 | */ 37 | @Target({TYPE, FIELD}) 38 | @Retention(RUNTIME) 39 | public @interface SequenceGenerator { 40 | 41 | /** 42 | * (Required) A unique generator name that can be referenced 43 | * by one or more classes to be the generator for primary key 44 | * values. 45 | */ 46 | String name(); 47 | 48 | /** 49 | * (Optional) The name of the database sequence object from 50 | * which to obtain primary key values. 51 | *
Defaults to a provider-chosen value. 52 | */ 53 | String sequenceName() default ""; 54 | 55 | /** (Optional) The catalog of the sequence generator. 56 | * 57 | * @since Java Persistence 2.0 58 | */ 59 | String catalog() default ""; 60 | 61 | /** (Optional) The schema of the sequence generator. 62 | * 63 | * @since Java Persistence 2.0 64 | */ 65 | String schema() default ""; 66 | 67 | /** 68 | * (Optional) The value from which the sequence object 69 | * is to start generating. 70 | */ 71 | int initialValue() default 1; 72 | 73 | /** 74 | * (Optional) The amount to increment by when allocating 75 | * sequence numbers from the sequence. 76 | */ 77 | int allocationSize() default 50; 78 | } 79 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Table.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jpa; 13 | 14 | import static java.lang.annotation.ElementType.TYPE; 15 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 16 | 17 | import java.lang.annotation.Inherited; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * Specifies the primary table for the annotated entity. Additional 23 | * tables may be specified using {@link SecondaryTable} or {@link 24 | * SecondaryTables} annotation. 25 | * 26 | *
If no Table
annotation is specified for an entity
27 | * class, the default values apply.
28 | *
29 | *
30 | * Example: 31 | * 32 | * @Entity 33 | * @Table(name="CUST", schema="RECORDS") 34 | * public class Customer { ... } 35 | *36 | * 37 | * @since Java Persistence 1.0 38 | */ 39 | @Inherited 40 | @Target(TYPE) 41 | @Retention(RUNTIME) 42 | public @interface Table { 43 | 44 | /** 45 | * (Optional) The name of the table. 46 | *
Defaults to the entity name. 47 | */ 48 | String name() default ""; 49 | 50 | /** (Optional) The catalog of the table. 51 | *
Defaults to the default catalog. 52 | */ 53 | String catalog() default ""; 54 | 55 | /** (Optional) The schema of the table. 56 | *
Defaults to the default schema for user.
57 | */
58 | String schema() default "";
59 |
60 | /**
61 | * (Optional) Unique constraints that are to be placed on
62 | * the table. These are only used if table generation is in
63 | * effect. These constraints apply in addition to any constraints
64 | * specified by the Column
and JoinColumn
65 | * annotations and constraints entailed by primary key mappings.
66 | *
Defaults to no additional constraints. 67 | */ 68 | UniqueConstraint[] uniqueConstraints() default {}; 69 | 70 | /** 71 | * (Optional) Indexes for the table. These are only used if 72 | * table generation is in effect. Note that it is not necessary 73 | * to specify an index for a primary key, as the primary key 74 | * index will be created automatically. 75 | * 76 | * @since Java Persistence 2.1 77 | */ 78 | Index[] indexes() default {}; 79 | } 80 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/TableGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jpa; 13 | 14 | import static java.lang.annotation.ElementType.FIELD; 15 | import static java.lang.annotation.ElementType.TYPE; 16 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 17 | 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * Defines a primary key generator that may be 23 | * referenced by name when a generator element is specified for 24 | * the {@link GeneratedValue} annotation. A table generator 25 | * may be specified on the entity class or on the primary key 26 | * field or property. The scope of the generator name is global 27 | * to the persistence unit (across all generator types). 28 | * 29 | *
30 | * Example 1: 31 | * 32 | * @Entity public class Employee { 33 | * ... 34 | * @TableGenerator( 35 | * name="empGen", 36 | * table="ID_GEN", 37 | * pkColumnName="GEN_KEY", 38 | * valueColumnName="GEN_VALUE", 39 | * pkColumnValue="EMP_ID", 40 | * allocationSize=1) 41 | * @Id 42 | * @GeneratedValue(strategy=TABLE, generator="empGen") 43 | * int id; 44 | * ... 45 | * } 46 | * 47 | * Example 2: 48 | * 49 | * @Entity public class Address { 50 | * ... 51 | * @TableGenerator( 52 | * name="addressGen", 53 | * table="ID_GEN", 54 | * pkColumnName="GEN_KEY", 55 | * valueColumnName="GEN_VALUE", 56 | * pkColumnValue="ADDR_ID") 57 | * @Id 58 | * @GeneratedValue(strategy=TABLE, generator="addressGen") 59 | * int id; 60 | * ... 61 | * } 62 | *63 | * 64 | * @see GeneratedValue 65 | * 66 | * @since Java Persistence 1.0 67 | */ 68 | @Target({TYPE, FIELD}) 69 | @Retention(RUNTIME) 70 | public @interface TableGenerator { 71 | 72 | /** 73 | * (Required) A unique generator name that can be referenced 74 | * by one or more classes to be the generator for id values. 75 | */ 76 | String name(); 77 | 78 | /** 79 | * (Optional) Name of table that stores the generated id values. 80 | *
Defaults to a name chosen by persistence provider. 81 | */ 82 | String table() default ""; 83 | 84 | /** (Optional) The catalog of the table. 85 | *
Defaults to the default catalog. 86 | */ 87 | String catalog() default ""; 88 | 89 | /** (Optional) The schema of the table. 90 | *
Defaults to the default schema for user. 91 | */ 92 | String schema() default ""; 93 | 94 | /** 95 | * (Optional) Name of the primary key column in the table. 96 | *
Defaults to a provider-chosen name. 97 | */ 98 | String pkColumnName() default ""; 99 | 100 | /** 101 | * (Optional) Name of the column that stores the last value generated. 102 | *
Defaults to a provider-chosen name. 103 | */ 104 | String valueColumnName() default ""; 105 | 106 | /** 107 | * (Optional) The primary key value in the generator table 108 | * that distinguishes this set of generated values from others 109 | * that may be stored in the table. 110 | *
Defaults to a provider-chosen value to store in the 111 | * primary key column of the generator table 112 | */ 113 | String pkColumnValue() default ""; 114 | 115 | /** 116 | * (Optional) The initial value to be used to initialize the column 117 | * that stores the last value generated. 118 | */ 119 | int initialValue() default 0; 120 | 121 | /** 122 | * (Optional) The amount to increment by when allocating id 123 | * numbers from the generator. 124 | */ 125 | int allocationSize() default 50; 126 | 127 | /** 128 | * (Optional) Unique constraints that are to be placed on the 129 | * table. These are only used if table generation is in effect. 130 | * These constraints apply in addition to primary key constraints. 131 | *
Defaults to no additional constraints.
132 | */
133 | UniqueConstraint[] uniqueConstraints() default {};
134 |
135 | /**
136 | * (Optional) Indexes for the table. These are only used if
137 | * table generation is in effect. Note that it is not necessary
138 | * to specify an index for a primary key, as the primary key
139 | * index will be created automatically.
140 | *
141 | * @since Java Persistence 2.1
142 | */
143 | Index[] indexes() default {};
144 | }
145 |
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Temporal.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved.
3 | *
4 | * This program and the accompanying materials are made available under the
5 | * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
6 | * which accompanies this distribution.
7 | * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
8 | * and the Eclipse Distribution License is available at
9 | * http://www.eclipse.org/org/documents/edl-v10.php.
10 | *
11 | * Contributors:
12 | * Linda DeMichiel - Java Persistence 2.1
13 | * Linda DeMichiel - Java Persistence 2.0
14 | *
15 | ******************************************************************************/
16 | package com.github.drinkjava2.jdialects.annotation.jpa;
17 |
18 | import java.lang.annotation.Target;
19 | import java.lang.annotation.Retention;
20 | import static java.lang.annotation.ElementType.FIELD;
21 | import static java.lang.annotation.ElementType.METHOD;
22 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
23 |
24 | /**
25 | * This annotation must be specified for persistent fields
26 | * or properties of type java.util.Date
and
27 | * java.util.Calendar
. It may only be specified for fields
28 | * or properties of these types.
29 | *
30 | *
The Temporal
annotation may be used in
31 | * conjunction with the {@link Basic} annotation, the {@link Id}
32 | * annotation, or the {@link ElementCollection} annotation (when
33 | * the element collection value is of such a temporal type.
34 | *
35 | *
36 | * Example: 37 | * 38 | * @Temporal(DATE) 39 | * protected java.util.Date endDate; 40 | *41 | * 42 | * @since Java Persistence 1.0 43 | */ 44 | @Target({METHOD, FIELD}) 45 | @Retention(RUNTIME) 46 | public @interface Temporal { 47 | 48 | /** The type used in mapping
java.util.Date
or java.util.Calendar
. */
49 | TemporalType value();
50 | }
51 |
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/TemporalType.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved.
3 | *
4 | * This program and the accompanying materials are made available under the
5 | * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
6 | * which accompanies this distribution.
7 | * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
8 | * and the Eclipse Distribution License is available at
9 | * http://www.eclipse.org/org/documents/edl-v10.php.
10 | *
11 | * Contributors:
12 | * Linda DeMichiel - Java Persistence 2.1
13 | * Linda DeMichiel - Java Persistence 2.0
14 | *
15 | ******************************************************************************/
16 | package com.github.drinkjava2.jdialects.annotation.jpa;
17 |
18 | /**
19 | * Type used to indicate a specific mapping of java.util.Date
20 | * or java.util.Calendar
.
21 | *
22 | * @since Java Persistence 1.0
23 | */
24 | public enum TemporalType {
25 |
26 | /** Map as java.sql.Date
*/
27 | DATE,
28 |
29 | /** Map as java.sql.Time
*/
30 | TIME,
31 |
32 | /** Map as java.sql.Timestamp
*/
33 | TIMESTAMP
34 | }
35 |
--------------------------------------------------------------------------------
/core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Transient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 | * use this file except in compliance with the License. You may obtain a copy of
6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
7 | * applicable law or agreed to in writing, software distributed under the
8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9 | * OF ANY KIND, either express or implied. See the License for the specific
10 | * language governing permissions and limitations under the License.
11 | */
12 | package com.github.drinkjava2.jdialects.annotation.jpa;
13 |
14 | import java.lang.annotation.Target;
15 | import java.lang.annotation.Retention;
16 | import static java.lang.annotation.ElementType.METHOD;
17 | import static java.lang.annotation.ElementType.FIELD;
18 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
19 |
20 | /**
21 | * Specifies that the property or field is not persistent. It is used
22 | * to annotate a property or field of an entity class, mapped
23 | * superclass, or embeddable class.
24 | *
25 | * 26 | * Example: 27 | * 28 | * @Entity 29 | * public class Employee { 30 | * @Id int id; 31 | * @Transient User currentUser; 32 | * ... 33 | * } 34 | *35 | * 36 | * @since Java Persistence 1.0 37 | */ 38 | @Target({METHOD, FIELD}) 39 | @Retention(RUNTIME) 40 | 41 | public @interface Transient {} 42 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/UniqueConstraint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jpa; 13 | 14 | import java.lang.annotation.Target; 15 | import java.lang.annotation.Retention; 16 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 17 | 18 | /** 19 | * Specifies that a unique constraint is to be included in 20 | * the generated DDL for a primary or secondary table. 21 | * 22 | *
23 | * Example: 24 | * @Entity 25 | * @Table( 26 | * name="EMPLOYEE", 27 | * uniqueConstraints= 28 | * @UniqueConstraint(columnNames={"EMP_ID", "EMP_NAME"}) 29 | * ) 30 | * public class Employee { ... } 31 | *32 | * 33 | * @since Java Persistence 1.0 34 | */ 35 | @Target({}) 36 | @Retention(RUNTIME) 37 | public @interface UniqueConstraint { 38 | 39 | /** (Optional) Constraint name. A provider-chosen name will be chosen 40 | * if a name is not specified. 41 | * 42 | * @since Java Persistence 2.0 43 | */ 44 | String name() default ""; 45 | 46 | /** (Required) An array of the column names that make up the constraint. */ 47 | String[] columnNames(); 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/annotation/jpa/Version.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.annotation.jpa; 13 | 14 | import java.lang.annotation.Target; 15 | import java.lang.annotation.Retention; 16 | import static java.lang.annotation.ElementType.METHOD; 17 | import static java.lang.annotation.ElementType.FIELD; 18 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 19 | 20 | /** 21 | * Specifies the version field or property of an entity class that serves as its 22 | * optimistic lock value. The version is used to ensure integrity when 23 | * performing the merge operation and for optimistic concurrency control. 24 | * 25 | *
26 | * Only a single Version
property or field should be used per
27 | * class; applications that use more than one Version
property or
28 | * field will not be portable.
29 | *
30 | *
31 | * The Version
property should be mapped to the primary table for
32 | * the entity class; applications that map the Version
property to
33 | * a table other than the primary table will not be portable.
34 | *
35 | *
36 | * The following types are supported for version properties: int
,
37 | * Integer
, short
, Short
,
38 | * long
, Long
39 | *
40 | *
41 | * Example: 42 | * 43 | * @Version 44 | * @Column(name="OPTLOCK") 45 | * protected int getVersionNum() { return versionNum; } 46 | *47 | * 48 | */ 49 | @Target({ METHOD, FIELD }) 50 | @Retention(RUNTIME) 51 | public @interface Version { 52 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/converter/BasicJavaToJdbcConverter.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jdialects.converter; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Calendar; 5 | import java.util.Date; 6 | 7 | import com.github.drinkjava2.jdialects.Java8DateUtils; 8 | 9 | public class BasicJavaToJdbcConverter implements JavaToJdbcConverter { 10 | public static final BasicJavaToJdbcConverter instance = new BasicJavaToJdbcConverter(); 11 | 12 | @Override 13 | public Object convert(Object value) { 14 | if (value == null) 15 | return value; 16 | Class> vType = value.getClass(); 17 | if (java.util.Date.class == vType) 18 | return new java.sql.Date(((Date) value).getTime()); 19 | if (Character.class == vType) 20 | return ((Character) value).toString(); 21 | if (BigInteger.class == vType) 22 | return ((BigInteger) value).longValue(); // 2020.10.1 change from int to long 23 | if (Boolean.class == vType) 24 | return ((Boolean) value).booleanValue(); 25 | else if (Calendar.class.isAssignableFrom(vType)) 26 | return new java.sql.Date(((Calendar) value).getTime().getTime()); 27 | /*- JAVA8_BEGIN */ 28 | else if (java.time.temporal.Temporal.class.isAssignableFrom(vType)) { 29 | if (java.time.LocalDate.class == vType) 30 | return Java8DateUtils.localDate2SqlDate((java.time.LocalDate) value); 31 | else if (java.time.LocalTime.class == vType) 32 | return Java8DateUtils.localTime2SqlTime((java.time.LocalTime) value); 33 | else if (java.time.OffsetTime.class == vType) 34 | return Java8DateUtils.offsetTime2SqlTime((java.time.OffsetTime) value); 35 | else if (java.time.Instant.class == vType) 36 | return Java8DateUtils.instant2SqlTimestamp((java.time.Instant) value); 37 | else if (java.time.LocalDateTime.class == vType) 38 | return Java8DateUtils.localDateTime2SqlTimestamp((java.time.LocalDateTime) value); 39 | else if (java.time.OffsetDateTime.class == vType) 40 | return Java8DateUtils.offsetDateTime2SqlTimestamp((java.time.OffsetDateTime) value); 41 | else if (java.time.ZonedDateTime.class == vType) 42 | return Java8DateUtils.zonedDateTime2SqlTimestamp((java.time.ZonedDateTime) value); 43 | } 44 | /* JAVA8_END */ 45 | return value; 46 | } 47 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/converter/BasicJdbcToJavaConverter.java: -------------------------------------------------------------------------------- 1 | package com.github.drinkjava2.jdialects.converter; 2 | 3 | public class BasicJdbcToJavaConverter implements JdbcToJavaConverter { 4 | public static final BasicJdbcToJavaConverter instance = new BasicJdbcToJavaConverter(); 5 | 6 | @Override 7 | public Object convert(Object value) { 8 | return value; 9 | } 10 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/converter/JavaConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package com.github.drinkjava2.jdialects.converter; 17 | 18 | /** 19 | * JdbcTypeConverter, used to conver jdbc value to java, or java value to jdbc 20 | * parameter for SQL 21 | * 22 | * @author yongz 23 | * @since 5.0.0 24 | * 25 | */ 26 | public interface JavaConverter { 27 | 28 | /** 29 | * Convert java value to targetType java value 30 | * @param value 31 | * @param targetType 32 | * @return new value 33 | */ 34 | public Object convert(Object value, Class> targetType); 35 | 36 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/converter/JavaToJdbcConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package com.github.drinkjava2.jdialects.converter; 17 | 18 | /** 19 | * JavaToJdbcConverter used to convert Java value to JDBC value 20 | * 21 | * @author yongz 22 | * @since 5.0.0 23 | * 24 | */ 25 | public interface JavaToJdbcConverter { 26 | 27 | /** Convert Java value to JDBC value */ 28 | public Object convert(Object value); 29 | 30 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/converter/JdbcToJavaConverter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package com.github.drinkjava2.jdialects.converter; 17 | 18 | /** 19 | * JdbcToJavaConverter used to convert jdbc value to java value 20 | * 21 | * @author yongz 22 | * @since 5.0.0 23 | * 24 | */ 25 | public interface JdbcToJavaConverter { 26 | 27 | /** Convert jdbc value to java value */ 28 | public Object convert(Object value); 29 | 30 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/id/AutoIdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.id; 13 | 14 | import java.sql.Connection; 15 | 16 | import com.github.drinkjava2.jdialects.Dialect; 17 | import com.github.drinkjava2.jdialects.Type; 18 | import com.github.drinkjava2.jdialects.annotation.jpa.GenerationType; 19 | 20 | /** 21 | * AutoGenerator will depends database's id generator mechanism like MySql's 22 | * Identity, Oracle's Sequence... 23 | * 24 | * @author Yong Zhu 25 | * @version 1.0.0 26 | * @since 1.0.0 27 | */ 28 | public class AutoIdGenerator implements IdGenerator { 29 | private static final String JDIALECTS_AUTOID_NAME = "jdia_autoid"; 30 | private static final String JDIALECTS_AUTOID_TABLE = "jdia_table_autoid"; 31 | private static final String JDIALECTS_AUTOID_SEQUENCE = "jdia_seq_autoid"; 32 | 33 | public static final AutoIdGenerator INSTANCE = new AutoIdGenerator(); 34 | 35 | public static final TableIdGenerator TABLE_AUTOID_INSTANCE = new TableIdGenerator(JDIALECTS_AUTOID_NAME, 36 | JDIALECTS_AUTOID_TABLE, "idcolumn", "valuecolumn", "next_val", 1, 50); 37 | 38 | public static final SequenceIdGenerator SEQ_AUTOID_INSTANCE = new SequenceIdGenerator(JDIALECTS_AUTOID_NAME, 39 | JDIALECTS_AUTOID_SEQUENCE, 1, 1); 40 | 41 | @Override 42 | public GenerationType getGenerationType() { 43 | return GenerationType.AUTO; 44 | } 45 | 46 | @Override 47 | public String getIdGenName() { 48 | return JDIALECTS_AUTOID_NAME; 49 | } 50 | 51 | @Override 52 | public IdGenerator newCopy() { 53 | return INSTANCE; 54 | } 55 | 56 | @Override 57 | public Boolean dependOnAutoIdGenerator() { 58 | return true; 59 | } 60 | 61 | @Override 62 | public Object getNextID(Connection con, Dialect dialect, Type dataType) { 63 | if (dialect.ddlFeatures.supportBasicOrPooledSequence()) 64 | return SEQ_AUTOID_INSTANCE.getNextID(con, dialect, dataType); 65 | else 66 | return TABLE_AUTOID_INSTANCE.getNextID(con, dialect, dataType); 67 | } 68 | 69 | /** 70 | * If dialect support sequence, return a SequenceIdGenerator, otherwise return a 71 | * TableIdGenerator 72 | */ 73 | public IdGenerator getSequenceOrTableIdGenerator(Dialect dialect) { 74 | if (dialect.ddlFeatures.supportBasicOrPooledSequence()) 75 | return SEQ_AUTOID_INSTANCE; 76 | else 77 | return TABLE_AUTOID_INSTANCE; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/id/IdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.id; 13 | 14 | import java.sql.Connection; 15 | 16 | import com.github.drinkjava2.jdialects.Dialect; 17 | import com.github.drinkjava2.jdialects.Type; 18 | import com.github.drinkjava2.jdialects.annotation.jpa.GenerationType; 19 | 20 | /** 21 | * Interface for all ID generators 22 | * 23 | * @author Yong Zhu 24 | * @version 1.0.0 25 | * @since 1.0 26 | */ 27 | 28 | public interface IdGenerator {// NOSONAR 29 | /** 30 | * Get the next ID generated by implementation of IdGenerator 31 | * 32 | * @param Connection 33 | * Connection which used get next ID, note this connection will not be closed in method call 34 | * @param dialect 35 | * The Dialect 36 | * @param dataType 37 | * The {@link Type} of a column 38 | * @return id generated by IdGenerator 39 | */ 40 | public Object getNextID(Connection con, Dialect dialect, Type dataType); 41 | 42 | /** Return GenerationType */ 43 | public GenerationType getGenerationType(); 44 | 45 | /** Return a unique Id Generator name in this TableModel */ 46 | public String getIdGenName(); 47 | 48 | /** Return a newCopy (Deep Clone) instance */ 49 | public IdGenerator newCopy(); 50 | 51 | /** 52 | * If depends on AutoIdGenerator, for example SortedUUIDGenerator depends on 53 | * AutoIdGenerator to create start numbers 54 | */ 55 | public Boolean dependOnAutoIdGenerator(); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/id/IdentityIdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.id; 13 | 14 | import java.sql.Connection; 15 | 16 | import com.github.drinkjava2.jdialects.DDLFeatures; 17 | import com.github.drinkjava2.jdialects.Dialect; 18 | import com.github.drinkjava2.jdialects.DialectException; 19 | import com.github.drinkjava2.jdialects.JdbcUtil; 20 | import com.github.drinkjava2.jdialects.StrUtils; 21 | import com.github.drinkjava2.jdialects.Type; 22 | import com.github.drinkjava2.jdialects.annotation.jpa.GenerationType; 23 | 24 | /** 25 | * Define an Identity type generator, supported by MySQL, SQL Server, DB2, 26 | * Derby, Sybase, PostgreSQL 27 | * 28 | * 29 | * @author Yong Zhu 30 | * @version 1.0.0 31 | * @since 1.0.0 32 | */ 33 | public class IdentityIdGenerator implements IdGenerator { 34 | private String table; 35 | 36 | private String column; 37 | 38 | public IdentityIdGenerator(String table, String column) { 39 | this.table = table; 40 | this.column = column; 41 | } 42 | 43 | @Override 44 | public GenerationType getGenerationType() { 45 | return GenerationType.IDENTITY; 46 | } 47 | 48 | @Override 49 | public String getIdGenName() { 50 | return "IDENTITY"; 51 | } 52 | 53 | @Override 54 | public Boolean dependOnAutoIdGenerator() { 55 | return false; 56 | } 57 | 58 | @Override 59 | public Object getNextID(Connection con, Dialect dialect, Type dataType) { 60 | if (!Boolean.TRUE.equals(dialect.ddlFeatures.getSupportsIdentityColumns())) 61 | throw new DialectException("Dialect '" + dialect + "' does not support identity type"); 62 | String sql = null; 63 | if (Type.BIGINT.equals(dataType)) 64 | sql = dialect.ddlFeatures.getIdentitySelectStringBigINT(); 65 | else 66 | sql = dialect.ddlFeatures.getIdentitySelectString(); 67 | if (StrUtils.isEmpty(sql) || DDLFeatures.NOT_SUPPORT.equals(sql)) 68 | throw new DialectException("Dialect '" + dialect + "' does not support identity type"); 69 | sql=StrUtils.replaceFirst(sql, "_table__col", new StringBuilder(table).append("_").append(column).toString()); 70 | return JdbcUtil.qryOneObject(con, sql); 71 | } 72 | 73 | @Override 74 | public IdGenerator newCopy() { 75 | return new IdentityIdGenerator(table, column); 76 | } 77 | 78 | // getter & setter============== 79 | public String getTable() { 80 | return table; 81 | } 82 | 83 | public void setTable(String table) { 84 | this.table = table; 85 | } 86 | 87 | public String getColumn() { 88 | return column; 89 | } 90 | 91 | public void setColumn(String column) { 92 | this.column = column; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/id/SequenceIdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.id; 13 | 14 | import java.sql.Connection; 15 | 16 | import com.github.drinkjava2.jdialects.Dialect; 17 | import com.github.drinkjava2.jdialects.DialectException; 18 | import com.github.drinkjava2.jdialects.JdbcUtil; 19 | import com.github.drinkjava2.jdialects.StrUtils; 20 | import com.github.drinkjava2.jdialects.Type; 21 | import com.github.drinkjava2.jdialects.annotation.jpa.GenerationType; 22 | 23 | /** 24 | * The platform-independent SequenceGen model, similar like JPA 25 | * 26 | * 27 | * 28 | * @author Yong Zhu 29 | * @since 1.0.0 30 | */ 31 | public class SequenceIdGenerator implements IdGenerator { 32 | 33 | /** 34 | * A unique generator name that can be referenced by one or more classes to 35 | * be the generator for primary key values. 36 | */ 37 | private String name; 38 | 39 | /** 40 | * The name of the sequence in database 41 | */ 42 | private String sequenceName; 43 | 44 | /** 45 | * The value from which the sequence is to start generating. 46 | */ 47 | private Integer initialValue = 0; 48 | 49 | /** 50 | * The amount to allocationSize by when allocating sequence numbers from the 51 | * sequence, in Oracle this is identical to "INCREMENT BY", for JPA and ORM 52 | * tools this usually value is 50 53 | */ 54 | private Integer allocationSize = 1; 55 | 56 | public SequenceIdGenerator() { 57 | // default constructor 58 | } 59 | 60 | public SequenceIdGenerator(String name, String sequenceName, Integer initialValue, Integer allocationSize) { 61 | this.name = name; 62 | this.sequenceName = sequenceName; 63 | this.initialValue = initialValue; 64 | this.allocationSize = allocationSize; 65 | } 66 | 67 | @Override 68 | public Object getNextID(Connection con, Dialect dialect, Type dataType) { 69 | DialectException.assureNotEmpty(sequenceName, "sequenceName can not be empty"); 70 | String sequenctSQL = dialect.ddlFeatures.getSequenceNextValString(); 71 | sequenctSQL = StrUtils.replace(sequenctSQL, "_SEQNAME", sequenceName); 72 | return JdbcUtil.qryOneObject(con, sequenctSQL); 73 | } 74 | 75 | @Override 76 | public GenerationType getGenerationType() { 77 | return GenerationType.SEQUENCE; 78 | } 79 | 80 | @Override 81 | public String getIdGenName() { 82 | return name; 83 | } 84 | 85 | @Override 86 | public IdGenerator newCopy() { 87 | return new SequenceIdGenerator(name,sequenceName,initialValue,allocationSize); 88 | } 89 | 90 | @Override 91 | public Boolean dependOnAutoIdGenerator() { 92 | return false; 93 | } 94 | 95 | // getter & setter============== 96 | public String getName() {//NOSONAR 97 | return name; 98 | } 99 | 100 | public void setName(String name) { 101 | this.name = name; 102 | } 103 | 104 | public String getSequenceName() { 105 | return sequenceName; 106 | } 107 | 108 | public void setSequenceName(String sequenceName) { 109 | this.sequenceName = sequenceName; 110 | } 111 | 112 | public Integer getInitialValue() { 113 | return initialValue; 114 | } 115 | 116 | public void setInitialValue(Integer initialValue) { 117 | this.initialValue = initialValue; 118 | } 119 | 120 | public Integer getAllocationSize() { 121 | return allocationSize; 122 | } 123 | 124 | public void setAllocationSize(Integer allocationSize) { 125 | this.allocationSize = allocationSize; 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/id/SnowflakeGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.id; 13 | 14 | import java.sql.Connection; 15 | 16 | import com.github.drinkjava2.jdialects.Dialect; 17 | import com.github.drinkjava2.jdialects.DialectException; 18 | import com.github.drinkjava2.jdialects.Type; 19 | import com.github.drinkjava2.jdialects.annotation.jpa.GenerationType; 20 | 21 | /** 22 | * SnowflakeGenerator is a special generator, only mark this column is a 23 | * snowflake type column, but getNextID() method does not work, because 24 | * snowflake value should generated by outside program, it depends on real 25 | * machine setting, in jDialects there is a SnowflakeCreator tool for these 26 | * outside program to use 27 | */ 28 | @SuppressWarnings("all") 29 | public class SnowflakeGenerator implements IdGenerator { 30 | public final static SnowflakeGenerator INSTANCE = new SnowflakeGenerator(); 31 | 32 | @Override 33 | public Object getNextID(Connection con, Dialect dialect, Type dataType) { 34 | throw new DialectException("Snowflake type column value should generated by outside program."); 35 | } 36 | 37 | @Override 38 | public GenerationType getGenerationType() { 39 | return GenerationType.SNOWFLAKE; 40 | } 41 | 42 | @Override 43 | public String getIdGenName() { 44 | return "SNOWFLAKE"; 45 | } 46 | 47 | @Override 48 | public IdGenerator newCopy() { 49 | return INSTANCE; 50 | } 51 | 52 | @Override 53 | public Boolean dependOnAutoIdGenerator() { 54 | return false; 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/id/SortedUUIDGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.id; 13 | 14 | import java.sql.Connection; 15 | 16 | import com.github.drinkjava2.jdialects.Dialect; 17 | import com.github.drinkjava2.jdialects.DialectException; 18 | import com.github.drinkjava2.jdialects.Type; 19 | import com.github.drinkjava2.jdialects.annotation.jpa.GenerationType; 20 | 21 | /** 22 | * Generate a Sorted UUID, total length = sortedLength + uuidLength,
24 | * Usage: 25 | * Table t=new Table('Customer'); 26 | * ... 27 | * t.fkey("column1").ref("refTable", "refColumn1") 28 | * 29 | * or compound foreign key: * 30 | * t.fkey("column1","column2").ref("refTable", "refColumn1", "refColumn2"); 31 | * 32 | *33 | * 34 | * @author Yong Zhu 35 | * @since 1.0.2 36 | */ 37 | public class FKeyModel { 38 | private String fkeyName; 39 | private String tableName; 40 | private List
20 | * Usage: 21 | * Table t=new Table('Customer'); 22 | * ... 23 | * t.index().forColumn("column1"); 24 | * or 25 | * t.index("indexName").forColumn("column1","column2"); 26 | * 27 | *28 | * 29 | * @author Yong Zhu 30 | * @since 1.0.5 31 | */ 32 | public class IndexModel { 33 | /** (Optional) The names of the index */ 34 | private String name; 35 | 36 | /** The names of the columns to be included in the index */ 37 | private String[] columnList; 38 | 39 | /** Whether the index is unique. */ 40 | private Boolean unique = false; 41 | 42 | private TableModel tableModel; // belong to which tableModel 43 | 44 | public IndexModel() { 45 | 46 | } 47 | 48 | public IndexModel(String name) { 49 | this.name = name; 50 | } 51 | 52 | public IndexModel newCopy() { 53 | IndexModel result = new IndexModel(); 54 | result.name = name; 55 | result.columnList = columnList; 56 | result.unique = unique; 57 | return result; 58 | } 59 | 60 | public IndexModel columns(String... columns) { 61 | checkReadOnly(); 62 | this.columnList = columns; 63 | return this; 64 | } 65 | 66 | public IndexModel unique() { 67 | checkReadOnly(); 68 | this.unique = true; 69 | return this; 70 | } 71 | 72 | public void checkReadOnly() { 73 | if (tableModel != null && tableModel.getReadOnly()) 74 | throw new DialectException( 75 | "TableModel '" + tableModel.getTableName() + "' is readOnly, can not be modified."); 76 | } 77 | 78 | // getter & setter ========= 79 | public String getName() { 80 | return name; 81 | } 82 | 83 | public void setName(String name) { 84 | checkReadOnly(); 85 | this.name = name; 86 | } 87 | 88 | public String[] getColumnList() { 89 | return columnList; 90 | } 91 | 92 | public void setColumnList(String[] columnList) { 93 | checkReadOnly(); 94 | this.columnList = columnList; 95 | } 96 | 97 | public Boolean getUnique() { 98 | return unique; 99 | } 100 | 101 | public void setUnique(Boolean unique) { 102 | checkReadOnly(); 103 | this.unique = unique; 104 | } 105 | 106 | public TableModel getTableModel() { 107 | return tableModel; 108 | } 109 | 110 | public void setTableModel(TableModel tableModel) { 111 | checkReadOnly(); 112 | this.tableModel = tableModel; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/model/UniqueModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by 7 | * applicable law or agreed to in writing, software distributed under the 8 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 9 | * OF ANY KIND, either express or implied. See the License for the specific 10 | * language governing permissions and limitations under the License. 11 | */ 12 | package com.github.drinkjava2.jdialects.model; 13 | 14 | import com.github.drinkjava2.jdialects.DialectException; 15 | 16 | /** 17 | * The platform-independent Unique Constraint model 18 | * 19 | *
20 | * Usage: 21 | * Table t=new Table('Customer'); 22 | * ... 23 | * t.index().forColumn("column1"); 24 | * or 25 | * t.index("indexName").forColumn("column1","column2"); 26 | * 27 | *28 | * 29 | * @author Yong Zhu 30 | * @since 1.0.5 31 | */ 32 | public class UniqueModel { 33 | private String name; 34 | private String[] columnList; 35 | private TableModel tableModel; // belong to which tableModel 36 | 37 | public UniqueModel() { 38 | 39 | } 40 | 41 | public UniqueModel(String name) { 42 | this.name = name; 43 | } 44 | 45 | public UniqueModel newCopy() { 46 | UniqueModel result = new UniqueModel(); 47 | result.name = name; 48 | result.columnList = columnList; 49 | return result; 50 | } 51 | 52 | public UniqueModel columns(String... columns) { 53 | checkReadOnly(); 54 | this.columnList = columns; 55 | return this; 56 | } 57 | 58 | public void checkReadOnly() { 59 | if (tableModel != null && tableModel.getReadOnly()) 60 | throw new DialectException( 61 | "TableModel '" + tableModel.getTableName() + "' is readOnly, can not be modified."); 62 | } 63 | 64 | // getter & setter ========= 65 | public String getName() { 66 | return name; 67 | } 68 | 69 | public void setName(String name) { 70 | checkReadOnly(); 71 | this.name = name; 72 | } 73 | 74 | public String[] getColumnList() { 75 | return columnList; 76 | } 77 | 78 | public void setColumnList(String[] columnList) { 79 | checkReadOnly(); 80 | this.columnList = columnList; 81 | } 82 | 83 | public TableModel getTableModel() { 84 | return tableModel; 85 | } 86 | 87 | public void setTableModel(TableModel tableModel) { 88 | checkReadOnly(); 89 | this.tableModel = tableModel; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jdialects/springsrc/PackageInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package com.github.drinkjava2.jdialects.springsrc; 18 | 19 | /** 20 | * All .java files in this folder are copied from Spring4.3.9.Release, no any 21 | * change except the package name 22 | * 23 | * @author Yong Zhu 24 | * @since 1.7.0 25 | */ 26 | public abstract class PackageInfo { 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jlogs/ConsoleLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package com.github.drinkjava2.jlogs; 17 | 18 | import java.io.PrintWriter; 19 | import java.io.StringWriter; 20 | 21 | /** 22 | * ConsoleLog only output to console 23 | * 24 | * @author Yong Zhu 25 | * @since 1.7.0 26 | */ 27 | @SuppressWarnings("all") 28 | public class ConsoleLog implements Log { 29 | 30 | public static final int OFF = 5; 31 | public static final int ERROR = 4; 32 | public static final int WARNING = 3; 33 | public static final int INFO = 2; 34 | public static final int DEBUG = 1; 35 | 36 | Class> clazz; 37 | private static int logLevel = INFO; 38 | private static boolean logHead = false; 39 | 40 | public ConsoleLog(Class> clazz) { 41 | this.clazz = clazz; 42 | } 43 | 44 | public static int getLogLevel() { 45 | return logLevel; 46 | } 47 | 48 | public static void setLogLevel(int logLevel) { 49 | ConsoleLog.logLevel = logLevel; 50 | } 51 | 52 | public static boolean isLogHead() { 53 | return logHead; 54 | } 55 | 56 | public static void setLogHead(boolean logHead) { 57 | ConsoleLog.logHead = logHead; 58 | } 59 | 60 | private String logheadStr(String method) { 61 | return logHead ? new StringBuilder(clazz.getSimpleName()).append(" ").append(method).append(": ").toString() 62 | : ""; 63 | } 64 | 65 | @Override 66 | public void info(String msg) { 67 | if (logLevel <= INFO) 68 | System.out.println(logheadStr("info") + msg); 69 | } 70 | 71 | @Override 72 | public void warn(String msg) { 73 | if (logLevel <= WARNING) 74 | System.out.println(logheadStr("warning") + msg); 75 | } 76 | 77 | @Override 78 | public void warn(String msg, Throwable t) { 79 | if (logLevel <= WARNING) 80 | System.out.println(logheadStr("warning") + msg + getStackTrace(t)); 81 | } 82 | 83 | @Override 84 | public void error(String msg) { 85 | if (logLevel <= ERROR) 86 | System.out.println(logheadStr("error") + msg); 87 | } 88 | 89 | @Override 90 | public void error(String msg, Throwable t) { 91 | if (logLevel <= WARNING) 92 | System.out.println(logheadStr("error") + msg + getStackTrace(t)); 93 | } 94 | 95 | @Override 96 | public void debug(String msg) { 97 | if (logLevel <= DEBUG) 98 | System.out.println(logheadStr("info") + msg); 99 | } 100 | 101 | public static String getStackTrace(Throwable t) { 102 | StringWriter sw = new StringWriter(); 103 | PrintWriter pw = new PrintWriter(sw); 104 | try { 105 | t.printStackTrace(pw); 106 | return sw.toString(); 107 | } finally { 108 | pw.close(); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jlogs/EmptyLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package com.github.drinkjava2.jlogs; 17 | 18 | /** 19 | * EmptyLog is an empty implementation of Log 20 | * 21 | * @author Yong Zhu 22 | * @since 1.7.0 23 | */ 24 | @SuppressWarnings("all") 25 | public class EmptyLog implements Log { 26 | 27 | public EmptyLog(Class> clazz) { 28 | } 29 | 30 | @Override 31 | public void info(String msg) { 32 | } 33 | 34 | @Override 35 | public void warn(String msg) { 36 | } 37 | 38 | @Override 39 | public void warn(String msg, Throwable t) { 40 | } 41 | 42 | @Override 43 | public void error(String msg) { 44 | 45 | } 46 | 47 | @Override 48 | public void error(String msg, Throwable t) { 49 | } 50 | 51 | @Override 52 | public void debug(String msg) { 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /core/src/main/java/com/github/drinkjava2/jlogs/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * 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, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | package com.github.drinkjava2.jlogs; 17 | 18 | /** 19 | * JLog used for inside of jSqlBox project, if a "jlogs.properties" file if 20 | * found on class root folder (main/resources), will try load the designated 21 | * JLog implementation, otherwise use default ConsoleLog as logger