KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > database > impl > InMemoryDatabaseServiceImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.database.impl;
6
7 import javax.sql.DataSource JavaDoc;
8 import java.util.* ;
9 import org.exoplatform.services.database.DatabaseService;
10 import org.picocontainer.Startable;
11
12 /**
13  * Created by The eXo Platform SARL . Author : Tuan Nguyen
14  * tuan08@users.sourceforge.net Date: Jun 14, 2003 Time: 1:12:22 PM
15  */

16 public class InMemoryDatabaseServiceImpl implements DatabaseService, Startable {
17   
18   private DataSource JavaDoc defaultDS_;
19   private Map datasources_ ;
20
21   public InMemoryDatabaseServiceImpl() throws Exception JavaDoc {
22     datasources_ = new HashMap() ;
23     defaultDS_ = createDataSource(DatabaseService.EXO_DATASOURCE_NAME) ;
24     datasources_.put(DatabaseService.EXO_DATASOURCE_NAME, defaultDS_) ;
25   }
26
27   public DataSource JavaDoc getDefaultDataSource() { return defaultDS_; }
28
29   public DataSource JavaDoc getDataSource(String JavaDoc name) {
30     DataSource JavaDoc ds = (DataSource JavaDoc) datasources_.get(name) ;
31     if(ds == null) {
32       ds = createDataSource(name) ;
33       datasources_.put(name, ds) ;
34     }
35     return ds ;
36   }
37
38   public String JavaDoc getDatabaseType(String JavaDoc dsName) { return DatabaseService.HSQL ; }
39   public String JavaDoc getDatabaseType(DataSource JavaDoc ds) { return DatabaseService.HSQL ; }
40   
41   private DataSource JavaDoc createDataSource(String JavaDoc name) {
42     org.hsqldb.jdbc.jdbcDataSource ds = new org.hsqldb.jdbc.jdbcDataSource() ;
43     ds.setDatabase("jdbc:hsqldb:mem:" + name) ;
44     ds.setUser("sa") ;
45     ds.setPassword("") ;
46     return ds ;
47   }
48   
49   public void start() { }
50   public void stop() { }
51 }
Popular Tags