Java Code Examples for org.mybatis.generator.api.IntrospectedTable#getFullyQualifiedTableNameAtRuntime()
The following examples show how to use
org.mybatis.generator.api.IntrospectedTable#getFullyQualifiedTableNameAtRuntime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyPgMapperPlugin.java From jvue-admin with MIT License | 6 votes |
/** * 处理实体类的包和@Table注解 * * @param topLevelClass * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); //如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } //是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (StringUtility.stringHasValue(schema) || StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if(forceAnnotation){ topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } }
Example 2
Source File: PostGreSQLReturnKeyPlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 6 votes |
/** * 返回主键方法 ==> 一般sql如下面 * <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer"> * SELECT currval('t_hui_order_id_seq') * </selectKey> * @param introspectedTable * @return */ private XmlElement addSelectKey(IntrospectedTable introspectedTable){ String resultType = introspectedTable.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType().getFullyQualifiedName(); String keyProperty = introspectedTable.getPrimaryKeyColumns().get(0).getActualColumnName(); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); String sql = "SELECT currval('" + tableName + "_id_seq')"; XmlElement selectKey = new XmlElement("selectKey"); TextElement selectKeySQL = new TextElement(sql); selectKey.addAttribute(new Attribute("keyProperty",keyProperty)); selectKey.addAttribute(new Attribute("order","AFTER")); selectKey.addAttribute(new Attribute("resultType", resultType)); selectKey.addElement(selectKeySQL); return selectKey; }
Example 3
Source File: MapperPlugin.java From tk-mybatis with MIT License | 6 votes |
/** * 处理实体类的包和@Table注解 * * @param topLevelClass * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); //如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } //是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (StringUtility.stringHasValue(schema) || StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } }
Example 4
Source File: CrudSupportPlugin.java From azeroth with Apache License 2.0 | 6 votes |
/** * 处理实体类的包和@Table注解 * * @param topLevelClass * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); //如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } //是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (StringUtility.stringHasValue(schema) || StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } }
Example 5
Source File: CrudSupportPlugin.java From jeesuite-libs with Apache License 2.0 | 6 votes |
/** * 处理实体类的包和@Table注解 * * @param topLevelClass * @param introspectedTable */ private void processEntityClass(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { //引入JPA注解 topLevelClass.addImportedType("javax.persistence.*"); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); //如果包含空格,或者需要分隔符,需要完善 if (StringUtility.stringContainsSpace(tableName)) { tableName = context.getBeginningDelimiter() + tableName + context.getEndingDelimiter(); } //是否忽略大小写,对于区分大小写的数据库,会有用 if (caseSensitive && !topLevelClass.getType().getShortName().equals(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (!topLevelClass.getType().getShortName().equalsIgnoreCase(tableName)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } else if (StringUtility.stringHasValue(schema) || StringUtility.stringHasValue(beginningDelimiter) || StringUtility.stringHasValue(endingDelimiter)) { topLevelClass.addAnnotation("@Table(name = \"" + getDelimiterName(tableName) + "\")"); } }
Example 6
Source File: GenPlugin.java From scaffold-cloud with MIT License | 5 votes |
@Override public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { // 数据库表名 String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); topLevelClass.addImportedType("lombok.Getter"); topLevelClass.addImportedType("lombok.Setter"); topLevelClass.addImportedType("lombok.ToString"); //添加domain的注解 topLevelClass.addAnnotation("@Getter"); topLevelClass.addAnnotation("@Setter"); topLevelClass.addAnnotation("@ToString"); if ("BaseEntity".equals(topLevelClass.getSuperClass().getShortName())) { topLevelClass.addImportedType("com.cms.scaffold.common.annotation.TableName"); //添加domain的注解 topLevelClass.addAnnotation("@TableName(name = \"" + tableName + "\")"); } //添加domain的注释 topLevelClass.addJavaDocLine("/**"); topLevelClass.addJavaDocLine("* " + introspectedTable.getRemarks()); topLevelClass.addJavaDocLine("* @author: Mybatis Generator"); topLevelClass.addJavaDocLine("* @date: " + DateUtil.now()); topLevelClass.addJavaDocLine("*/"); return true; }
Example 7
Source File: OracleReturnKeyPlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 5 votes |
/** * 返回主键方法 ==> 一般sql如下面 * <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer"> * SELECT currval('t_hui_order_id_seq') * </selectKey> * @param introspectedTable * @return */ private XmlElement addSelectKey(IntrospectedTable introspectedTable){ String resultType = introspectedTable.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType().getFullyQualifiedName(); String keyProperty = introspectedTable.getPrimaryKeyColumns().get(0).getActualColumnName(); String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); String sql = "SELECT " + tableName + "_SEQUENCE.nextval from dual')"; XmlElement selectKey = new XmlElement("selectKey"); TextElement selectKeySQL = new TextElement(sql); selectKey.addAttribute(new Attribute("keyProperty",keyProperty)); selectKey.addAttribute(new Attribute("order","BEFORE")); selectKey.addAttribute(new Attribute("resultType", resultType)); selectKey.addElement(selectKeySQL); return selectKey; }
Example 8
Source File: BatchInsertPlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 4 votes |
/** * batchInsert和batchInsertSelective的SQL生成 * * @param document * @param introspectedTable */ private void addSqlMapper(Document document, IntrospectedTable introspectedTable) { //table名名字 String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); //column信息 List<IntrospectedColumn> columnList = introspectedTable.getAllColumns(); XmlElement baseElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.INSERT, BATCH_INSERT, FullyQualifiedJavaType.getNewListInstance()); XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME, "item", "index", ","); baseElement.addElement(new TextElement(String.format("insert into %s (", tableName))); foreachElement.addElement(new TextElement("(")); for (int i = 0; i < columnList.size(); i++) { String columnInfo = ""; String valueInfo = ""; IntrospectedColumn introspectedColumn = columnList.get(i); if (introspectedColumn.isIdentity()) { continue; } columnInfo = introspectedColumn.getActualColumnName(); valueInfo = MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item."); if (i != (columnList.size() - 1)) { columnInfo += (","); valueInfo += (","); } baseElement.addElement(new TextElement(columnInfo)); foreachElement.addElement(new TextElement(valueInfo)); } foreachElement.addElement(new TextElement(")")); baseElement.addElement(new TextElement(")")); baseElement.addElement(new TextElement("values")); baseElement.addElement(foreachElement); //3.parent Add document.getRootElement().addElement(baseElement); }
Example 9
Source File: OracleBatchUpdatePlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 4 votes |
public void addSqlMapper(Document document, IntrospectedTable introspectedTable) { String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); List<IntrospectedColumn> columnList = introspectedTable.getAllColumns(); //primaryKey的JDBC名字 String primaryKeyName = introspectedTable.getPrimaryKeyColumns().get(0).getActualColumnName(); //primaryKey的JAVA名字 String primaryKeyJavaName = introspectedTable.getPrimaryKeyColumns().get(0).getJavaProperty(); String keyParameterClause = MyBatis3FormattingUtilities.getParameterClause(introspectedTable.getPrimaryKeyColumns().get(0), "item."); XmlElement baseElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.UPDATE, BATCH_UPDATE, FullyQualifiedJavaType.getNewListInstance()); XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME, "item", "index", ";"); foreachElement.addElement(new TextElement( String.format("update %s", tableName))); XmlElement setElement = new XmlElement("set"); StringBuilder columnInfo = new StringBuilder(); StringBuilder valuesInfo = new StringBuilder(); for (int i = 0; i < columnList.size(); i++) { IntrospectedColumn introspectedColumn = columnList.get(i); if (introspectedColumn.isIdentity()) { continue; } columnInfo.append(introspectedColumn.getActualColumnName()); valuesInfo.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.")); if (i != (columnList.size() - 1)) { valuesInfo.append(","); } String setSql = String.format(" %s = %s" ,columnInfo,valuesInfo); setElement.addElement(new TextElement(setSql)); valuesInfo.delete(0, valuesInfo.length()); columnInfo.delete(0, columnInfo.length()); } foreachElement.addElement(setElement); String whereSql = String.format("where %s = %s",primaryKeyName,keyParameterClause); foreachElement.addElement(new TextElement(whereSql)); baseElement.addElement(new TextElement("begin")); baseElement.addElement(foreachElement); baseElement.addElement(new TextElement(";end;")); //3.parent Add document.getRootElement().addElement(baseElement); }
Example 10
Source File: BatchDeletePlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 4 votes |
/** * 批量删除的xml方法生成 * @param document * @param introspectedTable */ private void addSqlMapper(Document document, IntrospectedTable introspectedTable){ String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); String key = introspectedTable.getPrimaryKeyColumns().get(0).getActualColumnName(); String baseSql = String.format("delete from %s where %s in (",tableName,key); FullyQualifiedJavaType paramType = introspectedTable.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType(); XmlElement deleteElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.DELETE, BATCH_DELETE,paramType); XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME,"item","index",null); deleteElement.addElement(new TextElement(baseSql)); foreachElement.addAttribute(new Attribute("separator", ",")); foreachElement.addElement(new TextElement("#{item}")); deleteElement.addElement(foreachElement); deleteElement.addElement(new TextElement(")")); document.getRootElement().addElement(deleteElement); }
Example 11
Source File: OracleBatchInsertPlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 4 votes |
private void addSqlMapper(Document document, IntrospectedTable introspectedTable) { //1.Batchinsert XmlElement baseElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.INSERT, BATCH_INSERT, FullyQualifiedJavaType.getNewListInstance()); XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME, "item", "index", "union all"); //tableName baseElement.addElement(new TextElement(String.format("insert into %s (", introspectedTable.getFullyQualifiedTableNameAtRuntime()))); foreachElement.addElement(new TextElement("(")); foreachElement.addElement(new TextElement("select")); for (int i = 0; i < introspectedTable.getAllColumns().size(); i++) { //column信息 IntrospectedColumn introspectedColumn = introspectedTable.getAllColumns().get(i); String columnInfo = ""; String valueInfo = ""; columnInfo = introspectedColumn.getActualColumnName(); valueInfo = MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item."); if (introspectedColumn.isIdentity()) { String nextval = introspectedTable.getFullyQualifiedTableNameAtRuntime()+"_SEQUENCE.nextval" ; valueInfo = nextval; } if (i != (introspectedTable.getAllColumns().size() - 1)) { columnInfo += (","); valueInfo += ","; } baseElement.addElement(new TextElement(columnInfo)); foreachElement.addElement(new TextElement(valueInfo)); } foreachElement.addElement(new TextElement("from dual")); foreachElement.addElement(new TextElement(")")); baseElement.addElement(new TextElement(")")); baseElement.addElement(new TextElement("(")); baseElement.addElement(foreachElement); baseElement.addElement(new TextElement(")")); //3.parent Add document.getRootElement().addElement(baseElement); }
Example 12
Source File: PostgreBatchUpdatePlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 4 votes |
private void addSqlMapper(Document document, IntrospectedTable introspectedTable){ String tableName = introspectedTable.getFullyQualifiedTableNameAtRuntime(); List<IntrospectedColumn> columnList = introspectedTable.getAllColumns(); String primaryKeyName = introspectedTable.getPrimaryKeyColumns().get(0).getActualColumnName(); //primaryKey的JAVA名字 String primaryKeyJavaName = introspectedTable.getPrimaryKeyColumns().get(0).getJavaProperty(); XmlElement updateElement = SqlMapperGeneratorTool.baseElementGenerator(SqlMapperGeneratorTool.UPDATE, BATCH_UPDATE, FullyQualifiedJavaType.getNewListInstance()); XmlElement foreachElement = SqlMapperGeneratorTool.baseForeachElementGenerator(PARAMETER_NAME, "item", "index", ","); String baseSql = String.format("update %s", tableName); updateElement.addElement(new TextElement(baseSql)); XmlElement setElement = new XmlElement("set"); StringBuilder columnInfo = new StringBuilder(); StringBuilder valuesInfo = new StringBuilder(); StringBuilder columnInfoTotal = new StringBuilder(); for (int i = 0; i < columnList.size(); i++) { IntrospectedColumn introspectedColumn = columnList.get(i); columnInfo.append(introspectedColumn.getActualColumnName()); columnInfoTotal.append(introspectedColumn.getActualColumnName()); if (introspectedColumn.getFullyQualifiedJavaType().equals(FullyQualifiedJavaType.getDateInstance())){ valuesInfo.append("to_timestamp("); valuesInfo.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.")); valuesInfo.append(",'yyyy-MM-dd hh24:mi:ss')"); }else { valuesInfo.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "item.")); } String setSql = String.format(" %s = %s," ,columnInfo,"temp."+columnInfo); if (i == (columnList.size() - 1)) { setSql = setSql.substring(0, setSql.length() - 1); } if (!introspectedColumn.isIdentity() && !introspectedColumn.getActualColumnName().equals(primaryKeyName)) { setElement.addElement(new TextElement(setSql)); } if (i != (columnList.size() - 1)) { valuesInfo.append(","); columnInfo.append(","); columnInfoTotal.append(","); } columnInfo.delete(0, valuesInfo.length()); } foreachElement.addElement(new TextElement("(")); foreachElement.addElement(new TextElement(valuesInfo.toString())); foreachElement.addElement(new TextElement(")")); updateElement.addElement(setElement); updateElement.addElement(new TextElement("from (values")); updateElement.addElement(foreachElement); updateElement.addElement(new TextElement(String.format(") as temp (%s) where %s.%s=temp.%s;",columnInfoTotal,tableName,primaryKeyName,primaryKeyName))); //3.parent Add document.getRootElement().addElement(updateElement); }