The applications which are used to run the generated artefacts are not generated
by the pmMDA explorer. But pmMDA.NET Framework provides base classes for these
applications to make it easy to implement pmMDA.NET applications such as server or
client.
For more information about the farmework for applications see the
PmMda.Net.Application
namespace in the
API or the examples provided within the pmMDA
source code.
The server or client application needs to implement a Locator
class. To run
the application one single instance of this class is created and registered.
A data object manager must be created and registered.
The NHibernate configuration and repository files are only used if the persistence handler is used as data object handler.
The NHibernate configuration is specified in the app.config file.
The application (normaly the server, except in a standalone client application) which
is responsible for persisting the data objects must contain the NHibernate repository
files (*.hbm.xml). These files can be embedded
differently.
pmMDA.NET recommend to compile the repository files as resource files. Add the
repository_do.hbm.xml and repository_lw.hbm.xml files to the Visual Studio project and set
the "Build Action" to "Embedded Resource".
Note: Visual Studio 2003 doesn't embedd the resource files to the assembly while building, if no source code has changed. If you change just the configuration files manually, choose "Rebuild Solution" or change some source files before building the solution.
This example shows how to implement a standalone application
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System"/> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/> </configSections> <nhibernate> <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> <add key="hibernate.connection.isolation" value="ReadCommitted"/> <!-- This is the ByteFX.Data.dll provider for MySql --> <add key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver"/> <add key="hibernate.connection.connection_string" value="Database=OJB;Data Source=localhost;User Id=nhibernate;Password=nhibernate"/> <add key="hibernate.dialect" value="NHibernate.Dialect.MySQLDialect"/> </nhibernate> </configuration>
StandaloneApp
to the project.
/* ********************************************************************** * Copyright 2005 BBV Software Services AG (http://www.bbv.ch) * * Licensed under the Apache License, Version 2.0 (the "Licence"); * http://www.apache.org/licenses/LICENSE-2.0 * you may not use this file except in compliance with the License. * **********************************************************************/ using System; using NHibernate; using NHibernate.Cfg; using PmMda.Net.Application; using PmMda.Net.Dog; using PmMda.Net.Dog.Persistence; namespace StandaloneApplication { public class StandaloneApp : Locator { [STAThread] static void Main(string[] args) { new StandaloneApp(); } public StandaloneApp() { // Configure NHibernate. // This will add the content of all *.hmb.xml files in the assemby "StandaloneApplication", // which are compiled as resource files, to the NHibernate configuration. Configuration configuration = new Configuration(); configuration.AddAssembly("StandaloneApplication"); // Initialize pmMDA Register(this); DataObjectManager manager = new DataObjectManager(new PersistenceHandler(configuration)); Register(manager); TypeFactory typeFactory = new TypeFactory(manager); typeFactory.RegisterAllTypes(); Initialize(); Startup(); // Here starts your application // Read data object example // MyDataObject myDataObject = // DataObjectManager.DataObjectHandler.Retrieve(typeof(MyDataObject), 123); // Modify data object example // myDataObject.MyProperty = "Hello world"; // Save the data object // try { // this.DataObjectManager.DataObjectHandler.Store(myDataObject); // } catch(PersistenceException e) { // // TODO: error handling; optimistic concurrency violation // } } } }