These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: My solution in 3 steps
PostPosted: Fri Jul 27, 2007 4:35 am 
Newbie

Joined: Fri Oct 06, 2006 1:25 pm
Posts: 5
Hibernate version: 1.0.2
Name and version of the database you are using: Sql Server 2000

Thanks for your answer ...
The full solution is below

1) Indeed I create a new usertype :
------------------------------------------------------------------------------------
#region Inclusion des namespaces systèmes

using System;
using System.Data;

using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.Type;
#endregion

#region Inclusion des namespaces applicatifs
using KPI.Mapping.Manag;
#endregion

namespace KPI.Mapping.Types
{
public class FormulaType : IUserType
{
StringType stringType = (StringType)NHibernateUtil.String;

public FormulaType()
{

}

#region IUserType Members

public SqlType[] SqlTypes
{
get
{
return new SqlType[] { stringType.SqlType };
}
}

public System.Type ReturnedType
{
get
{
return typeof(FormulaType);
}
}

bool IUserType.Equals(object x, object y)
{
if (x == y)
{
return true;
}
if ((x == null) || (y == null))
{
return false;
}
return x.Equals(y);
}

/// <summary>
/// Récupère la valeur dans la base de données
/// </summary>
public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner)
{
int index = rs.GetOrdinal(names[0]);

Formula loformula = new Formula();
if (rs.IsDBNull(index))
{
loformula.Value = null;
}
else
{
loformula.Value = rs[index].ToString();
}
return loformula;
}

/// <summary>
/// Passe la valeur à la base de données
/// </summary>
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
if (value == null)
{
((IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
return;
}

string lsValue = ((Formula)value).Value;
if ( lsValue == null)
{
((IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
return;
}

((IDbDataParameter)cmd.Parameters[index]).Value = lsValue;
}

public object DeepCopy(object value)
{
return value;
}

public bool IsMutable
{
get
{
return true;
}
}

#endregion

} //Fin classe FormulaType
}

2 )This user type interfaces my Formula instance
------------------------------------------
private Formula _FormulaRange = new Formula();
/// <summary>
/// Formule de seuil :
/// formule dont le calcul permet de vérifier
/// que le résultat se trouve bien entre les limites inférieure et supérieure
/// du seuil
/// </summary>
public Formula FormulaRange
{
get { return _FormulaRange; }
set { _FormulaRange = value; }
}

3) And the Formula class
-------------------------------------------
namespace KPI.Mapping.Manag
{
public class Formula
{
private string _sValue = null;
public string Value
{
get {return _sValue;}
set {_sValue = value;}
}

public int mOwnFunctionalty()
{
//You do what you want
} //Fin mGetElements

} //Fin classe Formula
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.