It show you that the sequence table can manage all tables.
// These are Schema Desgins
CREATE TABLE zz_app
(
id BIGINT UNSIGNED NOT NULL DEFAULT '0',
app_id VARCHAR(45) NOT NULL,
app_aaa VARCHAR(45) NULL,
app_bbb VARCHAR(45) NULL,
app_status_flag CHAR(1) NULL,
insert_time TIMESTAMP NOT NULL,
update_time TIMESTAMP NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE INDEX zz_app_idx1 ON zz_app(app_id);
CREATE INDEX zz_app_idx2 ON zz_app(insert_time);
CREATE TABLE zz_sequence
(
seq_name VARCHAR(30) NOT NULL,
id BIGINT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (seq_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
----------------------------------------------------------------------
// Update sequence number into the Mysql
<insert id="updateSequece" parameterType="map">
UPDATE
zz_sequence
SET
id=LAST_INSERT_ID(id+1)
WHERE
seq_name = #{seqName}
<selectKey resultType="Long" order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>
</insert>
// Insert a data into the Mysql
<insert id="insertApp" parameterType="map">
<selectKey keyProperty="id" resultType="Long" order="BEFORE">
SELECT
id
FROM
zz_sequence
WHERE
seq_name = #{seqName};
</selectKey>
INSERT INTO zz_app (
id,
app_id,
app_aaa,
app_bbb,
app_status_flag,
insert_time,
update_time
) VALUES (
#{id},
#{appId},
#{appAaa},
#{appBbb},
#{appStatusFlag},
now(),
now()
)
</insert>
Hi, I'm an architecture engineer and native Korean speaker.
I have started to live in Seoul in Korea.
I have been developping Abilists tool,
Please feel free to visit abilists.com
Showing posts with label Mybatis. Show all posts
Showing posts with label Mybatis. Show all posts
Friday, September 13, 2013
Monday, July 8, 2013
Spring - Spring3 connect to Mybatis on spring-mybatis.
// A part of ServiceImpl.javaList<HadoopGameModel> hadoopGameList = slaveAdminDao.getMapper(SlaveDao.class).selectGameList(mapSelectGameList);
Subscribe to:
Posts (Atom)