Assign sequence to a DB column through xml

228 Views Asked by At

In openbravo ERP application, tables are created through XML files, which are parsed through SAX parser and created using a Java class GenerateEntityTask.

The sample xml file is as follows -

<?xml version="1.0"?>
  <database name="TABLE RESPOS_KOT">
    <table name="RESPOS_KOT" primaryKey="RESPOS_KOT_KEY">
        <column name="RESPOS_KOT_ID" primaryKey="true" required="true" type="INTEGER" size="32" autoIncrement="false">
            <default/>
            <onCreateDefault/>
        </column>
        <column name="NAME" primaryKey="false" required="true" type="NVARCHAR" size="60" autoIncrement="false">
            <default/>
        <onCreateDefault/>
      </column>
    </table>
  </database>

I want to add a sequence to the postgres database & increment the RESPOS_KOT_ID column by 1 for every insertion. I did that from sql shell as -

create sequence kot_sequence increment by 1  start 1;

CREATE TABLE RESPOS_KOT (
    id      INT4 DEFAULT nextval('kot_sequence') NOT NULL,
    name    VARCHAR(60)
);
INSERT INTO RESPOS_KOT (name) VALUES ('Testing respos KOT');

How can i create the same in the xml format. Any suggestions would be of great help, Thanks!!!

1

There are 1 best solutions below

0
On

Tables are created through xml's only as you mentioned , However the xml's can also be generated by openbravo ant task-ant export.database.

steps may help you to create an xml for the above table is,

  1. create a new module in openbravo , indevelopment=true. OR choose any existing module and set indevelopment=true, also note down the dbprefix associated with the module.
  2. Fire a query at pgadmin query promt. UseDBPrefix while creating sequence as well as tables.
  3. do ant export.database
  4. The xml file that corresponds to the table will get created under modules/your_module folder.