org.apache.ibatis.annotations.SelectKey Java Examples

The following examples show how to use org.apache.ibatis.annotations.SelectKey. 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: PostgresDeviceLogMapper.java    From hmdm-server with Apache License 2.0 6 votes vote down vote up
@Insert("INSERT INTO plugin_devicelog_settings_rules (" +
        "  settingId, " +
        "  name, " +
        "  active, " +
        "  applicationId, " +
        "  severity, " +
        "  filter, " +
        "  groupId, " +
        "  configurationId " +
        ") " +
        "VALUES (" +
        "  #{settingId}, " +
        "  #{name}, " +
        "  #{active}, " +
        "  #{applicationId}, " +
        "  #{severity}, " +
        "  #{filter}, " +
        "  #{groupId}, " +
        "  #{configurationId} " +
        ")")
@SelectKey( statement = "SELECT currval('plugin_devicelog_settings_rules_id_seq')",
        keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertPluginSettingsRule(PostgresDeviceLogRule rule);
 
Example #2
Source File: MapperAnnotationBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private KeyGenerator handleSelectKeyAnnotation(SelectKey selectKeyAnnotation, String baseStatementId, Class<?> parameterTypeClass, LanguageDriver languageDriver) {
  String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
  Class<?> resultTypeClass = selectKeyAnnotation.resultType();
  StatementType statementType = selectKeyAnnotation.statementType();
  String keyProperty = selectKeyAnnotation.keyProperty();
  String keyColumn = selectKeyAnnotation.keyColumn();
  boolean executeBefore = selectKeyAnnotation.before();

  // defaults
  boolean useCache = false;
  KeyGenerator keyGenerator = new NoKeyGenerator();
  Integer fetchSize = null;
  Integer timeout = null;
  boolean flushCache = false;
  String parameterMap = null;
  String resultMap = null;
  ResultSetType resultSetTypeEnum = null;

  SqlSource sqlSource = buildSqlSourceFromStrings(selectKeyAnnotation.statement(), parameterTypeClass, languageDriver);
  SqlCommandType sqlCommandType = SqlCommandType.SELECT;

  assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum,
      flushCache, useCache, false,
      keyGenerator, keyProperty, keyColumn, null, languageDriver, null);

  id = assistant.applyCurrentNamespace(id, false);

  MappedStatement keyStatement = configuration.getMappedStatement(id, false);
  SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore);
  configuration.addKeyGenerator(id, answer);
  return answer;
}
 
Example #3
Source File: CoffeeMapper.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table t_coffee
 *
 * @mbg.generated Mon Dec 16 18:17:01 CST 2019
 */
@Insert({
    "insert into t_coffee (name, price, ",
    "create_time, update_time)",
    "values (#{name,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT,typeHandler=com.zuozewei.springbootdatabackuprecoverydemo.handler.MoneyTypeHandler}, ",
    "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
})
@SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
int insert(Coffee record);
 
Example #4
Source File: AnnotatedMapper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="call identity()", keyProperty="nameId", before=false, resultType=int.class)
int insertTable2(Name name);
 
Example #5
Source File: MapperAnnotationBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private KeyGenerator handleSelectKeyAnnotation(SelectKey selectKeyAnnotation, String baseStatementId, Class<?> parameterTypeClass, LanguageDriver languageDriver) {
  String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
  Class<?> resultTypeClass = selectKeyAnnotation.resultType();
  StatementType statementType = selectKeyAnnotation.statementType();
  String keyProperty = selectKeyAnnotation.keyProperty();
  String keyColumn = selectKeyAnnotation.keyColumn();
  boolean executeBefore = selectKeyAnnotation.before();

  // defaults
  boolean useCache = false;
  KeyGenerator keyGenerator = new NoKeyGenerator();
  Integer fetchSize = null;
  Integer timeout = null;
  boolean flushCache = false;
  String parameterMap = null;
  String resultMap = null;
  ResultSetType resultSetTypeEnum = null;

  SqlSource sqlSource = buildSqlSourceFromStrings(selectKeyAnnotation.statement(), parameterTypeClass, languageDriver);
  SqlCommandType sqlCommandType = SqlCommandType.SELECT;

  assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum,
      flushCache, useCache, false,
      keyGenerator, keyProperty, keyColumn, null, languageDriver, null);

  id = assistant.applyCurrentNamespace(id, false);

  MappedStatement keyStatement = configuration.getMappedStatement(id, false);
  SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore);
  configuration.addKeyGenerator(id, answer);
  return answer;
}
 
Example #6
Source File: CoffeeMapper.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table T_COFFEE
 *
 * @mbg.generated Sun Dec 08 00:33:16 CST 2019
 */
@Insert({
    "insert into T_COFFEE (NAME, PRICE, ",
    "CREATE_TIME, UPDATE_TIME)",
    "values (#{name,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT,typeHandler=com.zuozewei.springbootdatadrivendemo.handler.MoneyTypeHandler}, ",
    "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
})
@SelectKey(statement="CALL IDENTITY()", keyProperty="id", before=false, resultType=Long.class)
int insert(Coffee record);
 
Example #7
Source File: AnnotatedMapper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Insert("insert into table3 (id, name) values(#{nameId}, #{name})")
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
int insertTable3(Name name);
 
Example #8
Source File: AnnotatedMapper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="select id, name_fred from table2 where id = identity()", keyProperty="nameId,generatedName", keyColumn="ID,NAME_FRED", before=false, resultType=Map.class)
int insertTable2WithSelectKeyWithKeyMap(Name name);
 
Example #9
Source File: AnnotatedMapper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@InsertProvider(type=SqlProvider.class,method="insertTable3_2")
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
int insertTable3_2(Name name);
 
Example #10
Source File: AnnotatedMapper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Update("update table2 set name = #{name} where id = #{nameId}")
@SelectKey(statement="select name_fred from table2 where id = #{nameId}", keyProperty="generatedName", keyColumn="NAME_FRED", before=false, resultType=String.class)
int updateTable2WithSelectKeyWithKeyMap(Name name);
 
Example #11
Source File: AnnotatedMapper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Update("update table2 set name = #{name} where id = #{nameId}")
@SelectKey(statement="select name_fred as generatedName from table2 where id = #{nameId}", keyProperty="generatedName", before=false, resultType=Name.class)
int updateTable2WithSelectKeyWithKeyObject(Name name);
 
Example #12
Source File: AnnotatedMapper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="select id, name_fred from table2 where id = identity()", keyProperty="nameId,generatedName", keyColumn="ID,NAME_FRED", before=false, resultType=Map.class)
int insertTable2WithSelectKeyWithKeyMap(Name name);
 
Example #13
Source File: AnnotatedMapper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="select id as nameId, name_fred as generatedName from table2 where id = identity()", keyProperty="nameId,generatedName", before=false, resultType=Name.class)
int insertTable2WithSelectKeyWithKeyObject(Name name);
 
Example #14
Source File: AnnotatedMapper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Insert("insert into table3 (id, name) values(#{nameId}, #{name})")
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
int insertTable3(Name name);
 
Example #15
Source File: AnnotatedMapper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@InsertProvider(type=SqlProvider.class,method="insertTable3_2")
@SelectKey(statement="call next value for TestSequence", keyProperty="nameId", before=true, resultType=int.class)
int insertTable3_2(Name name);
 
Example #16
Source File: AnnotatedMapper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Update("update table2 set name = #{name} where id = #{nameId}")
@SelectKey(statement="select name_fred from table2 where id = #{nameId}", keyProperty="generatedName", keyColumn="NAME_FRED", before=false, resultType=String.class)
int updateTable2WithSelectKeyWithKeyMap(Name name);
 
Example #17
Source File: AnnotatedMapper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Update("update table2 set name = #{name} where id = #{nameId}")
@SelectKey(statement="select name_fred as generatedName from table2 where id = #{nameId}", keyProperty="generatedName", before=false, resultType=Name.class)
int updateTable2WithSelectKeyWithKeyObject(Name name);
 
Example #18
Source File: AnnotatedMapper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="select id as nameId, name_fred as generatedName from table2 where id = identity()", keyProperty="nameId,generatedName", before=false, resultType=Name.class)
int insertTable2WithSelectKeyWithKeyObject(Name name);
 
Example #19
Source File: CustomerMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@Insert({"INSERT INTO customers (name, description, filesDir, master, prefix, registrationTime) " +
        "VALUES (#{name}, #{description}, #{filesDir}, FALSE, #{prefix}, #{registrationTime})"})
@SelectKey( statement = "SELECT currval('customers_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insert(Customer customer);
 
Example #20
Source File: AnnotatedMapper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Insert("insert into table2 (name) values(#{name})")
@SelectKey(statement="call identity()", keyProperty="nameId", before=false, resultType=int.class)
int insertTable2(Name name);
 
Example #21
Source File: PostgresDeviceLogMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@Insert("INSERT INTO plugin_devicelog_settings (customerId, logsPreservePeriod) " +
        "VALUES (#{customerId}, #{logsPreservePeriod})")
@SelectKey( statement = "SELECT currval('plugin_devicelog_settings_id_seq')",
        keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertPluginSettings(PostgresDeviceLogPluginSettings postgresDeviceLogPluginSettings);
 
Example #22
Source File: NotificationMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@Insert("INSERT INTO pushMessages (messageType, deviceId, payload) " +
        "VALUES (#{messageType}, #{deviceId}, #{payload})")
@SelectKey( statement = "SELECT currval('pushmessages_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertPushMessage(PushMessage message);
 
Example #23
Source File: UploadedFileMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@Insert("INSERT INTO uploadedFiles (customerId, filePath, uploadTime) VALUES (#{customerId}, #{filePath}, EXTRACT(EPOCH FROM NOW()) * 1000)")
@SelectKey(statement = "SELECT currval('uploadedFiles_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class)
int insertFile(UploadedFile file);
 
Example #24
Source File: ConfigurationMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@SelectKey( statement = "SELECT currval('configurations_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertConfiguration(Configuration configuration);
 
Example #25
Source File: IconMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@Insert("INSERT INTO icons (customerId, name, fileId) VALUES (#{customerId}, #{name}, #{fileId})")
@SelectKey(statement = "SELECT currval('icons_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class)
int insertIcon(Icon icon);
 
Example #26
Source File: UserMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@Insert({"INSERT INTO users (login, email, name, password, customerId, userRoleId, allDevicesAvailable) " +
        "VALUES (#{login}, #{email}, #{name}, #{password}, #{customerId}, #{userRole.id}, #{allDevicesAvailable})"})
@SelectKey( statement = "SELECT currval('users_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insert(User user);
 
Example #27
Source File: ApplicationMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@Insert({"INSERT INTO applicationVersions (applicationId, version, url) " +
        "VALUES (#{applicationId}, #{version}, #{url})"})
@SelectKey( statement = "SELECT currval('applicationVersions_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
int insertApplicationVersion(ApplicationVersion version);
 
Example #28
Source File: ApplicationMapper.java    From hmdm-server with Apache License 2.0 4 votes vote down vote up
@Insert({"INSERT INTO applications (name, pkg, showIcon, system, customerId, runAfterInstall, runAtBoot, type, iconText, iconId) " +
        "VALUES (#{name}, #{pkg}, #{showIcon}, #{system}, #{customerId}, #{runAfterInstall}, #{runAtBoot}, #{type}, #{iconText}, #{iconId})"})
@SelectKey( statement = "SELECT currval('applications_id_seq')", keyColumn = "id", keyProperty = "id", before = false, resultType = int.class )
void insertApplication(Application application);
 
Example #29
Source File: ProductMapper.java    From springbootexamples with Apache License 2.0 2 votes vote down vote up
/**
 * 添加商品
 * @param product
 * @return Long 表示影响的行数
 */
@Insert("insert into product (product_Name, price,product_Brief) values(#{productName}, #{price}, #{productBrief})")
@Options(useGeneratedKeys=true,keyProperty="id")
@SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = long.class)
public Long insert(Product product);
 
Example #30
Source File: CommonMapper.java    From uncode-dal-all with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 新增
 * 所有字段传入 model.params,不能为空
 * @param model
 * @return
 */
@InsertProvider(method = "insert", type = SqlTemplate.class)
@SelectKey(before=false,keyProperty="params.id",resultType=Object.class,statementType=StatementType.STATEMENT,statement="SELECT LAST_INSERT_ID() AS id")
int insert(Table model);