Replication Classes
From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS
<keywords content="keywords">
replication, replication schema, replicated entities, data level integration, mySQL, custom replication
</keywords>
Applies to ENTERPRISE EDITIONS |
Contents |
Replication Classes
Introduction
This article presents an example of the replication classes that implement the "IProviderVirtualDA" and "IReplicationEntDA" interfaces, which are required for a custom replication (when the data source is in a database engine different from Oracle or Microsoft SQL Server).
The example provided illustrates a custom replication using a MySQL data source.
Alert: Take into account that the following code provides an illustration of the "GetEntity()" method implementation to serve as a guide, but other methods are not included and need to be completed. |
Prerequisites
To implement these classes, it is required to download and install the MySQL Connector/Net component for the connection to a MySQL instance.
For this example, these classes were worked with Microsoft Visual Studio. Within the .Net project worked with Visual Studio, the "MySql.Data.dll" assembly installed by the MySQL Connector/Net component needs to be referenced by the .Net project.
It is also necessary to reference the "Bizagi.EntityManager.Interfaces.IEntityDA.dll" assembly, which is found in the bin folder of the project's web application (by default at "C:\Bizagi\Enterprise\Projects\[PROJECT_NAME]\WebApplication\bin\".
Classes Implementation Example
Class Interface IProviderVirtualDA
using System; using System.Data; using System.Data.OleDb; using System.Collections; using System.Collections.Specialized; using System.Text; using MySql.Data.MySqlClient; using Bizagi.EntityManager.Interfaces; namespace BizagiMySQL { public class CMySQLProvider : IProviderVirtualDA { protected HybridDictionary m_htMetadata; protected MySqlConnection MySqlconn; protected bool bDisposed; public CMySQLProvider() { bDisposed = false; MySqlconn = null; } #region IProviderVirtualDA Members public void BeginTransaction() { // TODO: Add CMySQLProvider.BeginTransaction implementation } public void Rollback() { // TODO: Add CMySQLProvider.Rollback implementation } public void Commit() { // TODO: Add CMySQLProvider.Commit implementation } public void OpenConnection() { if (MySqlconn == null) { // Verify that the metadata fields are correct if (!m_htMetadata.Contains("Server") || !m_htMetadata.Contains("Database") || !m_htMetadata.Contains("Username") || !m_htMetadata.Contains("Password")) { throw new CEntityClassInterfaceException("Incomplete metadata:" + "connection parameters missing"); } else { // build the connection string string sConn; string sServer = m_htMetadata["Server"].ToString(); string sDatabase = m_htMetadata["Database"].ToString(); string sUsername = m_htMetadata["Username"].ToString(); string sPassword = m_htMetadata["Password"].ToString(); sConn = "Server=" + sServer + ";Database=" + sDatabase + ";Uid=" + sUsername + ";Pwd=" + sPassword + ";"; MySqlconn = new MySqlConnection(sConn); MySqlconn.Open(); } } } public void Init(HybridDictionary htMetadata) { m_htMetadata = htMetadata; } public void CloseConnection() { if (MySqlconn != null) MySqlconn.Close(); MySqlconn = null; } #endregion #region IDisposable Members public void Dispose() { if (!bDisposed) { // never close the connection in this method!! bDisposed = true; } } #endregion public MySqlConnection getConnection() { return this.MySqlconn; } public DataSet executeMySQLQuery(string sSQL) { MySqlCommand command; MySqlDataAdapter adapter; DataSet ds = new DataSet(); command = new MySqlCommand(sSQL, this.getConnection()); adapter = new MySqlDataAdapter(command); adapter.Fill(ds); return ds; } public void executeNonQueryMySQL(string sSQL) { MySqlCommand command; command = new MySqlCommand(sSQL, this.getConnection()); command.ExecuteNonQuery(); } } }
Class Interface IReplicationEntDA
using System; using System.Data; using System.Data.OleDb; using System.Collections; using System.Collections.Specialized; using System.Text; using System.Xml; using Bizagi.EntityManager.Interfaces; using MySql.Data.MySqlClient; using Bizagi.Defs; namespace BizagiMySQL { public class CMySQLReplication : IReplicationEntDA { /// <summary> /// Flag to show if object has been disposed /// </summary> protected bool m_bDisposed; /// <summary> /// Connection with the virtual System /// </summary> protected CMySQLProvider m_objSystem; /// <summary> /// Metadata used to initialize object, as collection of name-value pairs /// </summary> protected HybridDictionary m_htMetadata; public CMySQLReplication() { m_bDisposed = false; } #region IReplicationEntDA Members public void Init(IProviderVirtualDA objProvider, HybridDictionary htMetadata) { m_objSystem = (CMySQLProvider)objProvider; m_htMetadata = htMetadata; } public DataSet GetEntity(string sEntSource, string[] arrsColList) { try { StringBuilder sbSQL = new StringBuilder(); sbSQL.Append(" SELECT "); sbSQL.Append(string.Join(",", arrsColList)); // FROM clause sbSQL.Append(" FROM "); sbSQL.Append(sEntSource); DataSet ds = m_objSystem.executeMySQLQuery(sbSQL.ToString()); return ds; } catch (Exception e) { throw new ApplicationException(e.Message); } } #endregion #region IDisposable Members public void Dispose() { if (!m_bDisposed) { m_bDisposed = true; } } #endregion } }
Related Articles
- How to integrate Bizagi with an external data source.
- Custom Replication.
- MySQL Virtualization Classes Example.
<comments />