Persistence Layer - Xyna-Factory/xyna GitHub Wiki

Table of Contents

General Information

A Persistence Layer provides mappings between the data structures of Xyna Factory and different storage device data structures with the goal to store data. Xyna offers the following Persistence Layers:

  • XynaLocalMemoryPersistenceLayer
  • XynaJavaSerializationPersistenceLayer
  • MySQLPersistenceLayer
  • XMLPersistenceLayer
  • XynaDevNullPersistenceLayer
  • XynaXMLShellPersistenceLayer
  • OraclePersistenceLayer
To find out which Persistence Layers are available on a certain Xyna Factory Instance, use the following command:
./xynafactory.sh listpersistencelayers

It will also show the parameters that are necessary to instantiate a Layer.

Default persistence layers

There is also a default persistence layer configuration. When having a look at the table configuration these entries look like this:

./xynafactory.sh listtableconfig | grep repositoryc
repositoryconnectionstorable                    not configured - using default persistence layer.
The following property defines, what the default persistence layer is:
./xynafactory.sh get xnwh.persistence.xmom.defaultpersistencelayerid
Value of property 'xnwh.persistence.xmom.defaultpersistencelayerid': 31
The value then can be used to lookup the mapping between ID and persistence layer: `./xynafactory.sh listpersistencelayerinstances`

Set up MySQLPersistenceLayer for new Xyna Installation

In order for XMOM Persistence to work on a freshly installed Xyna Factory, the MySQLPersistenceLayer has to be set up.

 ./xynafactory.sh addconnectionpool -type MySQL -size 5 -user xyna -password xyna -name mysqlpool1 -connectstring jdbc:mysql://localhost/xyna -retries 1 -pooltypespecifics socketTimeout=180 connectTimeout=30 validationTimeout=30
 ./xynafactory.sh instantiatepersistencelayer -connectionType DEFAULT -department xprc -persistenceLayerName mysql -persistenceLayerInstanceName mysqlPL1 -persistenceLayerSpecifics mysqlpool1 30000 zippedBlobs=true
 ./xynafactory.sh instantiatepersistencelayer -connectionType HISTORY -department xprc -persistenceLayerName mysql -persistenceLayerInstanceName mysqlPL2 -persistenceLayerSpecifics mysqlpool1 30000 zippedBlobs=true
 ./xynafactory.sh set xyna.xprc.xprcods.orderarchive.auditxml.binary true
 ./xynafactory.sh registertable -persistenceLayerInstanceName mysqlPL2 -tableName orderarchive
 ./xynafactory.sh registertable -persistenceLayerInstanceName mysqlPL2 -tableName orderinfo
 ./xynafactory.sh registertable -persistenceLayerInstanceName mysqlPL1 -tableName orderbackup
 ./xynafactory.sh registertable -persistenceLayerInstanceName mysqlPL1 -tableName codegroup -c
 ./xynafactory.sh registertable -persistenceLayerInstanceName mysqlPL1 -tableName codepattern -c
 ./xynafactory.sh registertable -persistenceLayerInstanceName mysqlPL1 -tableName idgeneration -c
 ./xynafactory.sh registertable -persistenceLayerInstanceName mysqlPL1 -tableName cronlikeorders
 ./xynafactory.sh registertable -persistenceLayerInstanceName mysqlPL2 -tableName cronlikeorders
  #Warning - Might have to change ID:
 ./xynafactory.sh set xnwh.persistence.xmom.defaultpersistencelayerid 28

How to use Persistence Layers in Code Snippets

It is possible to access data on a database by using the according Persistence Layer.

//Instantiate Logger
final Logger logger = CentralFactoryLogging.getLogger(MyClass.class);
//List to put in results
List <MyType> list = new ArrayList <MyType> ();

String sqlstring = "SELECT * FROM mytable";

try {
    //Open connection to database
    com.gip.xyna.xnwh.persistence.ODSConnection con = com.gip.xyna.xnwh.persistence.ODSImpl.getInstance().openConnection();

    try {
        com.gip.xyna.xnwh.persistence.ResultSetReader <MyType> reader = new com.gip.xyna.xnwh.persistence.ResultSetReader <MyType> () {
            @Override
            public MyType read(java.sql.ResultSet rs) throws java.sql.SQLException {

                // In this example, MyType has the Membervariables word (String) and id (int)
                MyType mt = new MyType();
                mt.setWord(rs.getString("mytable.word"));
                mt.setId(rs.getInt("mytable.id"));
                return mt;
            }
        };

        com.gip.xyna.xnwh.persistence.PreparedQuery <MyType> pq =
            con.prepareQuery(new com.gip.xyna.xnwh.persistence.Query <MyType> (sqlstring, reader));
        list.addAll(con.query(pq, params, 50, reader));

    } finally {
        con.closeConnection();
    }

} catch (com.gip.xyna.xnwh.persistence.PersistenceLayerException e) {
    //Possible options: Logging, throwing exception, etc.
    logger.debug("Persistence Layer Exception", e);
}

//return gathered data
return list;
⚠️ **GitHub.com Fallback** ⚠️