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

📄 embedconnection.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		if (isClosed())			throw Util.noCurrentConnection();		getTR().setupContextStack();	}	protected final void restoreContextStack() throws SQLException {		if (SanityManager.DEBUG)		Util.ASSERT(this, (active) || getTR().getCsf() !=null, "No context service to do restore");		TransactionResourceImpl tr = getTR();		//REMIND: someone is leaving an incorrect manager on when they		// are exiting the system in the nested case.		if (SanityManager.DEBUG)		{			if ((tr.getCsf() != null) && (tr.getCsf().getCurrentContextManager() !=				tr.getContextManager()))			{				Util.THROWASSERT(this, 					"Current Context Manager not the one was expected: " +					 tr.getCsf().getCurrentContextManager() + " " + 					 tr.getContextManager());			}		}		tr.restoreContextStack();	}	/*	** Create database methods.	*/	/**		Create a new database.		@param dbname the database name		@param info the properties		@return	Database The newly created database or null.	 	@exception SQLException if fails to create database	*/	private Database createDatabase(String dbname, Properties info)		throws SQLException {		info = filterProperties(info);		try {			if (Monitor.createPersistentService(Property.DATABASE_MODULE, dbname, info) == null) 			{				// service already exists, create a warning				addWarning(EmbedSQLWarning.newEmbedSQLWarning(SQLState.DATABASE_EXISTS, dbname));			}		} catch (StandardException mse) {			SQLException se = newSQLException(SQLState.CREATE_DATABASE_FAILED, dbname);			se.setNextException(handleException(mse));			throw se;		}		// clear these values as some modules hang onto		// the properties set corresponding to service.properties		// and they shouldn't be interested in these JDBC attributes.		info.clear();		return (Database) Monitor.findService(Property.DATABASE_MODULE, dbname);	}	/**		Return false iff the monitor cannot handle a service		of the type indicated by the protocol within the name.		If that's the case then we are the wrong driver.		Throw exception if anything else is wrong.	 */	private boolean bootDatabase(Properties info) throws Throwable	{		String dbname = tr.getDBName();		// boot database now		try {			info = filterProperties(info);						// try to start the service if it doesn't already exist			if (!Monitor.startPersistentService(dbname, info)) {				// a false indicates the monitor cannot handle a service				// of the type indicated by the protocol within the name.				// If that's the case then we are the wrong driver				// so just return null.				return false;			}			// clear these values as some modules hang onto			// the properties set corresponding to service.properties			// and they shouldn't be interested in these JDBC attributes.			info.clear();			Database database = (Database) Monitor.findService(Property.DATABASE_MODULE, dbname);			tr.setDatabase(database);		} catch (StandardException mse) {			SQLException se = newSQLException(SQLState.BOOT_DATABASE_FAILED, dbname);			Throwable ne = mse.getNestedException();			SQLException nse;			/*			  If there is a next exception, assume			  that the first one is just a redundant "see the			  next exception" message.			  if it is a BEI, treat it as a database exception.			  If there isn't a BEI, treat it as a java exception.			  In general we probably want to walk the chain			  and return all of them, but empirically, this			  is all we need to do for now.			  */			if (ne instanceof StandardException)				nse = Util.generateCsSQLException((StandardException)ne);			else if (ne != null)				nse = Util.javaException(ne);			else				nse = Util.generateCsSQLException(mse);			se.setNextException(nse);			throw se;		}		// If database exists, getDatabase() will return the database object.		// If any error occured while booting an existing database, an		// exception would have been thrown already.		return true;	}	/*	 * Class interface methods used by database metadata to ensure	 * good relations with autocommit.	 */    PreparedStatement prepareMetaDataStatement(String sql)	    throws SQLException {		synchronized (getConnectionSynchronization()) {                        setupContextStack();			PreparedStatement s = null;			try {			    s = factory.newEmbedPreparedStatement(this, sql, true,											  JDBC20Translation.TYPE_FORWARD_ONLY,											  JDBC20Translation.CONCUR_READ_ONLY,											  connectionHoldAbility,											  JDBC30Translation.NO_GENERATED_KEYS,											  null,											  null);			} finally {			    restoreContextStack();			}			return s;		}	}	public final InternalDriver getLocalDriver()	{		if (SanityManager.DEBUG)			SanityManager.ASSERT(!isClosed(), "connection is closed");		return getTR().getDriver();	}	/**		Return the context manager for this connection.	*/	public final ContextManager getContextManager() {		if (SanityManager.DEBUG)			SanityManager.ASSERT(!isClosed(), "connection is closed");		return getTR().getContextManager();	}	private Properties filterProperties(Properties inputSet) {		Properties limited = new Properties();		// filter out any derby.* properties, only		// JDBC attributes can be set this way		for (java.util.Enumeration e = inputSet.propertyNames(); e.hasMoreElements(); ) {			String key = (String) e.nextElement();			// we don't allow properties to be set this way			if (key.startsWith("derby."))				continue;			limited.put(key, inputSet.getProperty(key));		}		return limited;	}	/*	** methods to be overridden by subimplementations wishing to insert	** their classes into the mix.	*/	protected Database getDatabase() 	{		if (SanityManager.DEBUG)			SanityManager.ASSERT(!isClosed(), "connection is closed");		return getTR().getDatabase();	}	final protected TransactionResourceImpl getTR()	{		return rootConnection.tr;	}	private EmbedConnectionContext pushConnectionContext(ContextManager cm) {		return new EmbedConnectionContext(cm, this);	}	public final void setApplicationConnection(java.sql.Connection applicationConnection) {		this.applicationConnection = applicationConnection;	}	public final java.sql.Connection getApplicationConnection() {		return applicationConnection;	}	public void setDrdaID(String drdaID) {		getLanguageConnection().setDrdaID(drdaID);	}	/**		Reset the connection before it is returned from a PooledConnection		to a new application request (wrapped by a BrokeredConnection).		Examples of reset covered here is dropping session temporary tables		and reseting IDENTITY_VAL_LOCAL.		Most JDBC level reset is handled by calling standard java.sql.Connection		methods from EmbedPooledConnection.	 */	public void resetFromPool() throws SQLException {		synchronized (getConnectionSynchronization())		{			setupContextStack();			try {				getLanguageConnection().resetFromPool();			} catch (StandardException t) {				throw handleException(t);			}			finally			{				restoreContextStack();			}		}	}	/*	** methods to be overridden by subimplementations wishing to insert	** their classes into the mix.	** The reason we need to override them is because we want to create a	** Local20/LocalStatment object (etc) rather than a Local/LocalStatment	** object (etc).	*/	/*	** XA support	*/	public final int xa_prepare() throws SQLException {		synchronized (getConnectionSynchronization())		{            setupContextStack();			try			{				XATransactionController tc = 					(XATransactionController) getLanguageConnection().getTransactionExecute();				int ret = tc.xa_prepare();				if (ret == XATransactionController.XA_RDONLY)				{					// On a prepare call, xa allows an optimization that if the					// transaction is read only, the RM can just go ahead and					// commit it.  So if store returns this read only status -					// meaning store has taken the liberty to commit already - we					// needs to turn around and call internalCommit (without					// committing the store again) to make sure the state is					// consistent.  Since the transaction is read only, there is					// probably not much that needs to be done.					getLanguageConnection().internalCommit(false /* don't commitStore again */);				}				return ret;			} catch (StandardException t)			{				throw handleException(t);			}			finally			{				restoreContextStack();			}		}	}	public final void xa_commit(boolean onePhase) throws SQLException {		synchronized (getConnectionSynchronization())		{            setupContextStack();			try			{		    	getLanguageConnection().xaCommit(onePhase);			} catch (StandardException t)			{				throw handleException(t);			}			finally 			{				restoreContextStack();			}		}	}	public final void xa_rollback() throws SQLException {		synchronized (getConnectionSynchronization())		{            setupContextStack();			try			{		    	getLanguageConnection().xaRollback();			} catch (StandardException t)			{				throw handleException(t);			}			finally 			{				restoreContextStack();			}		}	}	/**	 * returns false if there is an underlying transaction and that transaction	 * has done work.  True if there is no underlying transaction or that	 * underlying transaction is idle	 */	public final boolean transactionIsIdle()	{		return getTR().isIdle();	}	private int setResultSetType(int resultSetType) {		/* Add warning if scroll sensitive cursor		 * and downgrade to scroll insensitive cursor.		 */		if (resultSetType == JDBC20Translation.TYPE_SCROLL_SENSITIVE)		{			addWarning(EmbedSQLWarning.newEmbedSQLWarning(SQLState.NO_SCROLL_SENSITIVE_CURSORS));			resultSetType = JDBC20Translation.TYPE_SCROLL_INSENSITIVE;		}		return resultSetType;	}	private int setResultSetConcurrency(int resultSetType, int resultSetConcurrency) {		/* Add warning if updatable resultset is requested on cursor type other than forward only		 * and then downgrade the resultset to read only resultset.		 */		if (resultSetType != JDBC20Translation.TYPE_FORWARD_ONLY && resultSetConcurrency == JDBC20Translation.CONCUR_UPDATABLE)		{			addWarning(EmbedSQLWarning.newEmbedSQLWarning(SQLState.UPDATABLE_RESULTSET_FOR_FORWARD_ONLY));			resultSetConcurrency = JDBC20Translation.CONCUR_READ_ONLY;		}		return resultSetConcurrency;	}		/** 	 * Set the transaction isolation level that will be used for the 	 * next prepare.  Used by network server to implement DB2 style 	 * isolation levels.	 * @param level Isolation level to change to.  level is the DB2 level	 *               specified in the package names which happen to correspond	 *               to our internal levels. If 	 *               level == ExecutionContext.UNSPECIFIED_ISOLATION,	 *               the statement won't be prepared with an isolation level.	 * 	 * 	 */	public void setPrepareIsolation(int level) throws SQLException	{		if (level == getPrepareIsolation())			return;		switch (level)		{			case ExecutionContext.READ_UNCOMMITTED_ISOLATION_LEVEL:			case ExecutionContext.REPEATABLE_READ_ISOLATION_LEVEL:			case ExecutionContext.READ_COMMITTED_ISOLATION_LEVEL:			case ExecutionContext.SERIALIZABLE_ISOLATION_LEVEL:			case ExecutionContext.UNSPECIFIED_ISOLATION_LEVEL:				break;			default:				throw Util.generateCsSQLException(															   SQLState.UNIMPLEMENTED_ISOLATION_LEVEL, new Integer(level));		}				synchronized(getConnectionSynchronization())		{			getLanguageConnection().setPrepareIsolationLevel(level);		}	}	/**	 * Return prepare isolation 	 */	public int getPrepareIsolation()	{		return getLanguageConnection().getPrepareIsolationLevel();	}	/**		Return a unique order number for a result set.		A unique value is only needed if the result set is		being created within procedure and thus must be using		a nested connection.	*/	final int getResultSetOrderId() {		if (this == rootConnection) {			return 0;		} else {			return rootConnection.resultSetId++;		}	}	protected SQLException newSQLException(String messageId) {		return Util.generateCsSQLException(messageId);	}	protected SQLException newSQLException(String messageId, Object arg1) {		return Util.generateCsSQLException(messageId, arg1);	}	protected SQLException newSQLException(String messageId, Object arg1, Object arg2) {		return Util.generateCsSQLException(messageId, arg1, arg2);	}	/////////////////////////////////////////////////////////////////////////	//	//	OBJECT OVERLOADS	//	/////////////////////////////////////////////////////////////////////////    /**     * Get a String representation that uniquely identifies     * this connection     *     * In Derby the "physical" connection is a LanguageConnectionContext,      * or LCC.     * The JDBC Connection is an JDBC-specific layer on top of this.  Rather     * than create a new id here, we simply use the id of the underlying LCC.     * Note that this is a big aid in debugging, because much of the     * engine trace and log code prints the LCC id.      *     * @return a string representation of the unique id for the     *    underlying LanguageConnectionContext     */    public String toString()    {        if ( idString == null )        {            idString =               Integer.toString(getLanguageConnection().getInstanceNumber());        }                return idString;    }}

⌨️ 快捷键说明

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