1 5 package org.exoplatform.services.database.impl; 6 7 import javax.sql.DataSource ; 8 import java.util.* ; 9 import org.exoplatform.services.database.DatabaseService; 10 import org.picocontainer.Startable; 11 12 16 public class InMemoryDatabaseServiceImpl implements DatabaseService, Startable { 17 18 private DataSource defaultDS_; 19 private Map datasources_ ; 20 21 public InMemoryDatabaseServiceImpl() throws Exception { 22 datasources_ = new HashMap() ; 23 defaultDS_ = createDataSource(DatabaseService.EXO_DATASOURCE_NAME) ; 24 datasources_.put(DatabaseService.EXO_DATASOURCE_NAME, defaultDS_) ; 25 } 26 27 public DataSource getDefaultDataSource() { return defaultDS_; } 28 29 public DataSource getDataSource(String name) { 30 DataSource ds = (DataSource ) 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 getDatabaseType(String dsName) { return DatabaseService.HSQL ; } 39 public String getDatabaseType(DataSource ds) { return DatabaseService.HSQL ; } 40 41 private DataSource createDataSource(String 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 |