List of usage examples for org.apache.ibatis.builder MapperBuilderAssistant getConfiguration
public Configuration getConfiguration()
From source file:com.baomidou.mybatisplus.mapper.AutoSqlInjector.java
License:Apache License
/** * CRUD? ???//from ww w. ja va 2s . co m * * @param builderAssistant * @param mapperClass */ public void inspectInject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) { String className = mapperClass.toString(); Set<String> mapperRegistryCache = GlobalConfiguration .getMapperRegistryCache(builderAssistant.getConfiguration()); if (!mapperRegistryCache.contains(className)) { inject(builderAssistant, mapperClass); mapperRegistryCache.add(className); } }
From source file:com.baomidou.mybatisplus.mapper.AutoSqlInjector.java
License:Apache License
/** * ? crudSql//w w w . j a v a 2s. c o m */ public void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) { this.configuration = builderAssistant.getConfiguration(); this.builderAssistant = builderAssistant; this.languageDriver = configuration.getDefaultScriptingLanguageInstance(); /* * PLUS ? > ? */ GlobalConfiguration globalCache = this.getGlobalConfig(); if (!globalCache.isDbColumnUnderline()) { globalCache.setDbColumnUnderline(configuration.isMapUnderscoreToCamelCase()); } Class<?> modelClass = extractModelClass(mapperClass); if (modelClass != null) { TableInfo table = TableInfoHelper.initTableInfo(builderAssistant, modelClass); injectSql(builderAssistant, mapperClass, modelClass, table); } }
From source file:com.baomidou.mybatisplus.toolkit.TableInfoHelper.java
License:Apache License
/** * <p>/*from w w w . j ava 2 s . c o m*/ * ?????? * <p> * * @param clazz ?? * @return */ public synchronized static TableInfo initTableInfo(MapperBuilderAssistant builderAssistant, Class<?> clazz) { TableInfo ti = tableInfoCache.get(clazz.getName()); if (ti != null) { return ti; } TableInfo tableInfo = new TableInfo(); GlobalConfiguration globalConfig; if (null != builderAssistant) { tableInfo.setCurrentNamespace(builderAssistant.getCurrentNamespace()); tableInfo.setConfigMark(builderAssistant.getConfiguration()); globalConfig = GlobalConfiguration.getGlobalConfig(builderAssistant.getConfiguration()); } else { // globalConfig = GlobalConfiguration.DEFAULT; } /* ?? */ TableName table = clazz.getAnnotation(TableName.class); String tableName = clazz.getSimpleName(); if (table != null && StringUtils.isNotEmpty(table.value())) { tableName = table.value(); } else { // ? if (globalConfig.isDbColumnUnderline()) { tableName = StringUtils.camelToUnderline(tableName); } // ?? if (globalConfig.isCapitalMode()) { tableName = tableName.toUpperCase(); } else { // ?? tableName = StringUtils.firstToLowerCase(tableName); } } tableInfo.setTableName(tableName); /* Oracle ? */ KeySequence keySequence = clazz.getAnnotation(KeySequence.class); if (keySequence != null) { tableInfo.setKeySequence(keySequence); } /* */ if (table != null && StringUtils.isNotEmpty(table.resultMap())) { tableInfo.setResultMap(table.resultMap()); } List<TableFieldInfo> fieldList = new ArrayList<>(); List<Field> list = getAllFields(clazz); boolean existTableId = existTableId(list); for (Field field : list) { /* * ID ? */ if (existTableId) { if (initTableId(globalConfig, tableInfo, field, clazz)) { continue; } } else if (initFieldId(globalConfig, tableInfo, field, clazz)) { continue; } /* * ? */ if (initTableField(globalConfig, tableInfo, fieldList, field, clazz)) { continue; } /* * , camelToUnderline ?, TableField , ? */ fieldList.add(new TableFieldInfo(globalConfig, tableInfo, field)); } /* */ tableInfo.setFieldList(globalConfig, fieldList); /* * ???? */ if (StringUtils.isEmpty(tableInfo.getKeyColumn())) { logger.warn(String.format("Warn: Could not find @TableId in Class: %s.", clazz.getName())); } /* * */ tableInfoCache.put(clazz.getName(), tableInfo); return tableInfo; }
From source file:com.baomidou.mybatisplus.toolkit.TableInfoHelper.java
License:Apache License
public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant, String baseStatementId, LanguageDriver languageDriver) { DBType dbType = GlobalConfiguration.getDbType(builderAssistant.getConfiguration()); if (dbType != DBType.ORACLE) throw new IllegalArgumentException("??Oracle?"); String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX; Class<?> resultTypeClass = tableInfo.getKeySequence().idClazz(); Class<?> parameterTypeClass = null; StatementType statementType = StatementType.PREPARED; String keyProperty = tableInfo.getKeyProperty(); String keyColumn = tableInfo.getKeyColumn(); boolean executeBefore = true; boolean useCache = false; KeyGenerator keyGenerator = new NoKeyGenerator(); Integer fetchSize = null;/*ww w .j av a 2 s . c om*/ Integer timeout = null; boolean flushCache = false; String parameterMap = null; String resultMap = null; ResultSetType resultSetTypeEnum = null; //??ORACLE???? String sql = "select " + tableInfo.getKeySequence().value() + ".nextval from dual"; SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(), sql.trim(), null); SqlCommandType sqlCommandType = SqlCommandType.SELECT; builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum, flushCache, useCache, false, keyGenerator, keyProperty, keyColumn, null, languageDriver, null); id = builderAssistant.applyCurrentNamespace(id, false); MappedStatement keyStatement = builderAssistant.getConfiguration().getMappedStatement(id, false); SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore); builderAssistant.getConfiguration().addKeyGenerator(id, answer); return answer; }
From source file:com.mybatisX.mapper.AutoSqlInjector.java
License:Apache License
/** * ? crudSql//www.j av a 2 s. co m */ public void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) { this.configuration = builderAssistant.getConfiguration(); this.builderAssistant = builderAssistant; this.languageDriver = configuration.getDefaultScriptingLanuageInstance(); this.dbType = MybatisConfiguration.DB_TYPE; /* * PLUS ? > ? */ if (!MybatisConfiguration.DB_COLUMN_UNDERLINE) { MybatisConfiguration.DB_COLUMN_UNDERLINE = configuration.isMapUnderscoreToCamelCase(); } Class<?> modelClass = extractModelClass(mapperClass); TableInfo table = TableInfoHelper.initTableInfo(builderAssistant, modelClass); /** * ? */ if (null != table && null != table.getKeyProperty()) { /* ? */ this.injectInsertOneSql(mapperClass, modelClass, table); /* */ this.injectDeleteSql(mapperClass, modelClass, table); this.injectDeleteByMapSql(mapperClass, table); this.injectDeleteByIdSql(false, mapperClass, modelClass, table); this.injectDeleteByIdSql(true, mapperClass, modelClass, table); /* */ this.injectUpdateByIdSql(mapperClass, modelClass, table); this.injectUpdateSql(mapperClass, modelClass, table); /* */ this.injectSelectByIdSql(false, mapperClass, modelClass, table); this.injectSelectByIdSql(true, mapperClass, modelClass, table); this.injectSelectByMapSql(mapperClass, modelClass, table); this.injectSelectOneSql(mapperClass, modelClass, table); this.injectSelectCountSql(mapperClass, modelClass, table); this.injectSelectListSql(SqlMethod.SELECT_LIST, mapperClass, modelClass, table); this.injectSelectListSql(SqlMethod.SELECT_PAGE, mapperClass, modelClass, table); /* */ this.inject(configuration, builderAssistant, mapperClass, modelClass, table); } else { /** * */ logger.warn(String.format("%s ,Not found @TableId annotation, cannot use mybatis-plus curd method.", modelClass.toString())); } }
From source file:com.sinotopia.mybatis.plus.toolkit.TableInfoHelper.java
License:Apache License
/** * <p>// w w w. ja va 2 s . co m * ?????? * <p> * * @param clazz ?? * @return */ public synchronized static TableInfo initTableInfo(MapperBuilderAssistant builderAssistant, Class<?> clazz) { TableInfo ti = tableInfoCache.get(clazz.getName()); if (ti != null) { return ti; } TableInfo tableInfo = new TableInfo(); GlobalConfiguration globalConfig; if (null != builderAssistant) { tableInfo.setCurrentNamespace(builderAssistant.getCurrentNamespace()); tableInfo.setConfigMark(builderAssistant.getConfiguration()); globalConfig = GlobalConfiguration.getGlobalConfig(builderAssistant.getConfiguration()); } else { // globalConfig = GlobalConfiguration.DEFAULT; } /* ?? */ TableName table = clazz.getAnnotation(TableName.class); String tableName = clazz.getSimpleName(); if (table != null && StringUtils.isNotEmpty(table.value())) { tableName = table.value(); } else { // ? if (globalConfig.isDbColumnUnderline()) { tableName = StringUtils.camelToUnderline(tableName); } // ?? if (globalConfig.isCapitalMode()) { tableName = tableName.toUpperCase(); } else { // ?? tableName = StringUtils.firstToLowerCase(tableName); } } tableInfo.setTableName(tableName); // ? KEY ? if (null != globalConfig.getKeyGenerator()) { tableInfo.setKeySequence(clazz.getAnnotation(KeySequence.class)); } /* */ if (table != null && StringUtils.isNotEmpty(table.resultMap())) { tableInfo.setResultMap(table.resultMap()); } List<TableFieldInfo> fieldList = new ArrayList<>(); List<Field> list = getAllFields(clazz); boolean existTableId = existTableId(list); for (Field field : list) { /* * ID ? */ if (existTableId) { if (initTableId(globalConfig, tableInfo, field, clazz)) { continue; } } else if (initFieldId(globalConfig, tableInfo, field, clazz)) { continue; } /* * ? */ if (initTableField(globalConfig, tableInfo, fieldList, field, clazz)) { continue; } /* * , camelToUnderline ?, TableField , ? */ fieldList.add(new TableFieldInfo(globalConfig, tableInfo, field)); } /* */ tableInfo.setFieldList(globalConfig, fieldList); /* * ???? */ if (StringUtils.isEmpty(tableInfo.getKeyColumn())) { logger.warn(String.format("Warn: Could not find @TableId in Class: %s.", clazz.getName())); } /* * */ tableInfoCache.put(clazz.getName(), tableInfo); return tableInfo; }
From source file:com.sinotopia.mybatis.plus.toolkit.TableInfoHelper.java
License:Apache License
/** * <p>//from w ww . j a v a 2s . c o m * KEY ? * </p> */ public static KeyGenerator genKeyGenerator(TableInfo tableInfo, MapperBuilderAssistant builderAssistant, String baseStatementId, LanguageDriver languageDriver) { IKeyGenerator keyGenerator = GlobalConfiguration.getKeyGenerator(builderAssistant.getConfiguration()); if (null == keyGenerator) { throw new IllegalArgumentException("not configure IKeyGenerator implementation class."); } String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX; Class<?> resultTypeClass = tableInfo.getKeySequence().idClazz(); StatementType statementType = StatementType.PREPARED; String keyProperty = tableInfo.getKeyProperty(); String keyColumn = tableInfo.getKeyColumn(); SqlSource sqlSource = languageDriver.createSqlSource(builderAssistant.getConfiguration(), keyGenerator.executeSql(tableInfo), null); builderAssistant.addMappedStatement(id, sqlSource, statementType, SqlCommandType.SELECT, null, null, null, null, null, resultTypeClass, null, false, false, false, new NoKeyGenerator(), keyProperty, keyColumn, null, languageDriver, null); id = builderAssistant.applyCurrentNamespace(id, false); MappedStatement keyStatement = builderAssistant.getConfiguration().getMappedStatement(id, false); SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, true); builderAssistant.getConfiguration().addKeyGenerator(id, answer); return answer; }
From source file:org.apache.playframework.mybatisplus.mapper.AutoSqlInjector.java
License:Apache License
/** * ? crudSql// w ww . j av a 2 s . co m */ public void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) { this.configuration = builderAssistant.getConfiguration(); this.builderAssistant = builderAssistant; this.languageDriver = configuration.getDefaultScriptingLanuageInstance(); GlobalConfiguration globalCache = GlobalConfiguration.GlobalConfig(configuration); this.dbType = globalCache.getDbType(); /* * PLUS ? > ? */ if (!globalCache.isDbColumnUnderline()) { globalCache.setDbColumnUnderline(configuration.isMapUnderscoreToCamelCase()); } Class<?> modelClass = extractModelClass(mapperClass); TableInfo table = TableInfoHelper.initTableInfo(builderAssistant, modelClass); /** * ? */ if (null != table && null != table.getKeyProperty()) { /* ? */ this.injectInsertOneSql(mapperClass, modelClass, table); /* */ this.injectDeleteSql(mapperClass, modelClass, table); this.injectDeleteByMapSql(mapperClass, table); this.injectDeleteByIdSql(false, mapperClass, modelClass, table); this.injectDeleteByIdSql(true, mapperClass, modelClass, table); /* */ this.injectUpdateByIdSql(mapperClass, modelClass, table); this.injectUpdateSql(mapperClass, modelClass, table); /* */ this.injectSelectByIdSql(false, mapperClass, modelClass, table); this.injectSelectByIdSql(true, mapperClass, modelClass, table); this.injectSelectByMapSql(mapperClass, modelClass, table); this.injectSelectOneSql(mapperClass, modelClass, table); this.injectSelectCountSql(mapperClass, modelClass, table); this.injectSelectListSql(SqlMethod.SELECT_LIST, mapperClass, modelClass, table); this.injectSelectListSql(SqlMethod.SELECT_PAGE, mapperClass, modelClass, table); /* */ this.inject(configuration, builderAssistant, mapperClass, modelClass, table); } else { /** * */ logger.warn(String.format("%s ,Not found @TableId annotation, cannot use mybatis-plus curd method.", modelClass.toString())); } }