OPENJPA-656 : raise informational error on initial connection failure

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@675953 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2008-07-11 13:53:45 +00:00
parent 15715ab0db
commit 577c974463
4 changed files with 180 additions and 151 deletions

View File

@ -231,7 +231,14 @@ public class DataSourceFactory {
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 {

View File

@ -30,7 +30,9 @@ import java.util.Properties;
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 @@ public class SimpleDriverDataSource
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 class SimpleDriverDataSource
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() {

View File

@ -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.

View File

@ -47,6 +47,14 @@ public class StoreException
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;
}