Please enable JavaScript to view this site.

InterFormNG Manual 2020

Navigation: InterFormNG Inputs > Database Input

Transfer meta data from a DB into NG

Scroll Prev Top Next More

This is an example showing how you can transfer Meta data information from your database into InterFormNG.

 

Let's say that you want to implement the following ER-diagram:

 

  +-----------+

  | JOB       |

  +-----------+

PK | ID        |<--+

  | PROCESSED |   |

  | CREATED   |   |

  | XML       |   |

  +-----------+   |

                  |  +----------+

                  |  | METADATA |

                  |  +----------+

                  |  | ID       | PK

                  +--| JOB_ID   | FK

                     | MD_KEY   |

                     | MD_VALUE |

                     +----------+

 

On the SQL Server you could create the tables with the following commands:

 

SET ANSI_NULLS ON

SET QUOTED_IDENTIFIER ON

SET ANSI_PADDING ON

 

CREATE TABLE [dbo].[JOB](

             [ID] [int] IDENTITY(1,1) NOT NULL,

             [PROCESSED] [int] NULL,

             [CREATED] [datetime] NULL,

             [XML] [text] NOT NULL,

PRIMARY KEY CLUSTERED

(

             [ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

 

CREATE TABLE [dbo].[METADATA](

             [ID] [int] IDENTITY(1,1) NOT NULL,

             [JOB_ID] [int] NOT NULL,

             [MD_KEY] [varchar](255) NOT NULL,

             [MD_VALUE] [varchar](255) NULL,

PRIMARY KEY CLUSTERED

(

             [ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

 

SET ANSI_PADDING OFF

 

ALTER TABLE [dbo].[METADATA]  WITH CHECK ADD  CONSTRAINT [FK_JOB_ID] FOREIGN KEY([JOB_ID])

REFERENCES [dbo].[JOB] ([ID])

 

ALTER TABLE [dbo].[METADATA] CHECK CONSTRAINT [FK_JOB_ID]

 

The Hibenate mapping (job.hbm.xml) could look like:

 

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

 

<hibernate-mapping package="com.interform400.xml.plugin.db.model">

             <class name="Job" table="JOB">

                          <id name="id" column="ID">

                                        <generator class="native" />

                          </id>

                          <property name="processingStatus" column="PROCESSED" />

                          <property name="createdDate" column="CREATED" />

                          <property name="xmlData" column="XML" not-null="true" type="com.interform400.xml.plugin.db.hibernate.ClobUserType" update="false" />

 

                          <map table="METADATA" name="metaData" lazy="false">

                                        <key column="JOB_ID" />

                                        <index column="MD_KEY" type="string" />

                                        <element column="MD_VALUE" type="string" />

                          </map>

             </class>

             

             <query name="Job.findUnprocessedJobs"><![CDATA[

                          from Job job where job.processingStatus = 0 order by createdDate, id            

             ]]></query>

</hibernate-mapping>

 

Note that you'll have to do the mapping for METADATA inside the mapping for JOB.

 

As we don't want InterFormNG/Hibernate to mess around with the tables we created, we set hibernate.hbm2ddl.auto= in hibernate.properties, so that the hibernate.properties file looks like this:

 

hibernate.dialect=org.hibernate.dialect.SQLServerDialect

hibernate.show_sql=false

hibernate.hbm2ddl.auto=

 

 

Start "InterFormNG Document Processing Service".

 

Create a new record in the database:

 

begin transaction;

INSERT INTO JOB (XML, PROCESSED) VALUES ('<xml><greeting>Hello</greeting></xml>', 0);

INSERT INTO METADATA (JOB_ID, MD_KEY, MD_VALUE) VALUES ((SELECT MAX(ID) FROM JOB), 'someKey', 'someValue');

commit;

 

Examples of relevant meta data keys could e.g. be the actual printer onto which the output should be printed or e.g. the pdf file name and/or path when creating PDF output or even the email receiver when sending out emails.