com.webproject.checkpoint.HSQLDBDataSource.java Source code

Java tutorial

Introduction

Here is the source code for com.webproject.checkpoint.HSQLDBDataSource.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webproject.checkpoint;

import javax.annotation.PostConstruct;
import org.apache.commons.dbcp2.BasicDataSource;
import org.hsqldb.jdbc.JDBCDriver;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
 *
 * @author qiuyue
 */
@Component
@Profile("prd")
public class HSQLDBDataSource extends BasicDataSource implements DisposableBean {

    @PostConstruct
    public void postConstruct() throws Exception {
        this.setDriver(new JDBCDriver());
        this.setInitialSize(500);
        this.setUrl("jdbc:hsqldb:file:checkpoint;crypt_key=6f19d357b37298d42969f8da0ef01ea8;crypt_type=AES");
        this.setUsername("SA");
        this.setPassword("");
    }

    @Override
    public void destroy() throws Exception {
        close();
    }

    @Component
    @Profile("dev")
    static class DataSourceDev extends HSQLDBDataSource {
        @PostConstruct
        @Override
        public void postConstruct() {
            this.setDriver(new JDBCDriver());
            this.setInitialSize(100);
            this.setUrl("jdbc:hsqldb:mem:checkpoint");
            this.setUsername("SA");
            this.setPassword("");
        }

    }
}