3D PLM Enterprise Architecture |
Data Access - Database |
Extracting a Document from the Vault Server to a FileCopying an existing vault document to a file |
Use Case |
AbstractThis article shows how to open a document in the vault server, and copy its contents into into a file. |
This use case is intended to show you how to retrieve a document from a vault server using its URL, and copy it to a file. It also shows how to open a vault session.
[Top]
CAAEvcExtractDocIntoFile is a use case of the CAAENOVaultClientCPP.edu framework that illustrates ENOVaultClientCPP framework capabilities.
[Top]
CAAEvcExtractDocIntoFile begins by opening a vault session. Then it retrieves a vault document from an URL taken as input and copies the contents of the document to a file.
[Top]
To launch CAAEvcExtractDocIntoFile, you will need to set up the build time environment, then compile CAAEvcExtractDocIntoFile along with its prerequisites, set up the run time environment, and then execute the use case as follows: [3].
mkrun -c "CAAEvcExtractDocIntoFile -f FileName -u DocumentURL"
where:
FileName
is the full path name of the file you want to
copy the vault document toDocumentURL
is the Document URLYou can use as input the document URL generated by the CAAEvcCreateDocFromFile use case [1] or the CAAEvcCreateDocFromMemuse case [2].
[Top]
The CAAEvcExtractDocIntoFile use case is made of the single file CAAEvcExtractDocIntoFile.cpp located in the CAAEvcExtractDocIntoFile.m module of the CAAENOVaultClientCPP.edu framework:
Windows | InstallRootDirectory\CAAENOVaultClientCPP.edu\CAAEvcExtractDocIntoFile.m\ |
Unix | InstallRootDirectory/CAAENOVaultClientCPP.edu/CAAEvcExtractDocIntoFile.m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
There are eight logical steps in CAAEvcExtractDocIntoFile:
[Top]
... ENOVIVaultError VErr; CATBoolean Master = TRUE; // As the vault session is opened as master, the following arguments are // not taken into account CATUnicodeString Marker(""); CATUnicodeString Host(""); int Port = 0; ENOVIVaultSession * pSession = NULL; RC = ENOVIVaultSessionFactory::getVaultSession(Marker, Host, Port, Master, &pSession, VErr); ... |
The first thing to do is to create a vault session, thanks to the static getVaultSession
method of the ENOVIVaultSessionFactory class. The vault component
supports distributed transactions (i.e. several processes working in the context
of the same transaction) but in this case only one of the sessions is a master
one and is able to commit or rollback the transaction. As this use case is a
stand alone program, the session must necessarily be opened as master. The
useful arguments are:
Master
is set to TRUE
to indicate a master
sessionpSession
is the initialized vault session as a pointer to the
ENOVIVaultSession interfaceVErr
is an ENOVIVaultError class instance passed as
the last argument used if the method fails to convey information about the
failure.
[Top]
... ENOVIVaultDocument * pDoc = NULL; pSession->bindDocument(s_InputUrl, &pDoc, VErr); ... |
An URL contains all the necessary information enabling to retrieve a
document. The bind
Document
method of the ENOVIVaultSession
interface connects to the vault server containing the required document and
builds a vault document passed as an ENOVIVaultDocument interface
pointer.The parameters to pass to bind
Document
are:
s_InputUrl
is the URL of the document passed as a parameter
of the command that launches the use casepDoc
is the initialized document as a pointer to the ENOVIVaultDocument
interfaceVErr
is an ENOVIVaultError class instance passed as
the last argument used if the method fails to convey information about the
failure.[Top]
... RC = pDoc->openRead(VErr); ... |
Before any read operation, the document must be opened in read mode.
[Top]
... CATBoolean DeleteAtClose = CATFalse; // We don't want the file to be deleted at close RC = pDoc->copyToLocalFile(s_InputFile, DeleteAtClose, VErr); ... |
The document contents is now copied to the file. The parameter to pass to
copyToLocalFile
are:
s_InputFile
is the full path name of the file the document
will be copied to. It is passed as the first argument when launching the use
caseDeleteAtClose
is a flag to indicate whether the vault server
should delete the file when the document is closed. That can be useful when
using temporary filesVErr
is an ENOVIVaultError class instance passed as
the last argument used if the method fails to convey information about the
failure.[Top]
... RC = pDoc->close(VErr); ... |
The document must always be closed. Pay a special attention to the error management. If any kind of error occurs after a document has been opened, make sure it is closed before exiting the method in which you handle the document.
[Top]
... RC = pSession->prepare(VErr); ... |
The vault is designed to cooperate with other data servers. So it supports a two-phase commit. That means that the save operation has been split into two steps: prepare and commit. This applies to all the vault documents currently managed by all the user sessions of the vault session. When preparing and committing the transaction, a check is performed to determine whether documents are opened. If an opened document exists, it is considered as "in work" and to ensure that no document is saved in an inconsistent state, the whole save operation is aborted.
When preparing the transaction, all the necessary checks and most of the save operations are performed, the objective being to make sure that nothing will prevent from committing.
[Top]
... RC = pSession->commit(VErr); ... |
Committing the transaction is a very light operation validating what has been done when preparing the transaction. Once committed, all the modifications done since the previous commit are saved and become visible to the other users.
As no document has been modified or created in this use case, it would be equivalent to use the rollback or abort methods of the ENOVIVaultSession interface.
[Top]
... RC = ENOVIVaultSessionFactory::endVaultSession(pSession, VErr); ... |
This ends and closes the vault session.
[Top]
This use case has demonstrated how to initialize the vault environment, retrieve a vault document and copy it into a file.
ENOVIVaultSessionFactory::getVaultSession
static method that
returns a pointer to the ENOVIVaultSession interfacebindDocument
method of ENOVIVaultSession to which the document URL is passed. This
document is handled as a pointer to the ENOVIVaultDocument interface.openRead
, copyToLocalFile
,
and close
methods of ENOVIVaultDocument respectivelyprepare
and commit
methods of the ENOVIVaultSession interfaceENOVIVaultSessionFactory::endVaultSession
static method of the ENOVIVaultSession interface.[Top]
[1] | Creating a Document from a File in the Vault Server |
[2] | Creating a Document from a Memory Area in the Vault Server |
[3] | Building and Launching a CAA V5 Use Case |
[Top] |
Version: 1 [Sep 2001] | Document created |
[Top] |
Copyright © 2001, Dassault Systèmes. All rights reserved.