From: <ma...@rh...> - 2009-01-28 20:29:31
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [2807] [RHQ-1390] need to clean the db type factory's internal cache if the jdbc url is ever changed (this could have been very insidious - good thing I found it :) also had to add some additional version checking in the factory to build the proper db type</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>2807</dd> <dt>Author</dt> <dd>mazz</dd> <dt>Date</dt> <dd>2009-01-28 14:29:28 -0600 (Wed, 28 Jan 2009)</dd> </dl> <h3>Log Message</h3> <pre>[RHQ-1390] need to clean the db type factory's internal cache if the jdbc url is ever changed (this could have been very insidious - good thing I found it :) also had to add some additional version checking in the factory to build the proper db type</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulescoredbutilssrcmainjavaorgrhqcoredbDatabaseTypeFactoryjava">rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/DatabaseTypeFactory.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseguiinstallerwarsrcmainjavaorgrhqenterpriseinstallerConfigurationBeanjava">rhq/trunk/modules/enterprise/gui/installer-war/src/main/java/org/rhq/enterprise/installer/ConfigurationBean.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseguiinstallerwarsrcmainjavaorgrhqenterpriseinstallerServerInformationjava">rhq/trunk/modules/enterprise/gui/installer-war/src/main/java/org/rhq/enterprise/installer/ServerInformation.java</a></li> </ul> <h3>Added Paths</h3> <ul> <li><a href="#rhqtrunkmodulescoredbutilssrcmainjavaorgrhqcoredbPostgresql81DatabaseTypejava">rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql81DatabaseType.java</a></li> <li><a href="#rhqtrunkmodulescoredbutilssrcmainjavaorgrhqcoredbPostgresql82DatabaseTypejava">rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql82DatabaseType.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulescoredbutilssrcmainjavaorgrhqcoredbDatabaseTypeFactoryjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/DatabaseTypeFactory.java (2806 => 2807)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/DatabaseTypeFactory.java 2009-01-28 20:15:10 UTC (rev 2806) +++ rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/DatabaseTypeFactory.java 2009-01-28 20:29:28 UTC (rev 2807) </span><span class="lines">@@ -22,8 +22,10 @@ </span><span class="cx"> import java.sql.DatabaseMetaData; import java.util.Hashtable; import java.util.Map; </span><span class="add">+ </span><span class="cx"> import javax.naming.Context; import javax.sql.DataSource; </span><span class="add">+ </span><span class="cx"> import mazz.i18n.Logger; /** </span><span class="lines">@@ -36,7 +38,7 @@ </span><span class="cx"> /** * Maps the database type that is associated with a particular connection type. */ </span><span class="rem">- public static final Map<String, Class<? extends DatabaseType>> DATABASE_TYPES = new Hashtable<String, Class<? extends DatabaseType>>(); </span><span class="add">+ private static final Map<String, Class<? extends DatabaseType>> DATABASE_TYPES = new Hashtable<String, Class<? extends DatabaseType>>(); </span><span class="cx"> /** * This provides a map that keys JDBC URL protocols with their corresponding <code>java.sql.Driver</code> classes. </span><span class="lines">@@ -58,6 +60,19 @@ </span><span class="cx"> } /** </span><span class="add">+ * By default, this factory will remember what {@link DatabaseType} is associated with + * a specific connection class type. However, if you change the JDBC URL, its possible + * that this will also change the database type the connection class type should be + * associated with (i.e. the URL may point to a different version of the same vendor's + * database). If you change the JDBC URL, you should call this method to clear the + * cache, thus enabling the factory to re-check the connection metadata to associate + * a new database type with the connection class type. + */ + public static void clearDatabaseTypeCache() { + DATABASE_TYPES.clear(); + } + + /** </span><span class="cx"> * Convenience method that gives you the {@link DatabaseType} given a context and datasource. This is a combination * of {@link #getDatabaseType(Context, String)} and {@link #getDatabaseType(Connection)}. * </span><span class="lines">@@ -125,6 +140,10 @@ </span><span class="cx"> database_type_class = Postgresql7DatabaseType.class; } else if (db_version.startsWith("8.3")) { database_type_class = Postgresql83DatabaseType.class; </span><span class="add">+ } else if (db_version.startsWith("8.2")) { + database_type_class = Postgresql82DatabaseType.class; + } else if (db_version.startsWith("8.1")) { + database_type_class = Postgresql81DatabaseType.class; </span><span class="cx"> } else if (db_version.startsWith("8.")) { database_type_class = Postgresql8DatabaseType.class; } </span></pre></div> <a id="rhqtrunkmodulescoredbutilssrcmainjavaorgrhqcoredbPostgresql81DatabaseTypejava"></a> <div class="addfile"><h4>Added: rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql81DatabaseType.java (0 => 2807)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql81DatabaseType.java (rev 0) +++ rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql81DatabaseType.java 2009-01-28 20:29:28 UTC (rev 2807) </span><span class="lines">@@ -0,0 +1,40 @@ </span><span class="add">+/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.core.db; + +/** + * Postgres 8.1 database which extends the Postgres 8.x database. + */ +public class Postgresql81DatabaseType extends Postgresql8DatabaseType { + /** + * @see DatabaseType#getName() + */ + @Override + public String getName() { + return PostgresqlDatabaseType.VENDOR_NAME + "8.1"; + } + + /** + * @see DatabaseType#getVersion() + */ + @Override + public String getVersion() { + return "8.1"; + } +} </span><span class="cx">\ No newline at end of file Property changes on: rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql81DatabaseType.java ___________________________________________________________________ </span></pre></div> <a id="svnmimetype"></a> <div class="addfile"><h4>Added: svn:mime-type ( => )</h4> <pre class="diff"> <span class="info">Added: svn:keywords + Date Author Id Revision HeadURL </span></pre></div> <a id="svneolstyle"></a> <div class="addfile"><h4>Added: svn:eol-style ( => )</h4> <pre class="diff"> <span class="info"> Added: rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql82DatabaseType.java </span><span class="cx">=================================================================== </span><span class="rem">--- rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql82DatabaseType.java (rev 0) </span><span class="add">+++ rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql82DatabaseType.java 2009-01-28 20:29:28 UTC (rev 2807) </span><span class="lines">@@ -0,0 +1,40 @@ </span><span class="add">+/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.core.db; + +/** + * Postgres 8.2 database which extends the Postgres 8.x database. + */ +public class Postgresql82DatabaseType extends Postgresql8DatabaseType { + /** + * @see DatabaseType#getName() + */ + @Override + public String getName() { + return PostgresqlDatabaseType.VENDOR_NAME + "8.2"; + } + + /** + * @see DatabaseType#getVersion() + */ + @Override + public String getVersion() { + return "8.2"; + } +} </span><span class="cx">\ No newline at end of file </span></pre></div> <a id="rhqtrunkmodulescoredbutilssrcmainjavaorgrhqcoredbPostgresql82DatabaseTypejava"></a> <div class="propset"><h4>Property changes: rhq/trunk/modules/core/dbutils/src/main/java/org/rhq/core/db/Postgresql82DatabaseType.java</h4> <pre class="diff"> </pre></div> <a id="svnmimetype"></a> <div class="addfile"><h4>Added: svn:mime-type ( => )</h4> <pre class="diff"> <span class="info">Added: svn:keywords + Date Author Id Revision HeadURL </span></pre></div> <a id="svneolstyle"></a> <div class="addfile"><h4>Added: svn:eol-style ( => )</h4> <pre class="diff"> <span class="info"> Modified: rhq/trunk/modules/enterprise/gui/installer-war/src/main/java/org/rhq/enterprise/installer/ConfigurationBean.java </span><span class="cx">=================================================================== </span><span class="rem">--- rhq/trunk/modules/enterprise/gui/installer-war/src/main/java/org/rhq/enterprise/installer/ConfigurationBean.java 2009-01-28 20:15:10 UTC (rev 2806) </span><span class="add">+++ rhq/trunk/modules/enterprise/gui/installer-war/src/main/java/org/rhq/enterprise/installer/ConfigurationBean.java 2009-01-28 20:29:28 UTC (rev 2807) </span><span class="lines">@@ -35,6 +35,7 @@ </span><span class="cx"> import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; </span><span class="add">+import org.rhq.core.db.DatabaseTypeFactory; </span><span class="cx"> import org.rhq.core.util.exception.ThrowableUtil; import org.rhq.enterprise.installer.i18n.InstallerI18NResourceKeys; </span><span class="lines">@@ -288,6 +289,10 @@ </span><span class="cx"> public StartPageResults testConnection() { Properties configurationAsProperties = getConfigurationAsProperties(configuration); </span><span class="add">+ + // its possible the JDBC URL was changed, clear the factory cache in case the DB version is different now + DatabaseTypeFactory.clearDatabaseTypeCache(); + </span><span class="cx"> try { serverInfo.ensureDatabaseIsSupported(configurationAsProperties); lastTest = "OK"; </span><span class="lines">@@ -429,6 +434,9 @@ </span><span class="cx"> public StartPageResults save() { LOG.info("Installer raw values: " + configuration); </span><span class="add">+ // its possible the JDBC URL was changed, clear the factory cache in case the DB version is different now + DatabaseTypeFactory.clearDatabaseTypeCache(); + </span><span class="cx"> try { // update server properties with the latest ha info to keep the form and server properties file up to date getConfigurationProperty(configuration, ServerProperties.PROP_HIGH_AVAILABILITY_NAME).setValue( </span></pre></div> <a id="rhqtrunkmodulesenterpriseguiinstallerwarsrcmainjavaorgrhqenterpriseinstallerServerInformationjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/enterprise/gui/installer-war/src/main/java/org/rhq/enterprise/installer/ServerInformation.java (2806 => 2807)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/gui/installer-war/src/main/java/org/rhq/enterprise/installer/ServerInformation.java 2009-01-28 20:15:10 UTC (rev 2806) +++ rhq/trunk/modules/enterprise/gui/installer-war/src/main/java/org/rhq/enterprise/installer/ServerInformation.java 2009-01-28 20:29:28 UTC (rev 2807) </span><span class="lines">@@ -128,7 +128,8 @@ </span><span class="cx"> String version = db.getVersion(); if (DatabaseTypeFactory.isPostgres(db)) { </span><span class="rem">- if (version.startsWith("7") || version.startsWith("8.0") || version.startsWith("8.1")) { </span><span class="add">+ if (version.startsWith("7") || version.equals("8") || version.startsWith("8.0") + || version.startsWith("8.1")) { </span><span class="cx"> throw new Exception("Unsupported PostgreSQL [" + db + "]"); } } else if (DatabaseTypeFactory.isOracle(db)) { </span> </pre> </div> </div> </body> </html> |