-->
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.  [ 5 posts ] 
Author Message
 Post subject: GUI Programming
PostPosted: Tue Mar 02, 2004 7:13 pm 
Newbie

Joined: Tue Mar 02, 2004 7:00 pm
Posts: 3
I want to create a listmodel for showing some database table in my gui. With hibernate its very easy, for example:

package com.titan.vs;


import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import com.titan.service.camera.IPCameraListener_I;
import com.titan.service.camera.IPCamera_I;
import javax.swing.AbstractListModel;
import java.util.List;


/**
* @author martin
*
*/
public class DBCameraListModel_T extends AbstractListModel implements IPCameraListener_I

{


protected List m_list;

public DBCameraListModel_T()
{
doUpdate();
}

public void doUpdate()
{


try
{

Session se = Config_T.getSession();

m_list = se.createQuery( "from com.titan.vs.CameraService_T order by T54_NAME" ).list();
DBCameraListModel_T.this.fireContentsChanged(DBCameraListModel_T.this,0,m_list.size() );

}
catch ( Exception e)
{
log.fatal(e.getMessage() );

}
}


public int getSize()
{
if ( m_list != null)
{
return m_list.size();
}
else
{
return 0;
}

}

public Object getElementAt(int in_index)
{
if ( m_list != null)
{
return m_list.get(in_index);
}

return null;
}

public int indexOf( Object in_obj)
{
if ( m_list != null)
{
return m_list.indexOf( in_obj );
}
else
{
return -1;
}
}



}


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>



<class name="com.titan.db.T54IpCameras" table="T54_IP_CAMERAS">

<id column="T54_IP_CAMERAS_ID" name="id" type="long">
<generator class="native"/>
</id>

<property column="T54_NAME" length="64" name="t54Name" type="string"/>
<property column="T54_LOGIN" length="64" name="t54Login" type="string"/>
<property column="T54_PWD" length="10" name="t54Pwd" type="string"/>
<property column="T54_IP_ADDRESS" length="16" name="t54IpAddress" type="string"/>

<set name="events" lazy="true" cascade="all">
<key column="T54_IP_CAMERAS_ID"/>
<one-to-many class="com.titan.db.T60CameraActions"/>
</set>

</class>


</hibernate-mapping>

But is it the best way? How write an universal ListModel for my persistent Objects? Have anyone a better solution?

Database: Hsqldb
Hybernate Version: 2.1.2


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 5:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well it's not the worst thing I have seen, but not the cleanest either. You could take some look around the forum or the website for things like DAO-patterns and the like.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 5:52 am 
Newbie

Joined: Tue Mar 02, 2004 7:00 pm
Posts: 3
Thanks for help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 8:52 am 
Newbie

Joined: Tue Mar 02, 2004 7:00 pm
Posts: 3
I am searched for DAO Patterns, but i cannot find a right solution for my problem. Can you give me a little bit more information for making my database data visually in JList or JTable easily.

Thanks a lot


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 9:21 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
I recently wrote a swing app w/hibernate. Your method works of course, but my approach was to seperate bus logic and db access from swing related classes. This will not be "easier" but will make it a lot easier to unit test, or change to SWT 3 years from now. ;-)

Unfortuneately there is not a lot of good swing programming examples out there, and there does not seem to be re-usable frameworks like a struts for swing.

In our "framework" we have a service layer that handles all hibernate access. Basically singleton classes, or classes w/ static methods.

We created something called the "applicationstate" which is similar to an http session(a hashmap wrapper class), and a listener infrastructure, such that one a model (hibernate) object changes, screens can be nofified that there were changes in the objects.

We used the Command pattern to handle all actions. This is kind of built in to swing in 1.4, but for reasons I don't remember, it didn't work for us...

Advantage of doing this work is screens don't know about each other, screens are very "dumb", and we can unit test the service layer.
Also multiple open windows can make changes to objects, without screens having to tell each other things.

Disadvantage: more work up front building the framework, more classes...
--James


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.