Class StreamFileContainer
- java.lang.Object
-
- org.apache.derby.impl.store.raw.data.StreamFileContainer
-
- All Implemented Interfaces:
java.security.PrivilegedExceptionAction<java.lang.Object>
,TypedFormat
class StreamFileContainer extends java.lang.Object implements TypedFormat, java.security.PrivilegedExceptionAction<java.lang.Object>
The format of this stream file is: (RH) (FH) (field data) (FH) (field data) ........ (FH) (field data) Record header is stored once at the beginning of the file for all the rows stored in this file. Record Header indicates how many fields are in each row. Then we just stored all the column from each row. Field header stored on this file is fixed size with fieldDataLength size set to LARGE_SLOT_SIZE (4) bytes. NOTE: No locks are used in this container. All transaction are not logged.
-
-
Field Summary
Fields Modifier and Type Field Description private int
actionCode
private StorageFile
actionStorageFile
private java.io.BufferedInputStream
bufferedIn
private int
bufferSize
private byte[]
ciphertext
private BaseDataFileFactory
dataFactory
private DecryptInputStream
decryptIn
protected static int
FIELD_HEADER_SIZE
protected static int
FIELD_STATUS
private StorageFile
file
private java.io.InputStream
fileIn
private java.io.OutputStream
fileOut
protected static int
formatIdInteger
Constant Fields of the classprotected ContainerKey
identity
Fields of the classprotected static int
LARGE_SLOT_SIZE
private LimitInputStream
limitIn
private FormatIdInputStream
logicalDataIn
private FormatIdOutputStream
logicalDataOut
protected static int
MIN_BUFFER_SIZE
private DynamicByteArrayOutputStream
out
private StoredRecordHeader
recordHeader
private static int
STORAGE_FILE_DELETE_ACTION
private static int
STORAGE_FILE_EXISTS_ACTION
private static int
STORAGE_FILE_GET_INPUT_STREAM_ACTION
private static int
STORAGE_FILE_GET_OUTPUT_STREAM_ACTION
private static int
STORAGE_FILE_MKDIRS_ACTION
private byte[]
zeroBytes
-
Constructor Summary
Constructors Constructor Description StreamFileContainer(ContainerKey identity, BaseDataFileFactory dataFactory)
Constructor.StreamFileContainer(ContainerKey identity, BaseDataFileFactory dataFactory, java.util.Properties prop)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
close()
Close the stream file.boolean
fetchNext(java.lang.Object[] row)
void
getContainerProperties(java.util.Properties prop)
Request the system properties associated with a stream container.private static ContextService
getContextService()
Privileged lookup of the ContextService.protected StorageFile
getFileName(ContainerKey identity, boolean forCreate, boolean errorOK)
Return a file name for the identity.ContainerKey
getIdentity()
Request the container key associated with the stream container.private static java.lang.Object
getServiceModule(java.lang.Object serviceModule, java.lang.String factoryInterface)
Privileged module lookup.int
getTypeFormatId()
Return my format identifier.void
load(RowSource rowSource)
load data into this container.protected StreamFileContainer
open(boolean forUpdate)
Open a stream file container.private boolean
privDelete(StorageFile file)
private boolean
privExists(StorageFile file)
private java.io.InputStream
privGetInputStream(StorageFile file)
private java.io.OutputStream
privGetOutputStream(StorageFile file)
private boolean
privMkdirs(StorageFile file)
boolean
removeContainer()
Close the stream file and remove the file.java.lang.Object
run()
protected boolean
use(StreamContainerHandle handle)
Can I use this container?private void
writeColumn(java.lang.Object column)
private void
writeToFile()
Write the buffer to the file.
-
-
-
Field Detail
-
formatIdInteger
protected static int formatIdInteger
Constant Fields of the class
-
LARGE_SLOT_SIZE
protected static final int LARGE_SLOT_SIZE
- See Also:
- Constant Field Values
-
MIN_BUFFER_SIZE
protected static final int MIN_BUFFER_SIZE
- See Also:
- Constant Field Values
-
FIELD_STATUS
protected static final int FIELD_STATUS
-
FIELD_HEADER_SIZE
protected static final int FIELD_HEADER_SIZE
-
identity
protected ContainerKey identity
Fields of the class
-
dataFactory
private BaseDataFileFactory dataFactory
-
bufferSize
private int bufferSize
-
file
private StorageFile file
-
fileOut
private java.io.OutputStream fileOut
-
out
private DynamicByteArrayOutputStream out
-
logicalDataOut
private FormatIdOutputStream logicalDataOut
-
fileIn
private java.io.InputStream fileIn
-
bufferedIn
private java.io.BufferedInputStream bufferedIn
-
decryptIn
private DecryptInputStream decryptIn
-
limitIn
private LimitInputStream limitIn
-
logicalDataIn
private FormatIdInputStream logicalDataIn
-
recordHeader
private StoredRecordHeader recordHeader
-
ciphertext
private byte[] ciphertext
-
zeroBytes
private byte[] zeroBytes
-
STORAGE_FILE_EXISTS_ACTION
private static final int STORAGE_FILE_EXISTS_ACTION
- See Also:
- Constant Field Values
-
STORAGE_FILE_DELETE_ACTION
private static final int STORAGE_FILE_DELETE_ACTION
- See Also:
- Constant Field Values
-
STORAGE_FILE_MKDIRS_ACTION
private static final int STORAGE_FILE_MKDIRS_ACTION
- See Also:
- Constant Field Values
-
STORAGE_FILE_GET_OUTPUT_STREAM_ACTION
private static final int STORAGE_FILE_GET_OUTPUT_STREAM_ACTION
- See Also:
- Constant Field Values
-
STORAGE_FILE_GET_INPUT_STREAM_ACTION
private static final int STORAGE_FILE_GET_INPUT_STREAM_ACTION
- See Also:
- Constant Field Values
-
actionCode
private int actionCode
-
actionStorageFile
private StorageFile actionStorageFile
-
-
Constructor Detail
-
StreamFileContainer
StreamFileContainer(ContainerKey identity, BaseDataFileFactory dataFactory)
Constructor.- Throws:
StandardException
- Standard exception policy.
-
StreamFileContainer
StreamFileContainer(ContainerKey identity, BaseDataFileFactory dataFactory, java.util.Properties prop) throws StandardException
Constructorwhen rowSource is passed to the constructor, it will be loaded into the container after the container has been created.
- Throws:
StandardException
- Standard exception policy.
-
-
Method Detail
-
open
protected StreamFileContainer open(boolean forUpdate) throws StandardException
Open a stream file container.Open a container. Open the file that maps to this container, if the file does not exist then we assume the container was never created and return. If the file exists but we have trouble opening it then we throw some exception.
- Parameters:
forUpdate
- Currently only accepts false, updating and existing stream file container is not currently supported.- Returns:
- The opened StreamFileContainer.
- Throws:
StandardException
- Standard exception policy.
-
close
protected void close()
Close the stream file.Close this stream file, and all streams associated with it.
-
getTypeFormatId
public int getTypeFormatId()
Return my format identifier.- Specified by:
getTypeFormatId
in interfaceTypedFormat
- Returns:
- The identifier. (A UUID stuffed in an array of 16 bytes).
-
getContainerProperties
public void getContainerProperties(java.util.Properties prop) throws StandardException
Request the system properties associated with a stream container.Request the value of properties associated with a stream container. The following properties can be requested: derby.storage.streamFileBufferSize
To get the value of a particular property add it to the property list, and on return the value of the property will be set to it's current value. For example: get_prop(ConglomerateController cc) { Properties prop = new Properties(); prop.put("derby.storage.streamFileBufferSize", ""); cc.getContainerProperties(prop); System.out.println( "stream table's buffer size = " + prop.getProperty("derby.storage.streamFileBufferSize"); }
- Parameters:
prop
- Property list to fill in.- Throws:
StandardException
- Standard exception policy.
-
getIdentity
public ContainerKey getIdentity()
Request the container key associated with the stream container.
-
use
protected boolean use(StreamContainerHandle handle) throws StandardException
Can I use this container?This method always return true right now. In the future when there are different uses for this container, we may need to add qualifications for this.
- Throws:
StandardException
- Standard exception policy.
-
load
public void load(RowSource rowSource) throws StandardException
load data into this container.populate the stream container with data in the rowSource
- Parameters:
rowSource
- The row source to get rows to load into this container.- Throws:
StandardException
- Standard exception policy.
-
writeToFile
private void writeToFile() throws StandardException
Write the buffer to the file.If the database is encrypted, the dataFactory.getEncryptionBlockSize() - 1 reserved bytes will be used to pad the byte array to be dataFactory.getEncryptionBlockSize() aligned. Before the bytes are encrypted and written to the file stream, the actual length of the byte array is written out as a compressed integer. This number will be used when decrypting the data. If the database is not encrypted, then, we don't reserve the bytes upfront, and we simple just write the bytes out to the file stream.
- Throws:
StandardException
- Standard exception policy.
-
writeColumn
private void writeColumn(java.lang.Object column) throws StandardException, java.io.IOException
- Throws:
StandardException
java.io.IOException
-
fetchNext
public boolean fetchNext(java.lang.Object[] row) throws StandardException
- Throws:
StandardException
-
removeContainer
public boolean removeContainer() throws StandardException
Close the stream file and remove the file.- Throws:
StandardException
- Segment directory cannot be created
-
getFileName
protected StorageFile getFileName(ContainerKey identity, boolean forCreate, boolean errorOK) throws StandardException
Return a file name for the identity.Return a valid file name for the identity, or null if the data directory for this segment cannot be created
- Throws:
StandardException
- Segment directory cannot be created
-
privExists
private boolean privExists(StorageFile file)
-
privMkdirs
private boolean privMkdirs(StorageFile file) throws java.io.IOException
- Throws:
java.io.IOException
-
privDelete
private boolean privDelete(StorageFile file)
-
privGetOutputStream
private java.io.OutputStream privGetOutputStream(StorageFile file) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
privGetInputStream
private java.io.InputStream privGetInputStream(StorageFile file) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
run
public java.lang.Object run() throws java.io.IOException
- Specified by:
run
in interfacejava.security.PrivilegedExceptionAction<java.lang.Object>
- Throws:
java.io.IOException
-
getContextService
private static ContextService getContextService()
Privileged lookup of the ContextService. Must be private so that user code can't call this entry point.
-
getServiceModule
private static java.lang.Object getServiceModule(java.lang.Object serviceModule, java.lang.String factoryInterface)
Privileged module lookup. Must be private so that user code can't call this entry point.
-
-