PersistentObject.cs :  » Persistence-Frameworks » Persist.NET » Persist » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » Persist.NET 
Persist.NET » Persist » PersistentObject.cs
// Persist library : Persistence layer
// Copyright (C) 2003 Vincent Daron
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;

using Persist.Criteria;
using Persist.Attributes;

namespace Persist{
   /// <summary>
   /// This must be the base class of all object that must Persist in relationaldatabase
   /// </summary>
  public abstract class PersistentObject
  {
      /// <summary>
      /// Indicate if the object has been modifed
      /// </summary>
      protected internal bool isDirty;
      /// <summary>
      /// Indicate if the object is retrieved has proxy
      /// </summary>
      protected internal bool isProxy;
      /// <summary>
      /// Indicate if this object is Persistent
      /// </summary>
      protected internal bool isPersistent;
      /// <summary>
      /// Indicate if this object use Optimist lock mechanism
      /// </summary>
      protected internal bool isOptimisticLock;

      /// <summary>
      /// Indocate if this object is being saved (used to avoid Ping-Pong Save with assocations)
      /// </summary>
      protected internal bool isSaving;

      private PersistenceManagerFactory thePersistenceManager;

      /// <summary>
      /// Create a persistent object
      /// </summary>
    protected PersistentObject()
    {
         thePersistenceManager = Persist.PersistenceManagerFactory.Instance;
         isDirty = false;
         isProxy = false;
         isPersistent = false;
    }

      /// <summary>
      /// Indicate if the object has been changed.
      /// </summary>
      public bool Dirty
      {
         get{return isDirty;}
      }
      /// <summary>
      /// Indicate if the object is only retreive as a proxy
      /// </summary>
      public bool Proxy{get{return isProxy;}}
      /// <summary>
      /// Indicate if this object has been retrieved from database
      /// </summary>
      public bool Persistent{get{return isPersistent;}}
      /// <summary>
      /// Indicate if this object use Optimist lock
      /// </summary>
      public bool OptimisticLock{get{return isOptimisticLock;}}


      /// <summary>
      /// Retreive the object from database
      /// The primary key has to be set before calling this method
      /// </summary>
      public virtual void Retrieve()
      {
         thePersistenceManager.RetrieveObject(this);
      }

      /// <summary>
      /// Retreive the object from database
      /// The primary key has to be set before calling this method
      /// </summary>
      public virtual void RetrieveAsProxy()
      {
         thePersistenceManager.RetrieveObjectAsProxy(this);
      }

      /// <summary>
      /// Retrieve an assocation 
      /// </summary>
      /// <param name="targetName">the Attribute Target Assocation</param>
      /// <param name="orderAttributes">Sort order</param>
      public void RetrieveAssociation(string targetName,Order[] orderAttributes)
      {
         thePersistenceManager.RetrieveAssociation(this, targetName, orderAttributes);
      }

      /// <summary>
      /// Retrieve an assocation 
      /// </summary>
      /// <param name="targetName">the Attribute Target Assocation</param>
      public void RetrieveAssociation(string targetName)
      {
         RetrieveAssociation(targetName,null);
      }
      /// <summary>
      /// Retrieve an assocation as proxy objects
      /// </summary>
      /// <param name="targetName">the Attribute Target Assocation</param>
      /// <param name="orderAttributes">Sort order</param>
      public void RetrieveAssociationAsProxy(string targetName, Order[] orderAttributes)
      {

      }
      /// <summary>
      /// Retrieve an assocation as proxy objects
      /// </summary>
      /// <param name="targetName">the Attribute Target Assocation</param>
      public void RetrieveAssociationAsProxy(string targetName)
      {
         RetrieveAssociationAsProxy(targetName,null);
      }

      /// <summary>
      /// Delete this object. This call delete also all the associated object marked as "DeleteAutomatic"
      /// </summary>
      public virtual void Delete()
      {
         thePersistenceManager.DeleteObject(this);
      }
      /// <summary>
      /// Save this object. This call save also all the associated object marked as "SaveAutomatic"
      /// The object have to be flagged as Dirty to be saved.
      /// </summary>
      public void Save()
      {
         thePersistenceManager.SaveObject(this);
      }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.