All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.jinghui70.rainbow.dbaccess.memory.MemoryDba Maven / Gradle / Ivy

There is a newer version: 5.2.1
Show newest version
package io.github.jinghui70.rainbow.dbaccess.memory;

import cn.hutool.core.exceptions.ExceptionUtil;
import io.github.jinghui70.rainbow.dbaccess.Dba;

import java.io.Closeable;
import java.sql.SQLException;

/**
 * 内存表
 *
 * @author lijinghui
 */
public class MemoryDba extends Dba implements Closeable {

    private final MemoryConnection conn;

    public MemoryDba() {
        try {
            conn = new MemoryConnection();
        } catch (SQLException e) {
            throw ExceptionUtil.wrapRuntime(e);
        }
        MemoryDataSource ds = new MemoryDataSource(conn);
        initDataSource(ds, null);
    }

    @Override
    public void close() {
        try {
            this.conn.getRaw().close();
        } catch (SQLException e) {
            throw ExceptionUtil.wrapRuntime(e);
        }
    }

    /**
     * 创建一个内存表
     *
     * @param table 表对象
     */
    public void createTable(Table table) {
        getJdbcTemplate().update(table.ddl());
    }

    /**
     * 创建缺省名字为X的内存表
     *
     * @param fields 字段列表
     */
    public void createTable(Field... fields) {
        Table table = Table.create(Table.DEFAULT).add(fields);
        createTable(table);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy