浏览代码

Issue #814 - Fix the lookup of the Resin DataSource

Use custom data source that claims to be much faster than the competitors.
Upgrade Wicket to latest stable (6.16)
Martin Tzvetanov Grigorov 11 年之前
父节点
当前提交
190e051c77

+ 6 - 11
wicket/pom.xml

@@ -21,9 +21,8 @@
 	</licenses>
 	</licenses>
 	<properties>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-		<wicket.version>6.15.0</wicket.version>
+		<wicket.version>6.16.0</wicket.version>
 		<jetty.version>8.1.14.v20131031</jetty.version>
 		<jetty.version>8.1.14.v20131031</jetty.version>
-		<bonecp.version>0.8.0.RELEASE</bonecp.version>
 		<slf4j.version>1.7.7</slf4j.version>
 		<slf4j.version>1.7.7</slf4j.version>
 	</properties>
 	</properties>
 	<dependencies>
 	<dependencies>
@@ -34,16 +33,12 @@
 			<version>${wicket.version}</version>
 			<version>${wicket.version}</version>
 		</dependency>
 		</dependency>
 
 
+		<!-- a faster DataSource -->
 		<dependency>
 		<dependency>
-			<groupId>com.jolbox</groupId>
-			<artifactId>bonecp</artifactId>
-			<version>${bonecp.version}</version>
-		</dependency>
-
-		<dependency>
-			<groupId>com.google.guava</groupId>
-			<artifactId>guava</artifactId>
-			<version>17.0</version>
+			<groupId>com.zaxxer</groupId>
+			<artifactId>HikariCP</artifactId>
+			<version>1.4.0</version>
+			<scope>compile</scope>
 		</dependency>
 		</dependency>
 
 
 		<!-- LOGGING DEPENDENCIES - LOG4J -->
 		<!-- LOGGING DEPENDENCIES - LOG4J -->

+ 26 - 37
wicket/src/main/java/hellowicket/WicketApplication.java

@@ -1,14 +1,12 @@
 package hellowicket;
 package hellowicket;
 
 
-import java.io.IOException;
-import java.util.Properties;
-
+import javax.naming.InitialContext;
 import javax.sql.DataSource;
 import javax.sql.DataSource;
 
 
 import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.settings.IRequestCycleSettings;
 import org.apache.wicket.settings.IRequestCycleSettings;
 
 
-import com.jolbox.bonecp.BoneCPDataSource;
+import com.zaxxer.hikari.HikariDataSource;
 
 
 import hellowicket.dbupdates.HelloDbUpdatesReference;
 import hellowicket.dbupdates.HelloDbUpdatesReference;
 import hellowicket.fortune.FortunePage;
 import hellowicket.fortune.FortunePage;
@@ -19,7 +17,7 @@ import hellowicket.plaintext.HelloTextReference;
  */
  */
 public class WicketApplication extends WebApplication
 public class WicketApplication extends WebApplication
 {
 {
-	private BoneCPDataSource db;
+	private DataSource db;
 
 
 	@Override
 	@Override
 	public Class<HomePage> getHomePage()
 	public Class<HomePage> getHomePage()
@@ -54,15 +52,16 @@ public class WicketApplication extends WebApplication
 	@Override
 	@Override
 	protected void onDestroy()
 	protected void onDestroy()
 	{
 	{
-		db.close();
+		if (db instanceof HikariDataSource) {
+			((HikariDataSource)db).close();
+		}
 		super.onDestroy();
 		super.onDestroy();
 	}
 	}
 
 
-//	@Override
-//	public RuntimeConfigurationType getConfigurationType()
-//	{
-//		return RuntimeConfigurationType.DEVELOPMENT;
-//	}
+	private boolean useResinDataSource()
+	{
+		return false;
+	}
 
 
 	public static WicketApplication get()
 	public static WicketApplication get()
 	{
 	{
@@ -74,43 +73,33 @@ public class WicketApplication extends WebApplication
 		return db;
 		return db;
 	}
 	}
 
 
-	private BoneCPDataSource newDataSource()
+	private DataSource newDataSource()
 	{
 	{
+		DataSource dataSource;
 		try
 		try
 		{
 		{
 			Class.forName("com.mysql.jdbc.Driver");
 			Class.forName("com.mysql.jdbc.Driver");
-		} catch (ClassNotFoundException e)
-		{
-			throw new RuntimeException("Cannot load MySQL JDBC driver", e);
-		}
-		BoneCPDataSource ds = new BoneCPDataSource();
-		Properties settings = loadSettings();
-		ds.setJdbcUrl(settings.getProperty("mysql.uri"));
-		ds.setUsername(settings.getProperty("mysql.user"));
-		ds.setPassword(settings.getProperty("mysql.password"));
 
 
-		return ds;
-	}
-
-	private Properties loadSettings()
-	{
-		ClassLoader classLoader = WicketApplication.class.getClassLoader();
-		Properties settings = new Properties();
-
-		try
-		{
-			if (usesDeploymentConfig())
+			if (useResinDataSource())
 			{
 			{
-				settings.load(classLoader.getResourceAsStream("prod.properties"));
+				InitialContext jndiContext = new InitialContext();
+				dataSource = (DataSource) jndiContext.lookup("java:comp/env/jdbc/hello_world");
 			}
 			}
 			else
 			else
 			{
 			{
-				settings.load(classLoader.getResourceAsStream("dev.properties"));
+				// use faster DataSource impl
+				HikariDataSource ds = new HikariDataSource();
+				ds.setJdbcUrl("jdbc:mysql://localhost:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true");
+				ds.setDriverClassName("com.mysql.jdbc.Driver");
+				ds.setUsername("benchmarkdbuser");
+				ds.setPassword("benchmarkdbpass");
+				dataSource = ds;
 			}
 			}
-		} catch (IOException e)
+		} catch (Exception x)
 		{
 		{
-			throw new RuntimeException("Cannot load the settings!", e);
+			throw new RuntimeException("Cannot create the data source", x);
 		}
 		}
-		return settings;
+
+		return dataSource;
 	}
 	}
 }
 }

+ 0 - 3
wicket/src/main/resources/dev.properties

@@ -1,3 +0,0 @@
-mysql.uri = jdbc:mysql://localhost:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true
-mysql.user = benchmarkdbuser
-mysql.password = benchmarkdbpass

+ 0 - 3
wicket/src/main/resources/prod.properties

@@ -1,3 +0,0 @@
-mysql.uri = java:comp/env/jdbc/hello_world
-mysql.user = benchmarkdbuser
-mysql.password = benchmarkdbpass

+ 1 - 0
wicket/src/main/webapp/WEB-INF/web.xml

@@ -33,4 +33,5 @@
 		<filter-name>wicket.hellowicket</filter-name>
 		<filter-name>wicket.hellowicket</filter-name>
 		<url-pattern>/*</url-pattern>
 		<url-pattern>/*</url-pattern>
 	</filter-mapping>
 	</filter-mapping>
+
 </web-app>
 </web-app>