<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rdbms-table-configuration>
    <database name="h2">
        <createTableQuery>CREATE TABLE {{TABLE_NAME}} (id INT NOT NULL AUTO_INCREMENT, siddhiAppName VARCHAR(100), revision VARCHAR(100), snapshot BLOB, PRIMARY KEY (id))</createTableQuery>
        <insertTableQuery>INSERT INTO {{TABLE_NAME}} (siddhiAppName, revision, snapshot) VALUES (?, ?, ?)</insertTableQuery>
        <isTableExistQuery>SELECT * FROM {{TABLE_NAME}} limit 1</isTableExistQuery>
        <selectTableQuery>SELECT snapshot FROM {{TABLE_NAME}} WHERE  revision = ? AND siddhiAppName = ? </selectTableQuery>
        <selectLastQuery>SELECT revision FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY id DESC LIMIT 1</selectLastQuery>
        <deleteQuery>DELETE FROM {{TABLE_NAME}} WHERE id IN (SELECT id FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY id ASC LIMIT ?)</deleteQuery>
        <countQuery>SELECT COUNT(*) FROM {{TABLE_NAME}} WHERE siddhiAppName = ?</countQuery>
    </database>
    <database name="mysql">
        <createTableQuery>CREATE TABLE {{TABLE_NAME}} (id INT NOT NULL AUTO_INCREMENT, siddhiAppName VARCHAR(100), revision VARCHAR(100), snapshot BLOB, PRIMARY KEY (id))</createTableQuery>
        <insertTableQuery>INSERT INTO {{TABLE_NAME}} (siddhiAppName, revision, snapshot) VALUES (?, ?, ?)</insertTableQuery>
        <isTableExistQuery>SELECT * FROM {{TABLE_NAME}} limit 1</isTableExistQuery>
        <selectTableQuery>SELECT snapshot FROM {{TABLE_NAME}} WHERE  revision = ? AND siddhiAppName = ? </selectTableQuery>
        <selectLastQuery>SELECT revision FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY id DESC LIMIT 1</selectLastQuery>
        <deleteQuery>DELETE FROM {{TABLE_NAME}} WHERE siddhiAppName = ? IS NOT NULL ORDER BY id ASC LIMIT ?</deleteQuery>
        <countQuery>SELECT COUNT(*) FROM {{TABLE_NAME}} WHERE siddhiAppName = ?</countQuery>
    </database>
    <database name="postgresql">
        <createTableQuery>CREATE TABLE {{TABLE_NAME}} (id serial primary key, siddhiAppName VARCHAR(100), revision VARCHAR(100), snapshot bigint)</createTableQuery>
        <insertTableQuery>INSERT INTO {{TABLE_NAME}} (siddhiAppName, revision, snapshot) VALUES (?, ?, ?)</insertTableQuery>
        <isTableExistQuery>SELECT 1 FROM {{TABLE_NAME}} LIMIT 1</isTableExistQuery>
        <selectTableQuery>SELECT snapshot FROM {{TABLE_NAME}} WHERE  revision = ? AND siddhiAppName = ? </selectTableQuery>
        <selectLastQuery>SELECT revision FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY id DESC LIMIT 1</selectLastQuery>
        <deleteQuery>DELETE FROM {{TABLE_NAME}} WHERE id IN (SELECT id FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY id ASC LIMIT ?)</deleteQuery>
        <countQuery>SELECT COUNT(*) FROM {{TABLE_NAME}} WHERE siddhiAppName = ?</countQuery>
    </database>
    <database name="microsoft sql server">
        <createTableQuery>CREATE TABLE {{TABLE_NAME}} (id INT NOT NULL IDENTITY(1,1) PRIMARY KEY, siddhiAppName VARCHAR(100), revision VARCHAR(100), snapshot VARBINARY(8000))</createTableQuery>
        <insertTableQuery>INSERT INTO {{TABLE_NAME}} (siddhiAppName, revision, snapshot) VALUES (?, ?, ?)</insertTableQuery>
        <isTableExistQuery>SELECT TOP 1 1 FROM {{TABLE_NAME}}</isTableExistQuery>
        <selectTableQuery>SELECT snapshot FROM {{TABLE_NAME}} WHERE  revision = ? AND siddhiAppName = ? </selectTableQuery>
        <selectLastQuery>SELECT TOP 1 revision FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY id DESC</selectLastQuery>
        <deleteQuery>DELETE FROM {{TABLE_NAME}} WHERE id IN (SELECT TOP (?) id FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY id ASC)</deleteQuery>
        <countQuery>SELECT COUNT(*) FROM {{TABLE_NAME}} WHERE siddhiAppName = ?</countQuery>
    </database>
    <database name="oracle">
        <createTableQuery>CREATE TABLE {{TABLE_NAME}} (siddhiAppName VARCHAR2(100) NOT NULL, revision VARCHAR2(100), snapshot BLOB)</createTableQuery>
        <insertTableQuery>INSERT INTO {{TABLE_NAME}} (siddhiAppName, revision, snapshot) VALUES (?, ?, ?)</insertTableQuery>
        <isTableExistQuery>SELECT 1 FROM {{TABLE_NAME}} WHERE rownum=1</isTableExistQuery>
        <selectTableQuery>SELECT snapshot FROM {{TABLE_NAME}} WHERE  revision = ? AND siddhiAppName = ? </selectTableQuery>
        <selectLastQuery>SELECT revision FROM (SELECT revision FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY revision DESC) WHERE rownum=1</selectLastQuery>
        <deleteQuery>DELETE {{TABLE_NAME}} WHERE revision in (SELECT revision from (SELECT * FROM {{TABLE_NAME}} WHERE siddhiAppName = ? ORDER BY revision ASC) WHERE rownum&#60;=?)</deleteQuery>
        <countQuery>SELECT COUNT(*) FROM {{TABLE_NAME}} WHERE siddhiAppName = ?</countQuery>
    </database>
</rdbms-table-configuration>