-->
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.  [ 4 posts ] 
Author Message
 Post subject: Looking for opinions regarding Data- and Bussiness-Layer
PostPosted: Sat Jan 26, 2008 6:57 am 
Beginner
Beginner

Joined: Sat Jan 26, 2008 6:33 am
Posts: 24
Im developing a small finance reporting application for private use. Because NHibernate is able to work quite transparent, I thought it is not necessary to design an own Data-Layer and instead misuse the Bussiness-Layer as such.

But as allways there are some exceptions that make life a bit harder. The User-Class of course has a password property. The behaviour for the bussiness-layer in my opinion would be, that the aplication is just assigning a text to this property and inside the set-function the hash is calculated. Initially I was thinking to use the same property for NHibernate, which is actually not working since we dont need to calculate the hash of the hash when reading from the database.

I can think of three solutions I would like to hear other opinions about:

1. We actually do design an own data-layer, which is really a lot of work but would be the cleanest solution.

2. We add a private property that is used by NHibernate and leave the public property with Bussiness-logic.

3. The User-Class is not responsible for calculating hashes and there should be additional classes doing this job. Which in my opinion degrades the User-Class to a Data-Layer object.

At the moment im favoring solution 2. Im quite curious what other developers are thinking.

Greetings!
Zorgoban


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 3:01 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
I haven't tried this, but I see no reason why it wouln't work (the geek version of famous last words):

Code:
public class User
{
   private string username;
   private string password;

  public string Username
  {
     get { return username; }
     set { username = value; }
  }

  public string Password
  {
     get { return password; }
     set { password = HashPassword(password); }
  }
}


In your mapping file, just specify the access as nosetter.camelcase (or whatever your standard is)

Code:
<class name="FinApp.User, FinApp" table="Users">
  <id name="Username" type="String">
    <column name="username" not-null="true" unique="true"/>
    <generator class="assigned" />
  </id>

  <property name="Password" column="password" access="nosetter.camelcase" />
</class>


Then, when your UI sets the property, it hashes it. When nhibernate sets the property, it will do so by setting the field directly.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 27, 2008 5:27 am 
Beginner
Beginner

Joined: Sat Jan 26, 2008 6:33 am
Posts: 24
Hi!

Thats really good, thanks. Looks like I overlooked this one. Actually i name my fields a bit different, but fortunately there is also a strategy for this :

<property name="Password" column="usr_pass" type="String" access="nosetter.pascalcase-m-underscore" />

Greetings!
Zorgo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 27, 2008 6:15 am 
Beginner
Beginner

Joined: Sat Jan 26, 2008 6:33 am
Posts: 24
Ah now, after reading chapter 5.1 of the online docu a third time, this is the final solution I came up with:

<property name="m_Pass" column="usr_pass" type="String" access="field" />

Im really happy for this hint, otherwise I really would have made an extra property in the class.

Greetings!
Zorgo


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

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.