⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datadictionaryimpl.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
						setCacheMode(DataDictionary.COMPILE_ONLY_MODE);					}					if (SanityManager.DEBUG)					{						SanityManager.ASSERT(readersInDDLMode >= 0,							"readersInDDLMode is invalid -- should never be < 0");					}				}			}		}	}	/*	 * @see org.apache.derby.iapi.sql.dictionary.DataDictionary#startWriting	 *	 * @exception StandardException		Thrown on error	 */	public void startWriting(LanguageConnectionContext lcc) 		throws StandardException	{		boolean blocked = true;			/*		** Don't allow DDL if we're binding a SQL statement.		*/		if (lcc.getBindCount() != 0)		{			throw StandardException.newException(SQLState.LANG_DDL_IN_BIND);		}			/*		** Check whether we've already done a DDL statement in this		** transaction.  If so, we don't want to re-enter DDL mode, or		** bump the DDL user count.		*/		if ( ! lcc.dataDictionaryInWriteMode())		{			for (int i = 0; blocked; i++)			{				/*				** If we already tried 5 times and failed, do				** an unbounded wait for the lock w/o				** synchronization.  Immediately unlock and				** sleep a random amount of time and start				** the whole process over again.				*/				if (i > 4 && 					getCacheMode() == DataDictionary.COMPILE_ONLY_MODE)				{                    // Wait until the settable timeout value for the lock,                    // and once granted, immediately release the lock.  If                    // this wait time's out then a TIMEOUT error is sent                    // up the stack.                    lockFactory.zeroDurationlockObject(                        lcc.getTransactionExecute().getLockObject(),                        cacheCoordinator,                        ShExQual.EX,                        C_LockFactory.TIMED_WAIT);					i = 1;				}				if (i > 0)				{					try                     {                         Thread.sleep(                            (long)((java.lang.Math.random() * 1131) % 20));                     }					catch (InterruptedException ie)					{						throw StandardException.interrupt(ie);					}				} 				synchronized(this)				{					if (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE)					{                        // When the C_LockFactory.NO_WAIT is used this routine                         // will not throw timeout or deadlock exceptions.  The                         // boolean returned will indicate if the lock was                         // granted or not.  If it would have had to wait, it                         // just returns immediately and returns false.                        //                         // See if we can get this lock granted without waiting                        // (while holding the dataDictionary synchronization).                        boolean lockGranted =                             lockFactory.zeroDurationlockObject(                                lcc.getTransactionExecute().getLockObject(),                                cacheCoordinator,                                ShExQual.EX,                                C_LockFactory.NO_WAIT);                        if (!lockGranted)                            continue;						/* Switch the caching mode to DDL */						setCacheMode(DataDictionary.DDL_MODE);							/* Clear out all the caches */						clearCaches();					}							/* Keep track of the number of DDL users */					ddlUsers++;				} // end synchronized						/*				** Tell the connection the DD is in DDL mode, so it can take				** it out of DDL mode when the transaction finishes.				*/				lcc.setDataDictionaryWriteMode();				blocked = false;			}		}		else if (SanityManager.DEBUG)		{			SanityManager.ASSERT(getCacheMode() == DataDictionary.DDL_MODE,				"lcc.getDictionaryInWriteMode() but DataDictionary is COMPILE_MODE");		}	}	/* @see org.apache.derby.iapi.sql.dictionary.DataDictionary#transactionFinished */	public void transactionFinished() throws StandardException	{		/* This is an arbitrary choice of object to synchronize these methods */		synchronized(this)		{			if (SanityManager.DEBUG)			{				SanityManager.ASSERT(ddlUsers > 0,					"Number of DDL Users is <= 0 when finishing a transaction");				SanityManager.ASSERT(getCacheMode() == DataDictionary.DDL_MODE,					"transactionFinished called when not in DDL_MODE");			}			ddlUsers--;			/*			** We can only switch back to cached (COMPILE_ONLY)			** mode if there aren't any readers that started in			** DDL_MODE.  Otherwise we could get a reader			** in DDL_MODE that reads a cached object that			** was brought in by a reader in COMPILE_ONLY_MODE.			** If 2nd reader finished and releases it lock			** on the cache there is nothing to pevent another			** writer from coming along an deleting the cached			** object.			*/			if (ddlUsers == 0 && readersInDDLMode == 0)			{				clearCaches();				setCacheMode(DataDictionary.COMPILE_ONLY_MODE);			}		}	}	/*	** SYNCHRONIZATION: no synchronization	** necessary since integer reads/writes	** are atomic	*/	public int getCacheMode()	{		return cacheMode;	}	/*	** SYNCHRONIZATION: no synchronization	** necessary since integer reads/writes	** are atomic	*/	private void setCacheMode(int newMode)	{		cacheMode = newMode;	}	/**	 * Get a DataDescriptorGenerator, through which we can create	 * objects to be stored in the DataDictionary.	 *	 * @return	A DataDescriptorGenerator	 */	public DataDescriptorGenerator	getDataDescriptorGenerator()	{		return dataDescriptorGenerator;	}	/**	 * Get a DataValueFactory, through which we can create	 * data value objects.	 *	 * @return	A DataValueFactory	 */	public DataValueFactory	getDataValueFactory()	{		return dvf;	}	/**	 * Get ExecutionFactory associated with this database.	 *	 * @return	The ExecutionFactory	 */	public ExecutionFactory	getExecutionFactory()	{		return exFactory;	}	/**	 * @see DataDictionary#pushDataDictionaryContext	 */	public DataDictionaryContext pushDataDictionaryContext(ContextManager contextManager,														   boolean nested)	{		DataDictionaryContextImpl dataDictionaryContextImpl =			new DataDictionaryContextImpl(contextManager, this, nested);		return dataDictionaryContextImpl;	}    /* We defer getting the builtin schemas (system and default) past boot time so that     * the language connection context will be available.     */    private void getBuiltinSchemaNames() throws StandardException    {        if( builtinSchemasAreFromLCC)            return;                LanguageConnectionContext lcc = getLCC();        if( null == lcc)        {            systemSchemaName        = SchemaDescriptor.STD_SYSTEM_SCHEMA_NAME;            sysIBMSchemaName        = SchemaDescriptor.IBM_SYSTEM_SCHEMA_NAME;            systemDiagSchemaName    =                 SchemaDescriptor.STD_SYSTEM_DIAG_SCHEMA_NAME;            systemUtilSchemaName    =                 SchemaDescriptor.STD_SYSTEM_UTIL_SCHEMA_NAME;            declaredGlobalTemporaryTablesSchemaName =                 SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME;        }        else        {            systemSchemaName        = lcc.getSystemSchemaName();            sysIBMSchemaName        = lcc.getSysIBMSchemaName();            systemDiagSchemaName    = lcc.getSystemDiagSchemaName();            systemUtilSchemaName    = lcc.getSystemUtilSchemaName();            declaredGlobalTemporaryTablesSchemaName =                 lcc.getDeclaredGlobalTemporaryTablesSchemaName();            builtinSchemasAreFromLCC = true;        }    }    private void getBuiltinSchemas() throws StandardException    {        if( builtinSchemasAreFromLCC            && null != systemSchemaDesc            && null != sysIBMSchemaDesc            && null != systemDiagSchemaDesc            && null != systemUtilSchemaDesc            && null != declaredGlobalTemporaryTablesSchemaDesc)            return;        getBuiltinSchemaNames();		systemSchemaDesc =             newSystemSchemaDesc(                systemSchemaName, SchemaDescriptor.SYSTEM_SCHEMA_UUID);		sysIBMSchemaDesc =             newSystemSchemaDesc(                sysIBMSchemaName, SchemaDescriptor.SYSIBM_SCHEMA_UUID);		systemDiagSchemaDesc  =             newSystemSchemaDesc(                systemDiagSchemaName, SchemaDescriptor.SYSCS_DIAG_SCHEMA_UUID);		systemUtilSchemaDesc  =             newSystemSchemaDesc(                systemUtilSchemaName, SchemaDescriptor.SYSCS_UTIL_SCHEMA_UUID);		declaredGlobalTemporaryTablesSchemaDesc =             newDeclaredGlobalTemporaryTablesSchemaDesc(                declaredGlobalTemporaryTablesSchemaName);    }	/**	 * Get the descriptor for the system schema. Schema descriptors include      * authorization ids and schema ids.     *	 * SQL92 allows a schema to specify a default character set - we will	 * not support this.	 *	 * @return	The descriptor for the schema.	 *	 * @exception StandardException		Thrown on failure	 */	public SchemaDescriptor	getSystemSchemaDescriptor()						throws StandardException    {        getBuiltinSchemas();        return systemSchemaDesc;    }	/**	 * Get the descriptor for the SYSCS_UTIL system schema.      * Schema descriptors include authorization ids and schema ids.     *	 * SQL92 allows a schema to specify a default character set - we will	 * not support this.	 *	 * @return	The descriptor for the schema.	 *	 * @exception StandardException		Thrown on failure	 */	public SchemaDescriptor	getSystemUtilSchemaDescriptor()						throws StandardException    {        getBuiltinSchemas();        return(systemUtilSchemaDesc);    }	/**	 * Get the descriptor for the SYSCS_DIAG system schema.      * Schema descriptors include authorization ids and schema ids.     *	 * SQL92 allows a schema to specify a default character set - we will	 * not support this.	 *	 * @return	The descriptor for the schema.	 *	 * @exception StandardException		Thrown on failure	 */	public SchemaDescriptor	getSystemDiagSchemaDescriptor()						throws StandardException    {        getBuiltinSchemas();        return(systemDiagSchemaDesc);    }	/**	 * Get the descriptor for the SYSIBM schema. Schema descriptors include      * authorization ids and schema ids.     *	 * SQL92 allows a schema to specify a default character set - we will	 * not support this.	 *	 * @return	The descriptor for the schema.	 *	 * @exception StandardException		Thrown on failure	 */	public SchemaDescriptor	getSysIBMSchemaDescriptor()						throws StandardException    {        getBuiltinSchemas();        return sysIBMSchemaDesc;    }	/**	 * Get the descriptor for the declared global temporary table schema which      * is always named "SESSION".	 *	 * @return	The descriptor for the schema.	 *	 * @exception StandardException		Thrown on failure	 */	public SchemaDescriptor	getDeclaredGlobalTemporaryTablesSchemaDescriptor()        throws StandardException    {        getBuiltinSchemas();        return declaredGlobalTemporaryTablesSchemaDesc;    }          /**     * Determine whether a string is the name of the system schema.     *     * @param name     * @return	true or false	 *	 * @exception StandardException		Thrown on failure     */    public boolean isSystemSchemaName( String name)        throws StandardException    {        getBuiltinSchemaNames();        boolean ret_val = false;        for (int i = systemSchemaNames.length - 1; i >= 0;)        {            if ((ret_val = systemSchemaNames[i--].equals(name)))                break;        }                    return(ret_val);    }	/**	 * Get the descriptor for the named schema.	 * Schema descriptors include authorization ids and schema ids.	 * SQL92 allows a schema to specify a default character set - we will	 * not support this.  Will check default schema for a match	 * before scanning a system table.	 * 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -