From 4f5f815f88e81000510ef2544e3e392fd7465d8e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 9 Oct 2014 13:24:47 +1300 Subject: Integrate c3p0 database library --- src/org/traccar/http/WebServer.java | 48 +++++++------------------------------ 1 file changed, 8 insertions(+), 40 deletions(-) (limited to 'src/org/traccar/http') diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index 2745cd7b8..9a7cb9e4e 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,7 @@ */ package org.traccar.http; -import java.io.File; import java.net.InetSocketAddress; -import java.net.URL; -import java.net.URLClassLoader; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; @@ -34,41 +31,7 @@ public class WebServer { private Server server; - private void initDataSource(Properties properties) { - try { - - Context context = new InitialContext(); - - String dataSourceClass = properties.getProperty("database.dataSource"); - if (dataSourceClass != null) { - - Class clazz; - - String driverFile = properties.getProperty("database.driverFile"); - if (driverFile != null) { - URL url = new URL("jar:file:" + new File(driverFile).getAbsolutePath() + "!/"); - URLClassLoader cl = new URLClassLoader(new URL[] { url }); - clazz = Class.forName(dataSourceClass, true, cl); - } else { - clazz = Class.forName(dataSourceClass); - } - - if (clazz != null) { - DataSource ds = (DataSource) clazz.newInstance(); - clazz.getMethod("setURL", String.class).invoke(ds, properties.getProperty("database.url")); - clazz.getMethod("setUser", String.class).invoke(ds, properties.getProperty("database.user")); - clazz.getMethod("setPassword", String.class).invoke(ds, properties.getProperty("database.password")); - - context.bind("java:/DefaultDS", ds); - } - } - - } catch (Exception error) { - Log.warning(error); - } - } - - public WebServer(Properties properties) { + public WebServer(Properties properties, DataSource dataSource) { String address = properties.getProperty("http.address"); Integer port = Integer.valueOf(properties.getProperty("http.port", "8082")); if (address == null) { @@ -77,7 +40,12 @@ public class WebServer { server = new Server(new InetSocketAddress(address, port)); } - initDataSource(properties); + try { + Context context = new InitialContext(); + context.bind("java:/DefaultDS", dataSource); + } catch (Exception error) { + Log.warning(error); + } WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); -- cgit v1.2.3