db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r662416 - /db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
Date Mon, 02 Jun 2008 12:45:36 GMT
Author: kristwaa
Date: Mon Jun  2 05:45:35 2008
New Revision: 662416

URL: http://svn.apache.org/viewvc?rev=662416&view=rev
Log:
DERBY-3327 / DERBY-3690: Made GLCC cache the initial default schema descriptor.
This fix is an excerpt from issue 3327, and the code was extracted from the '4-full-e' patch.
The relevant commit on trunk is revision 643920.
Patch file: derby-3327-5a-extracted_initial_schema_patch.diff

Patch was extracted from a patch contributed by Dag H. Wanvik.

Modified:
    db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java

Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?rev=662416&r1=662415&r2=662416&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
(original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
Mon Jun  2 05:45:35 2008
@@ -200,6 +200,12 @@
 	protected String currentRole;
 	protected SchemaDescriptor	sd;
 
+    /**
+     * Used to hold the computed value of the initial default schema,
+     * cf logic in initDefaultSchemaDescriptor.
+     */
+    private SchemaDescriptor cachedInitialDefaultSchemaDescr = null;
+
 	// RESOLVE - How do we want to set the default.
     private int defaultIsolationLevel = ExecutionContext.READ_COMMITTED_ISOLATION_LEVEL;
 	protected int isolationLevel = defaultIsolationLevel;
@@ -345,6 +351,13 @@
 		setDefaultSchema(initDefaultSchemaDescriptor());
 	}
 
+    /**
+     * Compute the initial default schema and set
+     * cachedInitialDefaultSchemaDescr accordingly.
+     *
+     * @return computed initial default schema value for this session
+     * @throws StandardException
+     */
 	protected SchemaDescriptor initDefaultSchemaDescriptor()
 		throws StandardException {
 		/*
@@ -355,17 +368,33 @@
 		** user.
         ** - Else Set the default schema to APP.
         */
-		// SchemaDescriptor sd;
+        if (cachedInitialDefaultSchemaDescr == null) {
+            DataDictionary dd = getDataDictionary();
+            String authorizationId = getAuthorizationId();
+            SchemaDescriptor sd =
+                dd.getSchemaDescriptor(
+                    authorizationId, getTransactionCompile(), false);
+            if (sd == null) {
+                sd = new SchemaDescriptor(
+                    dd, authorizationId, authorizationId, (UUID)null, false);
+            }
+            cachedInitialDefaultSchemaDescr = sd;
+        }
+        return cachedInitialDefaultSchemaDescr;
+    }
 
-		DataDictionary dd = getDataDictionary();
-        String authorizationId = getAuthorizationId();
-	
-		if ( (sd = dd.getSchemaDescriptor(authorizationId, getTransactionCompile(), false)) ==
null )
-		{
-			sd = new SchemaDescriptor(dd, authorizationId, authorizationId, (UUID) null, false);
-		}
-		return sd;
-	}
+    /**
+     * Get the computed value for the initial default schema.
+     * @return the schema descriptor of the computed initial default schema
+     */
+    private SchemaDescriptor getInitialDefaultSchemaDescriptor() {
+        if (SanityManager.DEBUG) {
+            SanityManager.ASSERT(cachedInitialDefaultSchemaDescr != null,
+                                 "cachedInitialDefaultSchemaDescr is null!");
+        }
+
+        return cachedInitialDefaultSchemaDescr;
+    }
 
 	//
 	// LanguageConnectionContext interface
@@ -777,7 +806,8 @@
         public PreparedStatement prepareInternalStatement(String sqlText) 
 	    throws StandardException 
         {
-    	    return connFactory.getStatement(sd, sqlText, true).prepare(this);
+        return connFactory.getStatement(
+                getDefaultSchema(), sqlText, true).prepare(this);
     	}      
 
 	/**
@@ -1818,7 +1848,7 @@
 	{ 	
 		if (sd == null)
 		{	
-		    sd = initDefaultSchemaDescriptor();
+		    sd = getInitialDefaultSchemaDescriptor();
 		}
 		this.sd = sd;
 		



Mime
View raw message