db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: rev 54001 - in incubator/derby/code/trunk/java/engine/org/apache/derby/impl: jdbc sql/catalog
Date Thu, 07 Oct 2004 17:59:18 GMT
Author: djd
Date: Thu Oct  7 10:59:17 2004
New Revision: 54001

Modified:
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java
   incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Log:
Faster create database by moving DatabaseMetaData SPS creation into the DataDictionary.
MEans creation of these statements is not logged and compilation is delayed until the
matching DatabaseMetaData method is first called.


Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
Thu Oct  7 10:59:17 2004
@@ -143,9 +143,6 @@
 	public EmbedConnection(Driver169 driver, String url, Properties info)
 		 throws SQLException
 	{
-		boolean createdNewDatabase = false; // indicates whether we created
-											// a new db or not
-
 		// Create a root connection.
 		applicationConnection = rootConnection = this;
 		factory = driver;
@@ -199,8 +196,6 @@
 					addWarning(EmbedSQLWarning.newEmbedSQLWarning(SQLState.DATABASE_EXISTS, getDBName()));
 				} else {
 
-					boolean[] didCreate = { false };
-
 					// check for user's credential and authenticate the user
 					// with system level authentication service.
 					// FIXME: We should also check for CREATE DATABASE operation
@@ -211,9 +206,8 @@
 					checkUserCredentials(null, info);
 					
 					// Process with database creation
-					database = createDatabase(tr.getDBName(), info, didCreate);
+					database = createDatabase(tr.getDBName(), info);
 					tr.setDatabase(database);
-					createdNewDatabase = didCreate[0];
 				}
 			}
 
@@ -241,20 +235,6 @@
 				throw tr.shutdownDatabaseException();
 			}
 
-			/*
-			** We may be required to do some work creating
-			** stored prepared statements for use by 
-			** DatabaseMetaData.  Be careful to only instantiate
-			** a DatabaseMetaData if absolutely necessary because
-			** of the overhead.
-			*/
-			boolean creatingMetaData = false;
-			if (createdNewDatabase)
-			{
-                creatingMetaData = true;
-                ((EmbedDatabaseMetaData) getMetaData()).initializeNewDatabase(info);
-			}
-
 		} catch (Throwable t) {
 			throw handleException(t);
 		} finally {
@@ -1470,16 +1450,13 @@
 		Create a new database.
 		@param dbname the database name
 		@param info the properties
-		@param didCreate a boolean array that serves as a return
-			parameter that indicates whether the database was
-			actually created or not
 
 		@return	Database The newly created database or null.
 
 	 	@exception SQLException if fails to create database
 	*/
 
-	private Database createDatabase(String dbname, Properties info, boolean[] didCreate)
+	private Database createDatabase(String dbname, Properties info)
 		throws SQLException {
 
 		info = filterProperties(info);
@@ -1489,10 +1466,6 @@
 			{
 				// service already exists, create a warning
 				addWarning(EmbedSQLWarning.newEmbedSQLWarning(SQLState.DATABASE_EXISTS, dbname));
-			}
-			else if (didCreate != null)
-			{
-				didCreate[0] = true;
 			}
 		} catch (StandardException mse) {
 

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData.java
Thu Oct  7 10:59:17 2004
@@ -137,7 +137,7 @@
 		try {
 
 			// SECURITY PERMISSION - IP3
-			InputStream is = EmbedDatabaseMetaData.class.getResourceAsStream("metadata.properties");
+			InputStream is = getClass().getResourceAsStream("metadata.properties");
 			
 			p.load(is);
 			is.close();
@@ -2847,29 +2847,6 @@
 	// MISC 
 	//
 	//////////////////////////////////////////////////////////////
-
-
-	/**
-	 * Creates  all SPSes for metadata queries. 
-	 *
-	 *
-	 * @exception StandardException standard cloudscape error
-	 *
-	 */
-	final void initializeNewDatabase(Properties dummy) throws StandardException
-	{
-		Properties p = getQueryDescriptions();
-		Enumeration enum = p.keys();
-		LanguageConnectionContext lcc = getLanguageConnectionContext();				
-		
-		while (enum.hasMoreElements())
-		{
-			String key = (String)enum.nextElement();
-			createNewSPS(key, p.getProperty(key));
-		}
-
-		lcc.internalCommit( true );
-	}
 	
 	/*
 	 * utility helper routines:
@@ -2901,13 +2878,6 @@
 
 				
                 ps = prepareSPS(nameKey, queryText);
-
-				if (ps == null)
-				{
-					// executed if for whatever reason we couldn't get a 
-                    // prepared statement from an SPS
-					ps = getEmbedConnection().prepareMetaDataStatement(queryText);
-				}
 			}
 
 			catch (Throwable t) 
@@ -2942,7 +2912,7 @@
 		 */
 		lcc.beginNestedTransaction(true);
 
-		DataDictionary dd = getDataDictionary();
+		DataDictionary dd = getLanguageConnectionContext().getDataDictionary();
 		SPSDescriptor spsd = dd.getSPSDescriptor(
 										spsName, 
 										dd.getSystemSchemaDescriptor());
@@ -2950,7 +2920,7 @@
 
 		if (spsd == null)
 		{
-			createNewSPS(spsName, spsText);
+			throw Util.notImplemented(spsName);
 		}
 
 		/* manish:
@@ -2968,48 +2938,8 @@
 
 	}
 
-
-	/*
-	** Create a new stored prepared statement.  Uses
-	** the CreateSPSConstantAction to do its dirty work.
-	**
-	*/
-	private void createNewSPS(String 		spsName,
-								String 		spsText)
-		throws StandardException
-	{
-		try
-		{
-			SchemaDescriptor sd = getDataDictionary().getSystemSchemaDescriptor();
-
-			ConstantAction action = getGenericConstantActionFactory().getCreateSPSConstantAction(
-										sd.getSchemaName(),
-										spsName,		// name
-										spsText,		// text
-										(String)null,	// using text
-										true,			// ok to create in SYS
-										false,			// compile it
-										sd.getUUID());	// compilation schema
-
-			action.executeConstantAction(null);
-		} catch (StandardException e)
-		{
-			// I think the right thing to do here is to not
-			// throw an exception if the sps already exists.
-			if (e.getMessageId().equals(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT))
-				return;
-			throw e;
-		}
-		return;
-	}
-
 	static final protected String swapNull(String s) {
 		return (s == null ? "%" : s);
-	}
-
-	private DataDictionary getDataDictionary()
-	{
-		return getLanguageConnectionContext().getDataDictionary();
 	}
 
 	/**

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DD_Version.java
Thu Oct  7 10:59:17 2004
@@ -282,7 +282,7 @@
 			bootingDictionary.upgradeMakeCatalog(tc, DataDictionary.SYSDUMMY1_CATALOG_NUM);
 			bootingDictionary.populateSYSDUMMY1(tc);
 			bootingDictionary.create_SYSIBM_procedures(tc);
-			bootingDictionary.createNetworkServerMetadataSps(tc);
+			bootingDictionary.createSystemSps(tc);
 		}
 	}
 

Modified: incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
==============================================================================
--- incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Thu Oct  7 10:59:17 2004
@@ -557,7 +557,7 @@
 				//create procedures for network server metadata
 				create_SYSIBM_procedures(bootingTC);
 				//create metadata sps statement required for network server
-				createNetworkServerMetadataSps(bootingTC);
+				createSystemSps(bootingTC);
                 // create the SYSCS_UTIL system procedures)
                 create_SYSCS_procedures(bootingTC);
 				// log the current dictionary version
@@ -7995,26 +7995,40 @@
 		return dictionaryVersion.checkVersion(requiredMajorVersion, feature);
 	}
 		
-	/*
-	** Create system built-in metadata stored prepared statements.  This is now only for network
server.
+	/**
+	** Create system built-in metadata stored prepared statements.
+	*/
+	void createSystemSps(TransactionController tc)
+		throws StandardException
+	{
+		// DatabaseMetadata stored plans
+		createSPSSet(tc, false, getSystemSchemaDescriptor().getUUID());
+
+		// network server stored plans
+		createSPSSet(tc, true, getSysIBMSchemaDescriptor().getUUID());
+	}
+
+	/**
+		Create a set of stored prepared statements from a properties file.
+		Key is the statement name, value is the SQL statement.
 	*/
-	public void createNetworkServerMetadataSps(TransactionController tc)
+	private void createSPSSet(TransactionController tc, boolean net, UUID schemaID)
 		throws StandardException
 	{
-		Properties p = getQueryDescriptions();
+		Properties p = getQueryDescriptions(net);
 		Enumeration enum = p.keys();
 		//statement will get compiled on first execution
 		//Note: Don't change this to FALSE LCC is not available for compiling
 		boolean nocompile = true;
-		UUID sysIBMUUID = getSysIBMSchemaDescriptor().getUUID();
+		
 		while (enum.hasMoreElements())
 		{
 			String spsName = (String)enum.nextElement();
 			String spsText =  p.getProperty(spsName);
 			SPSDescriptor spsd = new SPSDescriptor(this, spsName,
 												   getUUIDFactory().createUUID(),
-												   sysIBMUUID,
-												   sysIBMUUID,
+												   schemaID,
+												   schemaID,
 												   SPSDescriptor.SPS_TYPE_REGULAR,
 												   !nocompile,		// it is valid, unless nocompile
 												   spsText, //sps text
@@ -9224,26 +9238,23 @@
 	** Priv block code to load net work server meta data queries.
 	*/
 
-	private final Properties getQueryDescriptions() {
+	private String spsSet;
+	private final synchronized Properties getQueryDescriptions(boolean net) {
+		spsSet = net ? "metadata_net.properties" : "/org/apache/derby/impl/jdbc/metadata.properties";
 		return (Properties) java.security.AccessController.doPrivileged(this);
 	}
 
-	
-	private Properties PrivGetQueryDescriptions() {
+	public final Object run() {
+		// SECURITY PERMISSION - IP3
 		Properties p = new Properties();
 		try {
 
 			// SECURITY PERMISSION - IP3
-			InputStream is = DataDictionaryImpl.class.getResourceAsStream("metadata_net.properties");
+			InputStream is = getClass().getResourceAsStream(spsSet);
 			p.load(is);
 			is.close();
 		} catch (IOException ioe) {}
 		return p;
-	}
-
-	public final Object run() {
-		// SECURITY PERMISSION - IP3
-		return PrivGetQueryDescriptions();
 	}
 
 

Mime
View raw message