|
ActiveMQ example source code file (DataSourceSupport.java)
The ActiveMQ DataSourceSupport.java source code/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.activemq.store.jdbc; import java.io.File; import java.io.IOException; import javax.sql.DataSource; import org.apache.activemq.util.IOHelper; import org.apache.derby.jdbc.EmbeddedDataSource; /** * A helper class which provides a factory method to create a default * {@link DataSource) if one is not provided. * * */ public class DataSourceSupport { private String dataDirectory = IOHelper.getDefaultDataDirectory(); private File dataDirectoryFile; private DataSource dataSource; public DataSourceSupport() { } public DataSourceSupport(DataSource dataSource) { this.dataSource = dataSource; } public File getDataDirectoryFile() { if (dataDirectoryFile == null) { dataDirectoryFile = new File(getDataDirectory()); } return dataDirectoryFile; } public void setDataDirectoryFile(File dataDirectory) { this.dataDirectoryFile = dataDirectory; } public String getDataDirectory() { return dataDirectory; } public void setDataDirectory(String dataDirectory) { this.dataDirectory = dataDirectory; } public DataSource getDataSource() throws IOException { if (dataSource == null) { dataSource = createDataSource(); if (dataSource == null) { throw new IllegalArgumentException("No dataSource property has been configured"); } } return dataSource; } public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } protected DataSource createDataSource() throws IOException { // Setup the Derby datasource. System.setProperty("derby.system.home", getDataDirectoryFile().getCanonicalPath()); System.setProperty("derby.storage.fileSyncTransactionLog", "true"); System.setProperty("derby.storage.pageCacheSize", "100"); final EmbeddedDataSource ds = new EmbeddedDataSource(); ds.setDatabaseName("derbydb"); ds.setCreateDatabase("create"); return ds; } public String toString() { return "" + dataSource; } } Other ActiveMQ examples (source code examples)Here is a short list of links related to this ActiveMQ DataSourceSupport.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.