// 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);
}
}
}
|