本文整理匯總了Java中org.apache.ibatis.mapping.MappedStatement.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java MappedStatement.Builder方法的具體用法?Java MappedStatement.Builder怎麽用?Java MappedStatement.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.ibatis.mapping.MappedStatement
的用法示例。
在下文中一共展示了MappedStatement.Builder方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyFromMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement copyFromMappedStatement(MappedStatement ms,
SqlSource newSqlSource) {
MappedStatement.Builder builder = new MappedStatement.Builder(
ms.getConfiguration(), ms.getId(), newSqlSource,
ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if (null != ms.getKeyProperties()) {
for (String keyProperty : ms.getKeyProperties()) {
builder.keyProperty(keyProperty);
}
}
builder.timeout(ms.getTimeout());
builder.parameterMap(ms.getParameterMap());
builder.resultMaps(ms.getResultMaps());
builder.cache(ms.getCache());
return builder.build();
}
示例2: copyFromMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource,
ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
// builder.keyProperty((ms.getKeyProperty()));
builder.keyProperty(arrayToStr(ms.getKeyProperties()));
// setStatementTimeout()
builder.timeout(ms.getTimeout());
// setStatementResultMap()
builder.parameterMap(ms.getParameterMap());
// setStatementResultMap()
builder.resultMaps(ms.getResultMaps());
builder.resultSetType(ms.getResultSetType());
// setStatementCache()
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例3: insert
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
public String insert(Class<?> entityType) {
// 命令名稱
String statementId = buildStatementId(entityType, "insert");
if (configuration.hasStatement(statementId)) {
return statementId;
}
// 創建命令
String sql = new SqlBuilder(entityType).insert();
SqlSource sqlSource = new RawSqlSource(configuration, sql, null);
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, statementId, sqlSource,
SqlCommandType.INSERT);
// 判斷是否需要自動生成主鍵
EntityMetadata metadata = EntityMetadata.get(entityType);
for (IdProperty idProperty : metadata.getIdProperties()) {
KeyGenerator keyGenerator = idProperty.getKeyGenerator();
if (keyGenerator == null) {
continue;
}
String propertyName = idProperty.getName();
String columnName = idProperty.getColumnName();
statementBuilder.keyProperty(propertyName).keyColumn(columnName).keyGenerator(keyGenerator);
}
MappedStatement statement = statementBuilder.build();
StatementResultMapHelper.addMappedStatement(configuration, statement);
return statementId;
}
示例4: build
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
/**
* @param configuration
* @param entity
*/
public static void build(Configuration configuration, LanguageDriver languageDriver,
EntityInfo entity) {
String[] names = GeneralSqlGenerator.methodDefines.updateName().split(",");
for (String name : names) {
String msId = entity.getMapperClass().getName() + "." + name;
EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
String sql = buildUpdateSql(entityMapper, name.endsWith("Selective"));
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql,
entity.getEntityClass());
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration,
msId, sqlSource, SqlCommandType.UPDATE);
MappedStatement statement = statementBuilder.build();
configuration.addMappedStatement(statement);
}
}
示例5: build
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
/**
* @param configuration
* @param entity
*/
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.deleteName();
// 從參數對象裏提取注解信息
EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
// 生成sql
String sql = buildDeleteSql(entityMapper);
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.DELETE);
MappedStatement statement = statementBuilder.build();
configuration.addMappedStatement(statement);
}
示例6: createCountMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement createCountMappedStatement(MappedStatement ms, String newMsId) {
MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), newMsId, ms.getSqlSource(), ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
StringBuilder keyProperties = new StringBuilder();
for (String keyProperty : ms.getKeyProperties()) {
keyProperties.append(keyProperty).append(",");
}
keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
builder.keyProperty(keyProperties.toString());
}
builder.timeout(ms.getTimeout());
builder.parameterMap(ms.getParameterMap());
//count查詢返回值int
List<ResultMap> resultMaps = new ArrayList<ResultMap>();
ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), Long.class, new ArrayList<ResultMapping>(0)).build();
resultMaps.add(resultMap);
builder.resultMaps(resultMaps);
builder.resultSetType(ms.getResultSetType());
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例7: update
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
public String update(Class<?> entityType, String[] fields, String condition) {
// 命令名稱
String statementId = buildStatementId(entityType, "[email protected]" + ArrayUtils.join(fields, ",") + ">" + condition);
if (configuration.hasStatement(statementId)) {
return statementId;
}
String sql = new SqlBuilder(entityType).update(fields, condition);
// 創建命令
SqlSource sqlSource = new RawSqlSource(configuration, sql, null);
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, statementId, sqlSource,
SqlCommandType.UPDATE);
MappedStatement statement = statementBuilder.build();
StatementResultMapHelper.addMappedStatement(configuration, statement);
return statementId;
}
示例8: delete
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
public String delete(Class<?> entityType, String condition) {
// 命令名稱
String statementId = buildStatementId(entityType, "[email protected]" + condition);
if (configuration.hasStatement(statementId)) {
return statementId;
}
String sql = new SqlBuilder(entityType).delete(condition);
// 創建命令
SqlSource sqlSource = new RawSqlSource(configuration, sql, null);
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, statementId, sqlSource,
SqlCommandType.DELETE);
MappedStatement statement = statementBuilder.build();
StatementResultMapHelper.addMappedStatement(configuration, statement);
return statementId;
}
示例9: build
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
/**
* @param configuration
* @param entity
*/
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
String[] names = GeneralSqlGenerator.methodDefines.insertName().split(",");
for (String name : names) {
String msId = entity.getMapperClass().getName() + "." + name;
// 從參數對象裏提取注解信息
EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
// 生成sql
String sql = buildInsertSql(entityMapper, name.endsWith("Selective"));
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.INSERT);
KeyGenerator keyGenerator = entityMapper.autoId() ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
statementBuilder.keyGenerator(keyGenerator)//
.keyProperty(entityMapper.getIdColumn().getProperty())//
.keyColumn(entityMapper.getIdColumn().getColumn());
MappedStatement statement = statementBuilder.build();
configuration.addMappedStatement(statement);
}
}
示例10: copyFromMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource)
{
Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource, ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
String[] arr = ms.getKeyProperties();
if(arr != null && arr.length > 0)
{
StringBuilder sb = new StringBuilder();
for(String s : arr)
{
sb.append(",").append(s);
}
if(sb.length() > 0)
{
sb.delete(0, 1);
}
builder.keyProperty(sb.toString());
}
// setStatementTimeout()
builder.timeout(ms.getTimeout());
// setStatementResultMap()
builder.parameterMap(ms.getParameterMap());
// setStatementResultMap()
builder.resultMaps(ms.getResultMaps());
builder.resultSetType(ms.getResultSetType());
// setStatementCache()
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例11: getCountMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
/**
* 新建count查詢的MappedStatement
*
* @param ms
* @return
*/
public MappedStatement getCountMappedStatement(MappedStatement ms) {
String newMsId = ms.getId() + PAGE_COUNT_SUFFIX;
MappedStatement statement = null;
Configuration configuration = ms.getConfiguration();
try {
statement = configuration.getMappedStatement(newMsId);
if (statement != null) { return statement; }
} catch (Exception e) {
}
synchronized (configuration) {
if (configuration.hasStatement(newMsId)) { return configuration.getMappedStatement(newMsId); }
MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(),
newMsId, ms.getSqlSource(), ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
StringBuilder keyProperties = new StringBuilder();
for (String keyProperty : ms.getKeyProperties()) {
keyProperties.append(keyProperty).append(",");
}
keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
builder.keyProperty(keyProperties.toString());
}
builder.timeout(ms.getTimeout());
builder.parameterMap(ms.getParameterMap());
//count查詢返回值int
List<ResultMap> resultMaps = new ArrayList<ResultMap>();
String id = newMsId + "-Inline";
ResultMap resultMap = new ResultMap.Builder(configuration, id, Long.class,
new ArrayList<ResultMapping>(0)).build();
resultMaps.add(resultMap);
builder.resultMaps(resultMaps);
builder.resultSetType(ms.getResultSetType());
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
statement = builder.build();
configuration.addMappedStatement(statement);
return statement;
}
}
示例12: getQueryIdsMappedStatementForUpdateCache
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement getQueryIdsMappedStatementForUpdateCache(MappedStatement mt,
EntityInfo entityInfo) {
String msId = mt.getId() + QUERY_IDS_SUFFIX;
MappedStatement statement = null;
Configuration configuration = mt.getConfiguration();
try {
statement = configuration.getMappedStatement(msId);
if (statement != null) { return statement; }
} catch (Exception e) {
}
synchronized (configuration) {
if (configuration.hasStatement(msId)) { return configuration.getMappedStatement(msId); }
String sql = entityInfo.getMapperSqls().get(mt.getId());
if (StringUtils.isNotBlank(sql)) {
if (!sql.toLowerCase().contains(entityInfo.getTableName().toLowerCase())) {
return null;
}
sql = "select " + entityInfo.getIdColumn() + " from " + entityInfo.getTableName()
+ " WHERE " + sql.split(WHERE_REGEX)[1];
sql = String.format(SqlTemplate.SCRIPT_TEMAPLATE, sql);
} else {
sql = PARSE_SQL_ERROR_DEFAULT;
}
SqlSource sqlSource = configuration.getDefaultScriptingLanguageInstance()
.createSqlSource(configuration, sql, Object.class);
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration,
msId, sqlSource, SqlCommandType.SELECT);
statementBuilder.resource(mt.getResource());
statementBuilder.fetchSize(mt.getFetchSize());
statementBuilder.statementType(mt.getStatementType());
statementBuilder.parameterMap(mt.getParameterMap());
statement = statementBuilder.build();
List<ResultMap> resultMaps = new ArrayList<ResultMap>();
String id = msId + "-Inline";
ResultMap.Builder builder = new ResultMap.Builder(configuration, id,
entityInfo.getIdType(), new ArrayList<ResultMapping>(), true);
resultMaps.add(builder.build());
MetaObject metaObject = SystemMetaObject.forObject(statement);
metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps));
configuration.addMappedStatement(statement);
return statement;
}
}
示例13: build
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
/**
* @param configuration
* @param entity
*/
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.selectName();
EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
String sql = buildGetByIdSql(entityMapper);
SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.SELECT);
// 將返回值修改為實體類型
MappedStatement statement = statementBuilder.build();
setResultType(configuration, statement, entity.getEntityClass());
configuration.addMappedStatement(statement);
}