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

📄 streamfilecontainer.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        {			// Get the number of columns in the row.			int numberFields = recordHeader.getNumberFields();			int arrayPosition = 0;			for (columnId = 0; columnId < numberFields; columnId++)             {				if (arrayPosition >= row.length)					break;					limitIn.clearLimit();				// read the field header				int fieldStatus = StoredFieldHeader.readStatus(logicalDataIn);				int fieldDataLength = StoredFieldHeader.readFieldDataLength(					logicalDataIn, fieldStatus, LARGE_SLOT_SIZE);				limitIn.setLimit(fieldDataLength);				if (SanityManager.DEBUG)                 {                    if (StoredFieldHeader.isExtensible(fieldStatus))                    {                        SanityManager.THROWASSERT(                            "extensible fields not supported yet.  columnId = "                            + columnId);                    }					SanityManager.ASSERT(!StoredFieldHeader.isOverflow(fieldStatus),						"overflow field is not supported yet");				}				Object column = row[arrayPosition];								// Deal with Storable columns				if (StoredFieldHeader.isNullable(fieldStatus))                 {														if (column == null)                    {						throw StandardException.newException(                                SQLState.DATA_NULL_STORABLE_COLUMN,                                 Integer.toString(columnId));                    }					// SRW-DJD RESOLVE: - fix error message					if (!(column instanceof Storable))                     {						throw StandardException.newException(                            SQLState.DATA_NULL_STORABLE_COLUMN,                             column.getClass().getName());					}					Storable sColumn = (Storable) column;					// is the column null ?					if (StoredFieldHeader.isNull(fieldStatus))                     {						sColumn.restoreToNull();						arrayPosition++;						continue;					}					inUserCode = true;					sColumn.readExternal(logicalDataIn);					inUserCode = false;					arrayPosition++;					continue;				}				// Only Storables can be null ... SRW-DJD RESOLVE: - fix error message				if (StoredFieldHeader.isNull(fieldStatus))                {					throw StandardException.newException(                        SQLState.DATA_NULL_STORABLE_COLUMN,                         Integer.toString(columnId));                }				// This is a non-extensible field, which means the caller must                 // know the correct type and thus the element in row is the                 // correct type or null. If the element implements                 // Externalizable then we can just fill it in, otherwise it                 // must be Serializable and we have to throw it away.				Object neColumn = row[arrayPosition];				if (neColumn instanceof Externalizable)                 {					Externalizable exColumn = (Externalizable) neColumn;					inUserCode = true;					exColumn.readExternal(logicalDataIn);					inUserCode = false;					arrayPosition++;					continue;				}				// neColumn will be ignored				neColumn = null;				inUserCode = true;				row[arrayPosition] = logicalDataIn.readObject();				inUserCode = false;				arrayPosition++;				continue;			}		}         catch (IOException ioe)         {			// an exception during the restore of a user column, this doesn't			// make the databse corrupt, just that this field is inaccessable			if (inUserCode)             { 				if (ioe instanceof EOFException)                 {					throw StandardException.newException(                        SQLState.DATA_STORABLE_READ_MISMATCH,                         ioe, logicalDataIn.getErrorInfo());				}				throw StandardException.newException(                    SQLState.DATA_STORABLE_READ_EXCEPTION,                     ioe, logicalDataIn.getErrorInfo());			}			if (ioe instanceof InvalidClassException)            {				throw StandardException.newException(                        SQLState.DATA_STORABLE_READ_EXCEPTION,                         ioe, logicalDataIn.getErrorInfo());   			}			// If we are at the end of the file, trying to fetch the first             // column, then we know there is no more rows to fetch			if ((ioe instanceof EOFException) && (columnId == 0))             {				close();				return false;			}			throw dataFactory.markCorrupt(                StandardException.newException(                    SQLState.DATA_CORRUPT_STREAM_CONTAINER, ioe, identity));		}         catch (ClassNotFoundException cnfe)         {			if (SanityManager.DEBUG)             {				SanityManager.ASSERT(inUserCode);			}			// an exception during the restore of a user column, this doesn't			// make the databse corrupt, just that this field is inaccessable			throw StandardException.newException(                SQLState.DATA_STORABLE_READ_MISSING_CLASS, cnfe,                 logicalDataIn.getErrorInfo());		}         catch (LinkageError le)         {			if (inUserCode)            {				throw StandardException.newException(                    SQLState.DATA_STORABLE_READ_EXCEPTION, le,                    logicalDataIn.getErrorInfo());            }			throw le;		}		return true;	}    /**     * Close the stream file and remove the file.     *     * @exception StandardException Segment directory cannot be created     **/	public boolean removeContainer()         throws StandardException     {		close();        if (privExists(file))        {            return privDelete(file);        }        else        {            return true;        }	}    /**     * Return a file name for the identity.     * <p>     * Return a valid file name for the identity, or null if the data     * directory for this segment cannot be created     *	 * @exception StandardException Segment directory cannot be created     **/	protected StorageFile getFileName(    ContainerKey    identity,     boolean         forCreate,     boolean         errorOK)		 throws StandardException     {		if (identity.getSegmentId() == StreamContainerHandle.TEMPORARY_SEGMENT)        {			return( dataFactory.storageFactory.newStorageFile( dataFactory.storageFactory.getTempDir(),                     "T" + identity.getContainerId() + ".tmp"));        }		else         {			if (SanityManager.DEBUG)				SanityManager.THROWASSERT(                    "cannot create stream container in non-temp segments yet.");			StorageFile container = dataFactory.getContainerPath( identity, false);			if (!privExists(container))             {				if (!forCreate)					return null;				StorageFile directory = container.getParentDir();				if (!privExists(directory))                 {					// make sure only 1 thread can create a segment at one time					synchronized(dataFactory)                     {						if (!privExists(directory))                         {							if (!privMkdirs(directory))                             {								if (errorOK)									return null;								else									throw StandardException.newException(                                            SQLState.FILE_CANNOT_CREATE_SEGMENT,                                            directory);							}						}					}				}			}			return container;		}	}        private synchronized boolean privExists(StorageFile file)    {        actionCode = STORAGE_FILE_EXISTS_ACTION;        actionStorageFile = file;        try        {            Object ret = AccessController.doPrivileged( this);            return ((Boolean) ret).booleanValue();        }catch( PrivilegedActionException pae)         {             // method executed under this priveleged block             // does not throw an exception            return false;        }         finally        {            actionStorageFile = null;        }    }    private synchronized boolean privMkdirs(StorageFile file)    {        actionCode = STORAGE_FILE_MKDIRS_ACTION;        actionStorageFile = file;        try        {            Object ret = AccessController.doPrivileged( this);            return ((Boolean) ret).booleanValue();        }catch( PrivilegedActionException pae)         {            // method executed under this priveleged block             // does not throw an exception            return false;        }         finally        {            actionStorageFile = null;        }    }        private synchronized boolean privDelete(StorageFile file)    {        actionCode = STORAGE_FILE_DELETE_ACTION;        actionStorageFile = file;        try        {            Object ret = AccessController.doPrivileged( this);            return ((Boolean) ret).booleanValue();        }catch( PrivilegedActionException pae)         {             // method executed under this priveleged block             // does not throw an exception            return false;        }         finally        {            actionStorageFile = null;        }    }    private synchronized OutputStream privGetOutputStream(StorageFile file)        throws FileNotFoundException    {        actionCode = STORAGE_FILE_GET_OUTPUT_STREAM_ACTION;        actionStorageFile = file;        try        {            return (OutputStream) AccessController.doPrivileged( this);        }catch( PrivilegedActionException pae)         {             throw (FileNotFoundException)pae.getException();        }         finally        {            actionStorageFile = null;        }    }    private synchronized InputStream privGetInputStream(StorageFile file)        throws FileNotFoundException    {        actionCode = STORAGE_FILE_GET_INPUT_STREAM_ACTION;        actionStorageFile = file;        try        {            return (InputStream) AccessController.doPrivileged( this);        }catch( PrivilegedActionException pae)         {             throw (FileNotFoundException)pae.getException();        }         finally        {            actionStorageFile = null;        }    }    // PrivilegedAction method    public Object run() throws FileNotFoundException    {        switch(actionCode)        {        case STORAGE_FILE_EXISTS_ACTION:            return ReuseFactory.getBoolean(actionStorageFile.exists());        case STORAGE_FILE_DELETE_ACTION:            return ReuseFactory.getBoolean(actionStorageFile.delete());        case STORAGE_FILE_MKDIRS_ACTION:            return ReuseFactory.getBoolean(actionStorageFile.mkdirs());        case STORAGE_FILE_GET_OUTPUT_STREAM_ACTION:            return actionStorageFile.getOutputStream();        case STORAGE_FILE_GET_INPUT_STREAM_ACTION:            return actionStorageFile.getInputStream();        }        return null;    }}

⌨️ 快捷键说明

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