Inspector | Message | Severity | Location |
---|---|---|---|
Java Inspector 048 | Copyrights information should be present in each file. | 1 | |
Java Inspector 049 | Use a Collection instead of arrays Object[] | 2 | 84:53 |
Java Inspector 089 | Constructor is not properly documented | 2 | 52:9 |
Java Inspector 089 | Undocumented parameter scriptReader | 2 | 52:9 |
Java Inspector 089 | Javadoc contains tag for non-existent parameter initScript | 2 | 52:9 |
Java Inspector 089 | Constructor is not properly documented | 2 | 64:9 |
Java Inspector 089 | Undocumented method | 2 | 82:41 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 53:23 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 53:54 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 53:54 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 53:60 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 53:60 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 65:23 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 65:54 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 65:54 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 65:60 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 65:60 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 68:47 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 74:50 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 75:59 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 76:33 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 76:72 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 77:33 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 92:82 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 94:47 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 96:39 |
1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.sql.hsqldb;
24
25import java.io.File;
26import java.io.IOException;
27import java.io.InputStream;
28import java.io.InputStreamReader;
29import java.io.Reader;
30import java.sql.SQLException;
31import java.text.SimpleDateFormat;
32import java.util.Date;
33
34
35/**
36 * Hypersonic temporary data source. It is similar to standalone datasource, but
37 * data files are created in system temporary directory and are scheduled to deletion
38 * on JVM exit. Use this datasource if you need to keep large amount of temporary data,
39 * for example data pumping applications can benefit from such data source.
40 * @author Pavel Vlasov
41 * @version $Revision: 1.6 $
42 */
43public class HsqldbTmpDataSource extends HsqldbDataSource {
44
45 /**
46 * @param initScript Fully qualified name of database initialization script to be loaded by
47 * classloader. Can be null.
48 * @throws ClassNotFoundException
49 * @throws IOException
50 * @throws SQLException
51 */
52 public HsqldbTmpDataSource(Reader scriptReader) throws ClassNotFoundException, IOException, SQLException {
53 super("jdbc:hsqldb:"+createTmpDir(), "sa", "", null);
54 initDB(scriptReader, null);
55 }
56
57 /**
58 * @param initScript Fully qualified name of database initialization script to be loaded by
59 * classloader. Can be null.
60 * @throws ClassNotFoundException
61 * @throws IOException
62 * @throws SQLException
63 */
64 public HsqldbTmpDataSource(String initScript) throws ClassNotFoundException, IOException, SQLException {
65 super("jdbc:hsqldb:"+createTmpDir(), "sa", "", null);
66 InputStream in = getClass().getClassLoader().getResourceAsStream(initScript);
67 if (in==null) {
68 throw new IOException("Resource not found: "+initScript);
69 }
70 initDB(new InputStreamReader(in), null);
71 }
72
73 private static String createTmpDir() throws IOException {
74 String tmpDir=System.getProperty("java.io.tmpdir");
75 SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
76 String prefix = "HypersonicDB_"+sdf.format(new Date())+"_";
77 String suffix = "_TMP";
78 final File tmpDbDir = tmpDir==null ? File.createTempFile(prefix, suffix) : File.createTempFile(prefix, suffix, new File(tmpDir));
79 if (tmpDbDir.delete()) {
80 if (tmpDbDir.mkdirs()) {
81 Runtime.getRuntime().addShutdownHook( new Thread() {
82 public void run() {
83
84 File[] dbFiles=tmpDbDir.listFiles();
85 for (int i=0; i<dbFiles.length; i++) {
86 dbFiles[i].deleteOnExit();
87 }
88
89 tmpDbDir.deleteOnExit();
90 }
91 });
92 return tmpDbDir.getAbsolutePath()+File.separator+"HypersonicTmpDB";
93 }
94 throw new IOException("Cannot create directory "+tmpDbDir.getAbsolutePath());
95 }
96 throw new IOException("Cannot delete file "+tmpDbDir.getAbsolutePath());
97 }
98}
99