Persistence Layer - Xyna-Factory/xyna GitHub Wiki

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:

<syntaxhighlight lang="bash">./xynafactory.sh listpersistencelayers</syntaxhighlight>

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

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.

<syntaxhighlight lang="bash"> ./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 </syntaxhighlight>

How to use Persistence Layers in Code Snippets

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

<syntaxhighlight lang="java"> //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; </syntaxhighlight>
⚠️ **GitHub.com Fallback** ⚠️