Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeEmacs
titleDocumentVersion.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="DocumentVersion">
	<resultMap id="documentVersion" class="(DocumentVersionModel path)">
		<result property="id" column="id" columnIndex="1"/>
		<result property="userId" column="user_id" columnIndex="2"/>
		<result property="domainId" column="domain_id" columnIndex="3"/>
		<result property="docId" column="doc_id" columnIndex="4"/>
		<result property="json" column="json" columnIndex="5"/>
		<result property="createdAt" column="created_at" columnIndex="6"/>
	</resultMap>
	<resultMap id="documentVersionList" class="(DocumentVersionModel path)">
		<result property="id" column="id" columnIndex="1"/>
		<result property="userId" column="user_id" columnIndex="2"/>
		<result property="domainId" column="domain_id" columnIndex="3"/>
		<result property="docId" column="doc_id" columnIndex="4"/>
		<result property="createdAt" column="created_at" columnIndex="5"/>
	</resultMap>

	<insert id="insert">
		INSERT INTO
			document_version(user_id, domain_id, doc_id, json, created_at)
		VALUES
			(#userId#, #domainId#, #docId# , #json#, SYSDATE())
	</insert>
	
    <delete id="remove">
		DELETE FROM document_version
		WHERE id = #id#
	</delete>

	<select id="getDocumentVersionById" resultMap="documentVersion">
		SELECT id, user_id, domain_id, doc_id, json, created_at
		FROM document_version
		WHERE
			id = #id#
	</select>

	<select id="getDocumentVersionByDocId" resultClass="java.util.List" resultMap="documentVersionList">
		SELECT id, user_id, domain_id, doc_id, created_at
		FROM document_version
		WHERE
			doc_id = #docId#
		ORDER BY id DESC
		LIMIT 500
	</select>
</sqlMap>


Code Block
languagejava
themeEmacs
titledocument_version DDL
CREATE TABLE `document_version` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `domain_id` int(11) NOT NULL DEFAULT 1,
  `doc_id` bigint(20) NOT NULL,
  `json` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=671 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;