KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > server > database > HSQLDBLayer


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.server.database;
20
21 import java.sql.*;
22
23 import javax.sql.DataSource JavaDoc;
24
25 import org.apache.commons.dbcp.BasicDataSource;
26 import org.lucane.common.Logging;
27 import org.lucane.server.Server;
28
29 class HSQLDBLayer extends DatabaseAbstractionLayer
30 {
31   private DataSource JavaDoc dataSource;
32   
33   public HSQLDBLayer(DataSource JavaDoc dataSource)
34   {
35     this.dataSource = dataSource;
36     BasicDataSource bds = (BasicDataSource)dataSource;
37     bds.setUrl(getAbsoluteUrl(bds.getUrl()));
38   }
39   
40   public Connection getConnection()
41   throws SQLException
42   {
43     return dataSource.getConnection();
44   }
45
46   private String JavaDoc getAbsoluteUrl(String JavaDoc url)
47   {
48     String JavaDoc standardStart = "jdbc:hsqldb:";
49
50     if(Server.getInstance() != null && url.toLowerCase().startsWith(standardStart))
51     {
52         String JavaDoc miniurl = url.substring(standardStart.length()).replace('\\','/');
53         
54         if(! miniurl.startsWith("/") && miniurl.charAt(1)!=':')
55             url = standardStart + Server.getInstance().getWorkingDirectory() + miniurl;
56     }
57     
58     Logging.getLogger().fine("HSQLdb url : " + url);
59     
60     return url;
61   }
62   
63   public String JavaDoc resolveType(String JavaDoc type)
64   {
65     if(type.equalsIgnoreCase("SMALLTEXT"))
66       return "VARCHAR(250)";
67     else if(type.equalsIgnoreCase("TEXT"))
68       return "VARCHAR";
69     else if(type.equalsIgnoreCase("SMALLINT"))
70       return "SMALLINT";
71     else if(type.equalsIgnoreCase("INT"))
72       return "INT";
73     else if(type.equalsIgnoreCase("BIGINT"))
74       return "NUMERIC";
75     else if(type.equalsIgnoreCase("REAL"))
76       return "REAL";
77     else
78       return type;
79   }
80 }
81
82
Popular Tags