Author: ppoddar
Date: Fri Jul 11 06:53:45 2008
New Revision: 675953
URL: http://svn.apache.org/viewvc?rev=675953&view=rev
Log:
OPENJPA-656 : raise informational error on initial connection failure
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java
openjpa/branches/1.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java?rev=675953&r1=675952&r2=675953&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java
(original)
+++
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/DataSourceFactory.java
Fri Jul 11 06:53:45 2008
@@ -231,7 +231,14 @@
return ds;
} catch (Exception e) {
- throw new StoreException(e).setFatal(true);
+ throw new StoreException(_loc.get("conn-failed", factory2
+ ? new Object[]{conf.getConnection2DriverName(),
+ conf.getConnection2URL(),
+ conf.getConnection2Properties()}
+ : new Object[]{conf.getConnectionDriverName(),
+ conf.getConnectionURL(),
+ conf.getConnectionProperties()}),
+ e);
} finally {
if (conn != null)
try {
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java?rev=675953&r1=675952&r2=675953&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java
(original)
+++
openjpa/branches/1.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SimpleDriverDataSource.java
Fri Jul 11 06:53:45 2008
@@ -30,7 +30,9 @@
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
+import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.util.StoreException;
+import org.apache.openjpa.util.UserException;
/**
* Non-pooling driver data source.
@@ -46,6 +48,9 @@
private Properties _connectionFactoryProperties;
private Driver _driver;
private ClassLoader _classLoader;
+
+ protected static Localizer _loc =
+ Localizer.forPackage(SimpleDriverDataSource.class);
public Connection getConnection()
throws SQLException {
@@ -70,7 +75,12 @@
public Connection getConnection(Properties props)
throws SQLException {
- return getDriver().connect(_connectionURL, props);
+ Connection con = getDriver().connect(_connectionURL, props);
+ if (con == null) {
+ throw new UserException(_loc.get("conn-failed",
+ _connectionDriverName, _connectionURL, props));
+ }
+ return con;
}
public int getLoginTimeout() {
Modified:
openjpa/branches/1.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties?rev=675953&r1=675952&r2=675953&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties
(original)
+++
openjpa/branches/1.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/schema/localizer.properties
Fri Jul 11 06:53:45 2008
@@ -1,149 +1,153 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-bad-join: The following error was detected when creating a foreign key: \
- "{0}". The foreign key is being ignored.
-no-driver: A JDBC Driver or DataSource class name must be specified in the \
- ConnectionDriverName property.
-bad-driver: The specified driver "{0}" is neither a java.sql.Driver \
- nor a javax.sql.DataSource class name.
-bad-sch-ref: The schema information table could not be created: {0}
-bad-sch-read: Attempt to read the schema information table failed; continuing \
- on the assumption that the table has not been created yet, and there is
\
- no data to read: {0}
-bad-sch-write-1: First attempt to write to the schema information table \
- failed; will attempt to create the table in case it has been dropped \
- before re-trying: {0}
-bad-sch-write-2: Attempt to write the schema information table for the second \
- time failed. See previous log messages for possible reasons.
-bad-seq-num: Bad numeric constant for attribute in sequence "{0}".
-pk-resolve: The column "{0}" specified as a primary key for table "{1}" \
- does not exist in that table.
-index-info: Unable to get index information for table "{0}": "{1}"
-index-resolve: The column "{1}" specified as part of index "{0}" on table \
- "{2}" does not exist in that table.
-unq-resolve: The column "{1}" specified as part of unique constraint "{0}" on \
- table "{2}" does not exist in that table.
-fk-totable: The foreign table "{1}" specified in foreign key "{0}" on \
- table "{2}" does not exist or does not have a primary key.
-fk-nocol: The column "{1}" specified by foreign key "{0}" on table "{2}" \
- does not exist in that table.
-fk-nopkcol: The column "{1}" of table "{2}" joined to by foreign key "{0}" \
- on table "{3}" does not exist or is not a primary key column.
-bad-name: You must supply a valid name for this schema component.
-dup-col-name: The name "{0}" is already taken by a column in this table.
-table-mismatch: You are attempting to add a column from table "{0}" to a \
- constraint or index on table "{1}".
-fk-mismatch: You are attempting to link to a primary key column in table \
- "{0}" in a foreign key that is already linked to primary key columns in
\
- table "{1}".
-ser-schema: Writing schema "{0}".
-tool-norepos: You cannot perform this action until you set the schema group \
- to act on.
-tool-running: Schema tool will run on schema file "{0}".
-tool-import-store: Storing imported schema data in schema factory.
-tool-export-gen: Gathering schema information to export; this process \
- may take some time. Enable the org.apache.openjpa.jdbc.Schema logging
category to see \
- messages about the collection of schema data.
-tool-action: Schema tool running action "{0}". This process may take some \
- time. Enable the org.apache.openjpa.jdbc.Schema logging category to
see messages about \
- the collection of schema data, and the org.apache.openjpa.jdbc.SQL
category to see \
- generated SQL commands.
-tool-record: Recording schema changes.
-tool-export-write: Writing schema data to XML.
-tool-usage: Usage: java org.apache.openjpa.jdbc.schema.SchemaTool\n\
- \t[-properties/-p <properties file or resource>]\n\
- \t[-<property name> <property value>]*\n\
- \t[-file/-f <stdout | output file or resource>]\n\
- \t[-ignoreErrors/-i <true/t | false/f>]\n\
- \t[-dropTables/-dt <true/t | false/f>]\n\
- \t[-openjpaTables/-ot <true/t | false/f>]\n\
- \t[-dropSequences/-dsq <true/t | false/f>]\n\
- \t[-sequences/-sq <true/t | false/f>]\n\
- \t[-primaryKeys/-pk <true/t | false/f>]\n\
- \t[-foreignKeys/-fk <true/t | false/f>]\n\
- \t[-indexes/-ix <true/t | false/f>]\n\
- \t[-record/-r <true/t | false/f>]\n\
- \t[-action/-a <add | retain | drop | refresh | build | reflect\n\
- \t\t| createDB | dropDB | import | export | deleteTableContents>]\n\
- \t<.schema file or resource>*
-sch-reflect: Reflecting on schemas "{0}". This process may take some time. \
- Enable the org.apache.openjpa.jdbc.Schema logging category to see
messages about the \
- collection of schema data.
-sch-reflect-write: Writing XML representation of schema.
-drop-index: The index "{0}" was not dropped from table "{1}".
-drop-fk: The foreign key "{0}" was not dropped from table "{1}".
-drop-pk: The primary key "{0}" was not dropped from table "{1}".
-drop-col: The column "{0}" was not dropped from table "{1}".
-drop-table: The table "{0}" was not dropped.
-drop-seq: The sequence "{0}" was not dropped.
-add-col: The column "{0}" was not added to table "{1}".
-add-index: The index "{0}" was not created on table "{1}".
-too-many-indexes: The index "{0}" was not created on table "{1}", since it \
- would go beyond the maximum index limit of {2}.
-add-pk: The primary key "{0}" was not added to table "{1}".
-add-fk: The foreign key "{0}" was not added to table "{1}".
-add-table: The table "{0}" was not created.
-add-seq: The sequence "{0}" was not added to the database.
-bad-col: Existing column "{0}" on table "{1}" is incompatible with the \
- same column in the given schema definition. Existing column:\n{2}\
- Given column:\n{3}
-bad-pk: Existing primary key "{0}" on table "{1}" is incompatible with \
- the same primary key in the given schema definition.
-bad-index: Existing index "{0}" on table "{1}" is incompatible with the \
- same index in the given schema definition.
-bad-fk: Existing foreign key "{0}" on table "{1}" is incompatible with \
- the same foreign key in the given schema definition.
-bad-fk-action-hint: "{1}" is not a recognized foreign key action, though it \
- closely resembles the standard action "{2}". Available actions are: {3}
-bad-fk-action: "{1}" is not a recognized foreign key action. Available \
- actions are: {2}
-gen-pk: Found existing primary key "{0}" on table "{1} ({2})".
-gen-index: Found existing index "{0}" on table "{1} ({2})".
-gen-fk: Found existing foreign key "{0}" on table "{1} ({2})" linking to \
- table "{3} ({4})". Sequence: "{5}".
-gen-nofktable: Table "{0}" has a foreign key to table "{1}" that has not been \
- generated. You must run the schema generator on all inter-related
tables \
- at once.
-gen-tables: Reading table information for schema name "{0}", table name "{1}".
-gen-pks: Reading primary keys for schema name "{0}", table name "{1}".
-gen-indexes: Reading indexes for schema name "{0}", table name "{1}".
-gen-fks: Reading foreign keys for schema name "{0}", table name "{1}".
-col-table: Reading column information for table "{0}".
-gen-column: Found existing column "{0}" on table "{1}".
-gen-seqs: Reading sequence information for schema "{0}", sequence name "{1}".
-no-idx-meta: Unable to get index metadata for table "{0}": {1}
-make-sch-table: Creating table to hold schema information.
-drop-sch-table: Dropping schema table.
-sch-usage: Usage: java org.apache.openjpa.jdbc.schema.TableSchemaFactory\n\
- \t[-properties <properties file or resource>]\n\
- \t[-<property name> <property value>]\n\
- \t-action/-a <add | drop>
-refresh-cancelled: Refresh operation cancelled.
-generating-schemas: Reading schemas
-generating-schema: Reading schema "{0}"
-generating-all-primaries: Reading primary keys for schema "{0}"
-generating-all-indexes: Reading indexes for schema "{0}"
-generating-all-foreigns: Reading foreign keys for schema "{0}"
-generating-columns: Reading columns for table "{1}"
-generating-primary: Reading primary keys for table "{1}"
-generating-indexes: Reading indexes for table "{1}"
-generating-foreign: Reading foreign keys for table "{1}"
-generating-sequences: Reading sequences for schema "{0}"
-no-custom-ds: use a custom DataSource
-delete-table-contents: An error occurred while attempting to delete all \
- records from all mapped tables.
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+bad-join: The following error was detected when creating a foreign key: \
+ "{0}". The foreign key is being ignored.
+no-driver: A JDBC Driver or DataSource class name must be specified in the \
+ ConnectionDriverName property.
+bad-driver: The specified driver "{0}" is neither a java.sql.Driver \
+ nor a javax.sql.DataSource class name.
+bad-sch-ref: The schema information table could not be created: {0}
+bad-sch-read: Attempt to read the schema information table failed; continuing \
+ on the assumption that the table has not been created yet, and there is
\
+ no data to read: {0}
+bad-sch-write-1: First attempt to write to the schema information table \
+ failed; will attempt to create the table in case it has been dropped \
+ before re-trying: {0}
+bad-sch-write-2: Attempt to write the schema information table for the second \
+ time failed. See previous log messages for possible reasons.
+bad-seq-num: Bad numeric constant for attribute in sequence "{0}".
+pk-resolve: The column "{0}" specified as a primary key for table "{1}" \
+ does not exist in that table.
+index-info: Unable to get index information for table "{0}": "{1}"
+index-resolve: The column "{1}" specified as part of index "{0}" on table \
+ "{2}" does not exist in that table.
+unq-resolve: The column "{1}" specified as part of unique constraint "{0}" on \
+ table "{2}" does not exist in that table.
+fk-totable: The foreign table "{1}" specified in foreign key "{0}" on \
+ table "{2}" does not exist or does not have a primary key.
+fk-nocol: The column "{1}" specified by foreign key "{0}" on table "{2}" \
+ does not exist in that table.
+fk-nopkcol: The column "{1}" of table "{2}" joined to by foreign key "{0}" \
+ on table "{3}" does not exist or is not a primary key column.
+bad-name: You must supply a valid name for this schema component.
+dup-col-name: The name "{0}" is already taken by a column in this table.
+table-mismatch: You are attempting to add a column from table "{0}" to a \
+ constraint or index on table "{1}".
+fk-mismatch: You are attempting to link to a primary key column in table \
+ "{0}" in a foreign key that is already linked to primary key columns in
\
+ table "{1}".
+ser-schema: Writing schema "{0}".
+tool-norepos: You cannot perform this action until you set the schema group \
+ to act on.
+tool-running: Schema tool will run on schema file "{0}".
+tool-import-store: Storing imported schema data in schema factory.
+tool-export-gen: Gathering schema information to export; this process \
+ may take some time. Enable the org.apache.openjpa.jdbc.Schema logging
category to see \
+ messages about the collection of schema data.
+tool-action: Schema tool running action "{0}". This process may take some \
+ time. Enable the org.apache.openjpa.jdbc.Schema logging category to
see messages about \
+ the collection of schema data, and the org.apache.openjpa.jdbc.SQL
category to see \
+ generated SQL commands.
+tool-record: Recording schema changes.
+tool-export-write: Writing schema data to XML.
+tool-usage: Usage: java org.apache.openjpa.jdbc.schema.SchemaTool\n\
+ \t[-properties/-p <properties file or resource>]\n\
+ \t[-<property name> <property value>]*\n\
+ \t[-file/-f <stdout | output file or resource>]\n\
+ \t[-ignoreErrors/-i <true/t | false/f>]\n\
+ \t[-dropTables/-dt <true/t | false/f>]\n\
+ \t[-openjpaTables/-ot <true/t | false/f>]\n\
+ \t[-dropSequences/-dsq <true/t | false/f>]\n\
+ \t[-sequences/-sq <true/t | false/f>]\n\
+ \t[-primaryKeys/-pk <true/t | false/f>]\n\
+ \t[-foreignKeys/-fk <true/t | false/f>]\n\
+ \t[-indexes/-ix <true/t | false/f>]\n\
+ \t[-record/-r <true/t | false/f>]\n\
+ \t[-action/-a <add | retain | drop | refresh | build | reflect\n\
+ \t\t| createDB | dropDB | import | export | deleteTableContents>]\n\
+ \t<.schema file or resource>*
+sch-reflect: Reflecting on schemas "{0}". This process may take some time. \
+ Enable the org.apache.openjpa.jdbc.Schema logging category to see
messages about the \
+ collection of schema data.
+sch-reflect-write: Writing XML representation of schema.
+drop-index: The index "{0}" was not dropped from table "{1}".
+drop-fk: The foreign key "{0}" was not dropped from table "{1}".
+drop-pk: The primary key "{0}" was not dropped from table "{1}".
+drop-col: The column "{0}" was not dropped from table "{1}".
+drop-table: The table "{0}" was not dropped.
+drop-seq: The sequence "{0}" was not dropped.
+add-col: The column "{0}" was not added to table "{1}".
+add-index: The index "{0}" was not created on table "{1}".
+too-many-indexes: The index "{0}" was not created on table "{1}", since it \
+ would go beyond the maximum index limit of {2}.
+add-pk: The primary key "{0}" was not added to table "{1}".
+add-fk: The foreign key "{0}" was not added to table "{1}".
+add-table: The table "{0}" was not created.
+add-seq: The sequence "{0}" was not added to the database.
+bad-col: Existing column "{0}" on table "{1}" is incompatible with the \
+ same column in the given schema definition. Existing column:\n{2}\
+ Given column:\n{3}
+bad-pk: Existing primary key "{0}" on table "{1}" is incompatible with \
+ the same primary key in the given schema definition.
+bad-index: Existing index "{0}" on table "{1}" is incompatible with the \
+ same index in the given schema definition.
+bad-fk: Existing foreign key "{0}" on table "{1}" is incompatible with \
+ the same foreign key in the given schema definition.
+bad-fk-action-hint: "{1}" is not a recognized foreign key action, though it \
+ closely resembles the standard action "{2}". Available actions are: {3}
+bad-fk-action: "{1}" is not a recognized foreign key action. Available \
+ actions are: {2}
+gen-pk: Found existing primary key "{0}" on table "{1} ({2})".
+gen-index: Found existing index "{0}" on table "{1} ({2})".
+gen-fk: Found existing foreign key "{0}" on table "{1} ({2})" linking to \
+ table "{3} ({4})". Sequence: "{5}".
+gen-nofktable: Table "{0}" has a foreign key to table "{1}" that has not been \
+ generated. You must run the schema generator on all inter-related
tables \
+ at once.
+gen-tables: Reading table information for schema name "{0}", table name "{1}".
+gen-pks: Reading primary keys for schema name "{0}", table name "{1}".
+gen-indexes: Reading indexes for schema name "{0}", table name "{1}".
+gen-fks: Reading foreign keys for schema name "{0}", table name "{1}".
+col-table: Reading column information for table "{0}".
+gen-column: Found existing column "{0}" on table "{1}".
+gen-seqs: Reading sequence information for schema "{0}", sequence name "{1}".
+no-idx-meta: Unable to get index metadata for table "{0}": {1}
+make-sch-table: Creating table to hold schema information.
+drop-sch-table: Dropping schema table.
+sch-usage: Usage: java org.apache.openjpa.jdbc.schema.TableSchemaFactory\n\
+ \t[-properties <properties file or resource>]\n\
+ \t[-<property name> <property value>]\n\
+ \t-action/-a <add | drop>
+refresh-cancelled: Refresh operation cancelled.
+generating-schemas: Reading schemas
+generating-schema: Reading schema "{0}"
+generating-all-primaries: Reading primary keys for schema "{0}"
+generating-all-indexes: Reading indexes for schema "{0}"
+generating-all-foreigns: Reading foreign keys for schema "{0}"
+generating-columns: Reading columns for table "{1}"
+generating-primary: Reading primary keys for table "{1}"
+generating-indexes: Reading indexes for table "{1}"
+generating-foreign: Reading foreign keys for table "{1}"
+generating-sequences: Reading sequences for schema "{0}"
+no-custom-ds: use a custom DataSource
+delete-table-contents: An error occurred while attempting to delete all \
+ records from all mapped tables.
+set-auto-commit: DataSource connection setAutoCommit to "{0}"
+conn-failed: Failed to connect to DataSource. Verify Driver "{0}", URL "{1}" \
+ and connection properties "{2}" are correct. See the nested exception
for \
+ further details.
Modified:
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java?rev=675953&r1=675952&r2=675953&view=diff
==============================================================================
---
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java
(original)
+++
openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java
Fri Jul 11 06:53:45 2008
@@ -47,6 +47,14 @@
super(cause);
}
+ public StoreException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ public StoreException(Message msg, Throwable cause) {
+ super(msg.getMessage(), cause);
+ }
+
public int getType() {
return STORE;
}