Issue Details (XML | Word | Printable)

Key: DERBY-3546
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Kathey Marsden
Reporter: Gary Xue
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

Failed to get database schemas of a JAR database

Created: 14/Mar/08 07:52 PM   Updated: 04/May/09 06:22 PM
Return to search
Component/s: JDBC
Affects Version/s: 10.3.2.1
Fix Version/s: 10.3.3.1, 10.4.2.0, 10.5.1.1

Time Tracking:
Not Specified

File Attachments:
  Size
Java Archive File BirtSample.jar 2008-03-14 07:54 PM Gary Xue 494 kB
Text File Licensed for inclusion in ASF works derby-3546_10.3_diff.txt 2008-05-16 06:08 PM Kathey Marsden 1 kB
Text File Licensed for inclusion in ASF works derby-3546_trunk_diff.txt 2008-05-17 07:35 PM Kathey Marsden 8 kB
Environment:
Sun JRE 1.5.0_08
Windows Server 2003

Issue & fix info: Patch Available
Resolution Date: 25/May/08 05:26 PM


 Description  « Hide
When a database residing in a JAR file is open via Derby embedded JDBC connection, the getSchemas() call on the connection's DatabaseMetaData fails with an exception: ERROR 40XD1: Container was opened in read-only mode.

STEPS TO REPRODUCE:
(1) Download the attached JAR database, BirtSample.jar, and place it in C:\ (or if another location, update the dbFile variable in test code below).
(2) Run the following Java test code, with derby.jar (version 10.3.1.1) in classpath.

// *** BEGIN TEST CODE
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class TestGetDBMetaData
{
public static void main(String[] args) throws Exception
{
final String dbFile = "c:/BirtSample.jar";
final String driverClass = "org.apache.derby.jdbc.EmbeddedDriver";
final String url= "jdbc:derby:jar:(" + dbFile + ")BirtSample";
final String user = "ClassicModels";
final String pwd = "";

Class.forName( driverClass );
Connection conn = DriverManager.getConnection( url, user, pwd);
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getSchemas();
rs.close();
conn.close();
}
}

// ***END TEST CODE

The following exception happens in the getSchemas() call:

Exception in thread "main" java.sql.SQLException: Container was opened in read-only mode.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver30.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareMetaDataStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedDatabaseMetaData.prepareSPS(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedDatabaseMetaData.getPreparedQueryUsingSystemTables(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedDatabaseMetaData.getPreparedQuery(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedDatabaseMetaData.getPreparedQuery(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedDatabaseMetaData.getSchemas(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedDatabaseMetaData.getSchemas(Unknown Source)
at TestGetDBMetaData.main(TestGetDBMetaData.java:34)
Caused by: ERROR 40XD1: Container was opened in read-only mode.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseContainer.use(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseContainerHandle.useContainer(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.openContainer(Unknown Source)
at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.openContainer(Unknown Source)
at org.apache.derby.impl.store.raw.xact.Xact.openContainer(Unknown Source)
at org.apache.derby.impl.store.access.conglomerate.OpenConglomerate.init(Unknown Source)
at org.apache.derby.impl.store.access.heap.Heap.open(Unknown Source)
at org.apache.derby.impl.store.access.RAMTransaction.openConglomerate(Unknown Source)
at org.apache.derby.impl.store.access.RAMTransaction.openConglomerate(Unknown Source)
at org.apache.derby.impl.sql.execute.RowChangerImpl.openForUpdate(Unknown Source)
at org.apache.derby.impl.sql.execute.RowChangerImpl.open(Unknown Source)
at org.apache.derby.impl.sql.catalog.TabInfoImpl.deleteRows(Unknown Source)
at org.apache.derby.impl.sql.catalog.TabInfoImpl.deleteRow(Unknown Source)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.dropDependentsStoredDependencies(Unknown Source)
at org.apache.derby.impl.sql.depend.BasicDependencyManager.clearDependencies(Unknown Source)
at org.apache.derby.iapi.sql.dictionary.SPSDescriptor.compileStatement(Unknown Source)
at org.apache.derby.iapi.sql.dictionary.SPSDescriptor.prepareAndRelease(Unknown Source)
at org.apache.derby.iapi.sql.dictionary.SPSDescriptor.getPreparedStatement(Unknown Source)
at org.apache.derby.iapi.sql.dictionary.SPSDescriptor.getPreparedStatement(Unknown Source)
at org.apache.derby.impl.sql.compile.ExecSPSNode.generate(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 12 more


NOTE:
This is an identical issue as reported in DERBY-854. It was reported as resolved but is still reproducible in 10.3.2.1., the latest official release as of this report.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Gary Xue added a comment - 14/Mar/08 07:55 PM
correction on (2) in STEPS TO REPRODUCE, derby.jar version should be version 10.3.2.1. This is the version of derby used to create the attached JAR database

Kathey Marsden added a comment - 16/May/08 06:08 PM
The attached patch fixes the issue for 10.3. This is not for commit as I haven't yet run tests or gotten a regression test, but wanted to check if it is the right approach. For read only databases metadata calls will read from the metadata.properties instead of attempting to use the Stored Prepared Statements, because those cannot be stored in the database.

Kathey Marsden added a comment - 16/May/08 08:04 PM
A workaround for this issue is to connect to the database and make the database metadata calls that are needed once before jaring up the database. The the stored prepared statements will already be in the database and Derby won't try to create them.

Kathey Marsden added a comment - 17/May/08 07:35 PM
Here is a patch for the trunk with a test. I will check in Monday afternoon if I hear no comments.

Dag H. Wanvik added a comment - 22/May/08 11:45 PM
I verified that the new test failed without the rest of the patch on trunk as expected, and worked
when the rest was added.
Approach looks good to me!
+1

Kathey Marsden added a comment - 22/May/08 11:54 PM
Thanks Dag for looking at the patch!