本文整理汇总了Java中org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator类的典型用法代码示例。如果您正苦于以下问题:Java Jdbc3KeyGenerator类的具体用法?Java Jdbc3KeyGenerator怎么用?Java Jdbc3KeyGenerator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Jdbc3KeyGenerator类属于org.apache.ibatis.executor.keygen包,在下文中一共展示了Jdbc3KeyGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Builder
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
public Builder(Configuration configuration, String id, SqlSource sqlSource, SqlCommandType sqlCommandType) {
mappedStatement.configuration = configuration;
mappedStatement.id = id;
mappedStatement.sqlSource = sqlSource;
mappedStatement.statementType = StatementType.PREPARED;
mappedStatement.parameterMap = new ParameterMap.Builder(configuration, "defaultParameterMap", null, new ArrayList<ParameterMapping>()).build();
mappedStatement.resultMaps = new ArrayList<ResultMap>();
mappedStatement.sqlCommandType = sqlCommandType;
mappedStatement.keyGenerator = configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType) ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
String logId = id;
if (configuration.getLogPrefix() != null) {
logId = configuration.getLogPrefix() + id;
}
mappedStatement.statementLog = LogFactory.getLog(logId);
mappedStatement.lang = configuration.getDefaultScriptingLanuageInstance();
}
示例2: update
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
@Override
public int update(Statement statement) throws SQLException {
String sql = boundSql.getSql();
Object parameterObject = boundSql.getParameterObject();
KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
int rows;
if (keyGenerator instanceof Jdbc3KeyGenerator) {
statement.execute(sql, Statement.RETURN_GENERATED_KEYS);
rows = statement.getUpdateCount();
keyGenerator.processAfter(executor, mappedStatement, statement, parameterObject);
} else if (keyGenerator instanceof SelectKeyGenerator) {
statement.execute(sql);
rows = statement.getUpdateCount();
keyGenerator.processAfter(executor, mappedStatement, statement, parameterObject);
} else {
statement.execute(sql);
rows = statement.getUpdateCount();
}
return rows;
}
示例3: instantiateStatement
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
@Override
protected Statement instantiateStatement(Connection connection) throws SQLException {
String sql = boundSql.getSql();
if (mappedStatement.getKeyGenerator() instanceof Jdbc3KeyGenerator) {
String[] keyColumnNames = mappedStatement.getKeyColumns();
if (keyColumnNames == null) {
return connection.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
} else {
return connection.prepareStatement(sql, keyColumnNames);
}
} else if (mappedStatement.getResultSetType() != null) {
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
} else {
return connection.prepareStatement(sql);
}
}
示例4: prepareInsertAuthorMappedStatementWithAutoKey
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT)
.parameterMap(
new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
}
}).build())
.cache(authorCache)
.keyGenerator(new Jdbc3KeyGenerator())
.keyProperty("id")
.build();
return ms;
}
示例5: getKeyGeneratorType
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
protected KeyGeneratorType getKeyGeneratorType(
MappedStatement mappedStatement)
throws NoSuchFieldException, IllegalAccessException {
KeyGenerator keyGenerator = mappedStatement
.getKeyGenerator();
KeyGeneratorType keyGeneratorType = KeyGeneratorType.NONE;
if (keyGenerator instanceof SelectKeyGenerator) {
Boolean executeBefore = (Boolean) ReflectHelper
.getValueByFieldName(keyGenerator,
"executeBefore");
if (executeBefore) {
keyGeneratorType = KeyGeneratorType.SELECT_BEFORE;
} else {
keyGeneratorType = KeyGeneratorType.SELECT_AFTER;
}
} else if (keyGenerator instanceof Jdbc3KeyGenerator) {
keyGeneratorType = KeyGeneratorType.SELECT_AFTER;
}
return keyGeneratorType;
}
示例6: Builder
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
public Builder(Configuration configuration, String id, SqlSource sqlSource, SqlCommandType sqlCommandType) {
mappedStatement.configuration = configuration;
mappedStatement.id = id;
mappedStatement.sqlSource = sqlSource;
mappedStatement.statementType = StatementType.PREPARED;
mappedStatement.parameterMap = new ParameterMap.Builder(configuration, "defaultParameterMap", null, new ArrayList<ParameterMapping>()).build();
mappedStatement.resultMaps = new ArrayList<ResultMap>();
mappedStatement.timeout = configuration.getDefaultStatementTimeout();
mappedStatement.sqlCommandType = sqlCommandType;
mappedStatement.keyGenerator = configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType) ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
String logId = id;
if (configuration.getLogPrefix() != null) {
logId = configuration.getLogPrefix() + id;
}
mappedStatement.statementLog = LogFactory.getLog(logId);
mappedStatement.lang = configuration.getDefaultScriptingLanuageInstance();
}
示例7: update
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
@Override
public int update(Statement statement) throws SQLException {
String sql = boundSql.getSql();
Object parameterObject = boundSql.getParameterObject();
KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
int rows;
if (keyGenerator instanceof Jdbc3KeyGenerator) {
statement.execute(sql, Statement.RETURN_GENERATED_KEYS);
rows = statement.getUpdateCount();
keyGenerator.processAfter(executor, mappedStatement, statement, parameterObject);
} else if (keyGenerator instanceof SelectKeyGenerator) {
statement.execute(sql);
rows = statement.getUpdateCount();
keyGenerator.processAfter(executor, mappedStatement, statement, parameterObject);
} else {
//如果没有keyGenerator,直接调用Statement.execute和Statement.getUpdateCount
statement.execute(sql);
rows = statement.getUpdateCount();
}
return rows;
}
示例8: instantiateStatement
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
@Override
protected Statement instantiateStatement(Connection connection) throws SQLException {
//调用Connection.prepareStatement
String sql = boundSql.getSql();
if (mappedStatement.getKeyGenerator() instanceof Jdbc3KeyGenerator) {
String[] keyColumnNames = mappedStatement.getKeyColumns();
if (keyColumnNames == null) {
return connection.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
} else {
return connection.prepareStatement(sql, keyColumnNames);
}
} else if (mappedStatement.getResultSetType() != null) {
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
} else {
return connection.prepareStatement(sql);
}
}
示例9: Builder
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
public Builder(Configuration configuration, String id, SqlSource sqlSource, SqlCommandType sqlCommandType) {
mappedStatement.configuration = configuration;
mappedStatement.id = id;
mappedStatement.sqlSource = sqlSource;
mappedStatement.statementType = StatementType.PREPARED;
mappedStatement.parameterMap = new ParameterMap.Builder(configuration, "defaultParameterMap", null, new ArrayList<ParameterMapping>()).build();
mappedStatement.resultMaps = new ArrayList<ResultMap>();
mappedStatement.sqlCommandType = sqlCommandType;
mappedStatement.keyGenerator = configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType) ? Jdbc3KeyGenerator.INSTANCE : NoKeyGenerator.INSTANCE;
String logId = id;
if (configuration.getLogPrefix() != null) {
logId = configuration.getLogPrefix() + id;
}
mappedStatement.statementLog = LogFactory.getLog(logId);
mappedStatement.lang = configuration.getDefaultScriptingLanguageInstance();
}
示例10: prepareInsertAuthorMappedStatementWithAutoKey
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT)
.parameterMap(
new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
}
}).build())
.cache(authorCache)
.keyGenerator(Jdbc3KeyGenerator.INSTANCE)
.keyProperty("id")
.build();
return ms;
}
示例11: setSqlSource
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
/**
* 重新设置SqlSource,同时判断如果是Jdbc3KeyGenerator,就设置为MultipleJdbc3KeyGenerator
*
* @param ms
* @param sqlSource
*/
protected void setSqlSource(MappedStatement ms, SqlSource sqlSource) {
MetaObject msObject = SystemMetaObject.forObject(ms);
msObject.setValue("sqlSource", sqlSource);
//如果是Jdbc3KeyGenerator,就设置为MultipleJdbc3KeyGenerator
KeyGenerator keyGenerator = ms.getKeyGenerator();
if (keyGenerator instanceof Jdbc3KeyGenerator) {
msObject.setValue("keyGenerator", new MultipleJdbc3KeyGenerator());
}
}
示例12: IdProperty
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
public IdProperty(EntityMetadata metadata , Field field){
super(metadata , field);
Id id = field.getAnnotation(Id.class);
if(id.useGeneratedKeys()){
keyGenerator = new Jdbc3KeyGenerator();
}
}
示例13: build
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的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);
}
}
示例14: build
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的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);
}
}
示例15: buildInsert
import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; //导入依赖的package包/类
private void buildInsert(String statementId) {
//
Integer fetchSize = null;
Integer timeout = null;
Class<?> parameterType = entityClass;
///~~~~~~~~~~
boolean flushCache = true;
boolean useCache = false;
boolean resultOrdered = false;
KeyGenerator keyGenerator = null;
String keyProperty = null;
String keyColumn = null;
Id id = AnnotationUtils.findDeclaredAnnotation(Id.class, entityClass);
if(id != null) {
String keyStatementId = entityClass.getName() + ".insert" + SelectKeyGenerator.SELECT_KEY_SUFFIX;
if (configuration.hasKeyGenerator(keyStatementId)) {
keyGenerator = configuration.getKeyGenerator(keyStatementId);
} else {
keyGenerator = id.generatedKeys() ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
}
keyProperty = idField.getName();
keyColumn = StringUtils.isBlank(id.column()) ? CaseFormatUtils.camelToUnderScore(idField.getName()) : id.column();
}
List<SqlNode> contents = new ArrayList<SqlNode>();
contents.add(this.getInsertSql());
SqlSource sqlSource = new DynamicSqlSource(configuration, new MixedSqlNode(contents));
assistant.addMappedStatement(statementId, sqlSource, StatementType.PREPARED,
SqlCommandType.INSERT, fetchSize, timeout, null, parameterType, null, null,
ResultSetType.FORWARD_ONLY, flushCache, useCache, resultOrdered, keyGenerator,
keyProperty, keyColumn, databaseId, lang);
}