Home | Table of Contents | JavaMapWriter | CloverETL 4.6.1
--- | --- | ---
Prev | Writers | Next

## JavaMapWriter

# Not available in Community Designer

Short Description
Ports
JavaMapWriter Attributes
Details
See also

### Short Description

JavaMapWriter writes JavaBeans (represented as `HashMaps`) into a dictionary. That allows dynamic data interchange between Clover graphs and external environment, such as cloud. The component is a specific implementation of JavaBeanWriter which allows easier mapping. Maps are less restrictive than Beans: there are no data types and type conversion is missing. This gives JavaMapWriter a greater flexibility - it always writes data types into Maps just as they were defined in metadata. However, its lower overheads come at the cost of accidental reading a different data type than desired (e.g. if you write `string` into a Map and then read it back as `integer` with JavaBeanReader, the graph fails).

Component | Data output | Input ports | Output ports | Each to all outputs | Different to different outputs | Transformation | Transf. req. | Java | CTL | Auto-propagated metadata
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
JavaMapWriter | dictionary | 1-n | 0 |  |  |  |  |  |  |

### Icon

### Ports

Port type | Number | Required | Description | Metadata
--- | --- | --- | --- | ---
Input | 0-N | At least one | Input records to be joined and mapped to Java Maps. | Any (each port can have different metadata)

### JavaMapWriter Attributes

Attribute | Req | Description | Possible values
--- | --- | --- | ---
Basic
Dictionary target | yes | The dictionary you want to write Java Maps to. |
Mapping | [1] | Defines how input data is mapped onto output Java Maps. See Details. |
Mapping URL | [1] | External text file containing the mapping definition. |
Advanced
Cache size |  | A size of of the database used when caching data from ports to elements (the data is first processed then written). The larger your data is, the larger cache is needed to maintain fast processing. | auto (default) | e.g. 300MB, 1GB etc.
Cache in Memory |  | Cache data records in memory instead of disk cache. Note that while it is possible to set maximal size of the cache for the disk cache, this setting is ignored in case in-memory-cache si used. As a result, an OutOfMemoryError may occur when caching too many data records. | true | false (default)
Sorted input |  | Tells JavaMapWriter whether the input data is sorted. Setting the attribute to true declares you want to use the sort order defined in Sort keys, see below. | false (default) | true
Sort keys |  | Tells JavaMapWriter how the input data is sorted, thus enabling streaming. The sort order of fields can be given for each port in a separate tab. Working with Sort keys has been described in Sort Key. |
Max number of records |  | Maximum number of records written to all output files. See Selecting Output Records. | 0-N
[1] One of these has to be specified. If both are specified, Mapping URL has a higher priority.

### Details

JavaMapWriter component receives data through all connected input ports and converts data records to Java `HashMaps` based on the mapping you define. At last, the component writes the resulting tree structure of elements to Maps.

The logic of mapping is similar to XMLWriter - if you are familiar with its mapping editor, you will have no problems designing the output tree in this component. The differences are:

- JavaMapWriter allows you to map arrays

- there are no attributes as in XML

Remember the component cannot write to a file - the only possible output is dictionary.

You map the input records to the output dictionary in a manner which is very close to what you already know from XMLWriter. Mapping editors in both components have similar logic. The very basics of mapping are:

- Connect input edges to JavaMapWriter and edit the component's Mapping attribute. This will open the visual mapping editor:

  Figure 49.11. Mapping editor in JavaMapWriter after first open. Metadata on the input edge(s) are displayed on the left hand side. The right hand pane is where you design the desired output tree. Mapping is then performed by dragging metadata from left to right (and performing additional tasks described below).

- In the right hand pane, design your output tree structure consisting of

  - Elements

    | Important
    Unlike XMLWriter, you do not map metadata to any 'attributes'.

  - Arrays - arrays are ordered sets of values. To learn how to map them in, see Example 49.4, “Writing arrays”.

  - Wildcard elements - another option to mapping elements explicitly. You use the Include and Exclude patterns to generate element names from respective metadata.

- Connect input records to output (wildcard) elements to create Binding.

  Example 49.3. Creating Binding

  Figure 49.12. Example mapping in JavaMapWriter - employees are joined with projects they work on. Fields in bold (their content) will be printed to the output dictionary.

  | Note
  If you extended your graph and had the output dictionary written to the console, you would get a structure like this. This excerpt is just to demonstrate how Java Maps, mapped in the figure above, are stored internally:
      				  [{employees=[{projects=[{manager=John Major, start=01062005,
      				  name=Data warehouse, customers=[Hanuman, Weblea, SomeBank], end=31052006}],
      				  lastName=Fish, firstName=Mark}, {projects=[{manager=John Smith, start=06062006,
      				  name=JSP, customers=[Sunny, Weblea], end=in progress}, {manager=Raymond Brown,
      				  start=11052004, name=OLAP, customers=[Sunny], end=31012006}], lastName=Simson,
      				  firstName=Jane}, {projects=[{manager=John Major, start=01062005,
      				  name=Data warehouse, customers=[Hanuman, Weblea, SomeBank], end=31052006},
      				  {manager=Raymond Brown, start=11052004, name=OLAP, customers=[Sunny], end=31012006},
      				  {manager=Brandon Morrison, start=01032006, name=Javascripting,
      				  customers=[Nestele, Traincorp, AnotherBank, Intershop], end=in progress}],
      				  lastName=Morrison, firstName=Brandon}]}]

  Example 49.4. Writing arrays

  Let us have the following mapping of the input file which contains information about actors. For explanatory reasons, we will part actors' personal data from their countries of origin. The summary of all countries will then be written into an array:

  Figure 49.13. Mapping arrays in JavaMapWriter - notice the array contains a dummy element 'State' which you bind the input field to.

  The array will be written to Maps as e.g.:

      				[ ...
      				Summary={Countries=[USA, ESP, ENG]}}]

- At any time, you can switch to the Source tab and write/check the mapping yourself in code.

- If the basic instructions found here were not satisfying, please consult XMLWriter's Details where the whole mapping process is described profusely.

### See also

Common Properties of Components
Specific Attribute Types
Common Properties of Writers
Writers Comparison

Prev | Up | Next
JavaBeanWriter | Home | Table of Contents | JMSWriter