Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

In this post I will describe what is module storage and how to use it.


Module storage service enables storage and retrieval of the module instance's runtime content. This storage service is designed only for module instances. Other components, such as module templates, should not use it.


Every module instance can use this service, when the lifecycle of the storage is handled by the service itself, so that module instances do not need to create or delete the storage. The storage is automatically created on the first request, and destroyed when the instance is deleted from the workspace (when a module is removed from a workspace, its storage is removed automatically). However, you can destroy the storage explicitly.


It provides significant benefits in terms of performance and maintenance, rather than PCD storage directly in the iView properties.


Today in enterprise workspaces, we use module storage in the TextPad, Link-List and Document List  modules in order to save texts, links, etc.


Another benefit is that during workspace transport, the storage of each module is included in the transport package.

How is the content saved in module storage?


The content is saved as a stream.


Let’s look at the following link list module and check how the content is saved in module storage:

<Link title="SAP" type="web" target="http://www.sap.com"/><Link title="Google" type="web" target="http://www.google.com "/><Link title="ynet" type="web" target="http://www.ynet.co.il"/>

Interfaces Summary:

Now, let’s take a look at the public interfaces:

IModuleStorage 

Provides storage for the runtime content of a module instance.


IModuleStorageFactory

Enables storage and retrieval of the module instance's runtime content.


As an example let's take this piece of code which illustrates how to access and use module storage using the public interfaces mentioned above:

private void storeModuleRuntimeContent(IPortalComponentRequest request)

{

// Get module storage factory

IWorkspacesRuntime workspacesRuntime = RuntimeFactory.getWorkspacesRuntime();

IModuleStorageFactory storageFactory = (IModuleStorageFactory)            

              workspacesRuntime.getService(IModuleStorageFactory.class);

IModuleContext moduleContext = ModuleHelper.getModuleContext(request);

//Returns the storage for this module instance; if the storage does not exist, creates it

IModuleStorage storage = storageFactory.getStorage(moduleContext);

// Get string content

String value = storage.getProperty("key");

// Store string content

            storage.setProperty("key", "value");

// Store binary property

byte[] myBinaryData = "myBinaryData".getBytes();

            storage.setBinaryProperty("key", new ByteArrayInputStream(myBinaryData));

}

Good Luck!

Go back to: A Deep Dive into SAP NetWeaver Portal, Enterprise Workspaces (Main TOC blog)