db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r526237 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/sql/dictionary/DataDictionary.java iapi/sql/dictionary/SchemaDescriptor.java impl/sql/catalog/DataDictionaryImpl.java
Date Fri, 06 Apr 2007 17:43:39 GMT
Author: mamta
Date: Fri Apr  6 10:43:38 2007
New Revision: 526237

URL: http://svn.apache.org/viewvc?view=rev&rev=526237
Log:
This commit is for DERBY- 2528 Set the correct collation type in SchemaDescriptor. The collation
type will be UCS_BASIC for system schemas but it can be 
TERRITORY_BASED/UCS_BASIC for user schemas.

The patch implements the correct default collation type for schemas with following design
DataDictionary(DD) now has two additional fields and two additional apis. The field names
are
int collationTypeOfSystemSchemas 
int collationTypeOfUserSchemas 
The apis associated with them are
public int getCollationTypeOfSystemSchemas() 
public int getCollationTypeOfUserSchemas() 
DD in it's boot method initializes the collationTypeOfSystemSchemas to StringDataValue.COLLATION_TYPE_UCS_BASIC
In the same boot method, it checks the 
collation property supplied through optional JDBC attribute COLLATION and set collationTypeOfUserSchemas
to StringDataValue.COLLATION_TYPE_UCS_BASIC or 
StringDataValue.COLLATION_TYPE_TERRITORY_BASED. This covers the changes made in DD. 
  
Now coming to SD. SD has a new field 
int collationType 
It also has a new api called 
public int getCollationType() 
This new field gets initialized in SD's constructor. SD's constructor already gets DD and
isSystem passed to it. SD can use these 2 parameters to 
initialize collationType. The additional code in SD's constructor looks like this 
if (isSystem) //check if I am a system schema 
   collationType = DD.getCollationTypeOfSystemSchemas(); 
else 
   collationType = DD.getCollationTypeOfUserSchemas(); 


The reason I am having SD's constructor call DD to get the collation type rather than collationType
simply getting passed to SD's constructor is that the 
later approach would require us to change all the places where a SD object is created and
have them pass the additional collationType parameter to it's 
constructor. I searched through the code and there are several places where we create a SD.

  
With the approach of this patch , we have to change code in only one place and that would
be in SD's constructor (and ofcourse we need changes in DD as 
explained in my mail earlier. But the changes in DD are required no matter how SD gets the
right value in it's collationType field). 

svn stat -q 
M java\engine\org\apache\derby\impl\sql\catalog\DataDictionaryImpl.java 
M java\engine\org\apache\derby\iapi\sql\dictionary\SchemaDescriptor.java 
M java\engine\org\apache\derby\iapi\sql\dictionary\DataDictionary.java 

Following describes individual file changes
1)The changes in DataDictionary(DD) involves adding 2 new apis. These apis is how a SchemaDescriptor
in it's constructor will get the correct collation type
from DD. The 2 apis are as follows 
public int getCollationTypeOfSystemSchemas(); 
public int getCollationTypeOfUserSchemas(); 
2)The changes in DataDictionaryImpl(DDimpl) involves adding 2 new fields and implementation
of the apis added in DD. The 2 new fields are 
private int collationTypeOfUserSchemas; 
private int collationTypeOfSystemSchemas; 
These 2 fields get initialized in DDimpl's boot method. Since the primary purpose of these
2 fields is to have correct collation type for user and system 
schema so a SchemaDescriptor(SD)'s constructor can call the apis on these 2 fields, these
2 fields should get initialized before SDs start loading into the 
system. 
It is easy to set collationTypeOfUserSchemas because in Derby 10.3, it is always UCS_BASIC.
I do this initalization before DDimpl's boot method calls 
getBuiltinSchemas. This method was used to load SYS SDs along with SESSION SD(which is used
for global temporary tables. But global temporary tables are 
user defined temporary tables and hence SESSION schema should be considered a user schema
rather than system schema. But the collation type of user schemas 
can't be determined at this point in the boot method and hence for this reason, 
I have taken out SESSION SD creation out of getBuiltinSchemas. Later, in DDimpl's boot method,
I go through the code of looking at COLLATION property(for 
existing database)/attribute (for database that is getting created) to determine the user
schema collation. Once that is determined, we are safe to load 
a SD for SESSION schema. 
3)The change in SD is to have a field called collationType and this field gets initialized
in SD's constructor using the 2 new apis on DD. 

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java?view=diff&rev=526237&r1=526236&r2=526237
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
Fri Apr  6 10:43:38 2007
@@ -265,7 +265,31 @@
 	 * @return	Whether sqlAuthorization is being used
 	 */
 	public boolean usesSqlAuthorization();
+	
+	/**
+	 * Return the collation type for SYSTEM schemas. In Derby 10.3, this will 
+	 * always be UCS_BASIC 
+	 * 
+	 * @return the collation type for SYSTEM schemas
+	 */
+	public int getCollationTypeOfSystemSchemas();
 
+	/**
+	 * Return the collation type for user schemas. In Derby 10.3, this is either 
+	 * UCS_BASIC or TERRITORY_BASED. The exact value is decided by what has 
+	 * user asked for through JDBC url optional attribute COLLATION. If that
+	 * atrribute is set to UCS_BASIC, the collation type for user schemas
+	 * will be UCS_BASIC. If that attribute is set to TERRITORY_BASED, the 
+	 * collation type for user schemas will be TERRITORY_BASED. If the user
+	 * has not provided COLLATION attribute value in the JDBC url at database
+	 * create time, then collation type of user schemas will default to 
+	 * UCS_BASIC. Pre-10.3 databases after upgrade to Derby 10.3 will also
+	 * use UCS_BASIC for collation type of user schemas. 
+	 * 
+	 * @return the collation type for user schemas
+	 */
+	public int getCollationTypeOfUserSchemas();
+	
 	/**
 	 * Get the descriptor for the named schema.
 	   Schema descriptors include authorization ids and schema ids.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java?view=diff&rev=526237&r1=526236&r2=526237
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
Fri Apr  6 10:43:38 2007
@@ -158,6 +158,13 @@
 
     private final boolean isSystem;
     private final boolean isSYSIBM;
+    
+    /**
+     * For system schemas, the only possible value for collation type is
+     * UCS_BASIC. For user schemas, the collation type can be UCS_BASIC or 
+     * TERRITORY_BASED.
+     */
+    private int collationType;
 
 	/**
 	 * Constructor for a SchemaDescriptor.
@@ -183,6 +190,10 @@
 		this.oid = oid;
         this.isSystem = isSystem;
 		isSYSIBM = isSystem && IBM_SYSTEM_SCHEMA_NAME.equals(name);
+		if (isSystem)
+			collationType = dataDictionary.getCollationTypeOfSystemSchemas();
+		else
+			collationType = dataDictionary.getCollationTypeOfUserSchemas();
 	}
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?view=diff&rev=526237&r1=526236&r2=526237
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Fri Apr  6 10:43:38 2007
@@ -416,6 +416,26 @@
 												"SYSCS_GET_RUNTIMESTATISTICS", 
 												};
 	
+	/**
+	 * Collation Type for SYSTEM schemas. In Derby 10.3, this will always 
+	 * be UCS_BASIC 
+	 */
+	private int collationTypeOfSystemSchemas;
+
+	/**
+	 * Collation Type for user schemas. In Derby 10.3, this is either 
+	 * UCS_BASIC or TERRITORY_BASED. The exact value is decided by what has 
+	 * user asked for through JDBC url optional attribute COLLATION. If that
+	 * atrribute is set to UCS_BASIC, the collation type for user schemas
+	 * will be UCS_BASIC. If that attribute is set to TERRITORY_BASED, the 
+	 * collation type for user schemas will be TERRITORY_BASED. If the user
+	 * has not provide COLLATION attribute value in the JDBC url at database
+	 * create time, then collation type of user schemas will default to 
+	 * UCS_BASIC. Pre-10.3 databases after upgrade to Derby 10.3 will also
+	 * use UCS_BASIC for collation type of user schemas.
+	 */
+	private int collationTypeOfUserSchemas;
+
 	/*
 	** Constructor
 	*/
@@ -464,8 +484,16 @@
 		uuidFactory = Monitor.getMonitor().getUUIDFactory();
 
 		engineType = Monitor.getEngineType( startParams );
-        
-        getBuiltinSchemas();
+
+		//Set the collation type of system schemas before we start loading 
+		//built-in schemas's SchemaDescriptor(s). This is because 
+		//SchemaDescriptor will look to DataDictionary to get the correct 
+		//collation type for themselves. We can't load SD for SESSION schema
+		//just yet because we do not know the collation type for user schemas
+		//yet. We will know the right collation for user schema little later
+		//in this boot method.
+		collationTypeOfSystemSchemas = StringDataValue.COLLATION_TYPE_UCS_BASIC;
+        getBuiltinSystemSchemas();
 
 		// REMIND: actually, we're supposed to get the DataValueFactory
 		// out of the connection context...this is a bit of a shortcut.
@@ -639,7 +667,49 @@
 			exFactory.newExecutionContext(cm);
 
 			DataDescriptorGenerator ddg = getDataDescriptorGenerator();
-	
+
+			//We should set the user schema collation type here now because
+			//later on, we are going to create user schema APP. By the time any
+			//user schema gets created, we should have the correct collation
+			//type set for such schemas to use. For this reason, don't remove
+			//the following if else statement and don't move it later in this 
+			//method.
+			String userDefinedCollation;		
+			if (create) {
+				// Get the collation attribute from the JDBC url. It can only have one of
+				// 2 possible values - UCS_BASIC or TERRITORY_BASED
+				// This attribute can only be specified at database create time.
+				userDefinedCollation = startParams.getProperty(Attribute.COLLATION);		
+				if (userDefinedCollation == null)
+					userDefinedCollation = Property.UCS_BASIC_COLLATION;
+				else {//Invalid value handling
+					if (!userDefinedCollation.equalsIgnoreCase(Property.UCS_BASIC_COLLATION)
+							&& !userDefinedCollation.equalsIgnoreCase(Property.TERRITORY_BASED_COLLATION))
+						throw StandardException.newException(SQLState.INVALID_COLLATION, userDefinedCollation);
+					}
+				bootingTC.setProperty(Property.COLLATION,userDefinedCollation,true);
+			} else {
+				userDefinedCollation = startParams.getProperty(Property.COLLATION);
+				if (userDefinedCollation == null)
+					userDefinedCollation = Property.UCS_BASIC_COLLATION;
+			}
+
+			//Initialize the collation type of user schemas after looking at 
+			//collation property/attribute.
+			if (userDefinedCollation.equalsIgnoreCase(Property.UCS_BASIC_COLLATION))
+				collationTypeOfUserSchemas = StringDataValue.COLLATION_TYPE_UCS_BASIC;
+			else
+				collationTypeOfUserSchemas = StringDataValue.COLLATION_TYPE_TERRITORY_BASED;
+
+			//Now is also a good time to create schema descriptor for global
+			//temporary tables. Since this is a user schema, it should use the
+			//collation type associated with user schemas. Since we just 
+			//finished setting up the collation type of user schema, it is 
+			//safe to create user SchemaDescriptor(s) now.
+			declaredGlobalTemporaryTablesSchemaDesc = 
+	            newDeclaredGlobalTemporaryTablesSchemaDesc(
+	                    SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME);
+			
 			if (create) {
 				String userName = IdUtil.getUserNameFromURLProps(startParams);
 				authorizationDatabaseOwner = IdUtil.getUserAuthorizationId(userName);
@@ -673,18 +743,6 @@
 					bootingTC.setProperty(Property.SQL_AUTHORIZATION_PROPERTY,"true",true);
 					usesSqlAuthorization=true;
 				}
-				// Get the collation attribute from the JDBC url. It can only have one of
-				// 2 possible values - UCS_BASIC or TERRITORY_BASED
-				// This attribute can only be specified at database create time.
-				String userDefinedCollation = startParams.getProperty(Attribute.COLLATION);		
-				if (userDefinedCollation == null)
-					userDefinedCollation = Property.UCS_BASIC_COLLATION;
-				else {//Invalid value handling
-					if (!userDefinedCollation.equalsIgnoreCase(Property.UCS_BASIC_COLLATION)
-							&& !userDefinedCollation.equalsIgnoreCase(Property.TERRITORY_BASED_COLLATION))
-						throw StandardException.newException(SQLState.INVALID_COLLATION, userDefinedCollation);
-					}
-				bootingTC.setProperty(Property.COLLATION,userDefinedCollation,true);
 			} else {
 				// Get the ids for non-core tables
 				loadDictionaryTables(bootingTC, ddg, startParams);
@@ -1193,6 +1251,18 @@
 	{
 		return usesSqlAuthorization;
 	}
+	
+	/** @see DataDictionary#getCollationTypeOfSystemSchemas() */
+	public int getCollationTypeOfSystemSchemas() 
+	{
+		return collationTypeOfSystemSchemas;		
+	}
+	
+	/** @see DataDictionary#getCollationTypeOfUserSchemas() */
+	public int getCollationTypeOfUserSchemas()
+	{
+		return collationTypeOfUserSchemas;
+	}
 
 	/**
 	 * Get a DataValueFactory, through which we can create
@@ -1217,9 +1287,9 @@
 
 
     /**
-     * Set up the builtin schema descriptors.
+     * Set up the builtin schema descriptors for system schemas.
      */
-    private void getBuiltinSchemas()
+    private void getBuiltinSystemSchemas()
     {
         if (systemSchemaDesc != null)
             return;
@@ -1233,10 +1303,6 @@
 		systemUtilSchemaDesc  = 
             newSystemSchemaDesc(SchemaDescriptor.STD_SYSTEM_UTIL_SCHEMA_NAME,
                 SchemaDescriptor.SYSCS_UTIL_SCHEMA_UUID);
-
-		declaredGlobalTemporaryTablesSchemaDesc = 
-            newDeclaredGlobalTemporaryTablesSchemaDesc(
-                    SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME);
     }
 
 	/**
@@ -6256,7 +6322,7 @@
 
 	/**
 		Create all the required dictionary tables. Any classes that extend this class
-		and need to create new tables shoudl override this method, and then
+		and need to create new tables should override this method, and then
 		call this method as the first action in the new method, e.g.
 		<PRE>
 		protected Configuration createDictionaryTables(Configuration cfg, TransactionController
tc,



Mime
View raw message