-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to map Strategy pattern
PostPosted: Sun Oct 19, 2003 2:17 pm 
Newbie

Joined: Sun Oct 19, 2003 2:02 pm
Posts: 1
I need to map strategy pattern with following source code. Please help me. :


public interface StrategyInterface {

public void writeToDB();

}

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;


public class StrategyA implements StrategyInterface {

int number;
int id;


public void writeToDB() {

number = 30;

try {

SessionFactory sessions =
new Configuration().configure().buildSessionFactory();

Session session = sessions.openSession();
StrategyA sa = new StrategyA();
sa.number = number;
session.save(sa);
session.flush();
session.close();

} catch (HibernateException e) {

e.printStackTrace();
}

}


}

public class StrategyB implements StrategyInterface{

int id;
String word;


public void writeToDB() {

.......

}

}




public class StrategyClient {
public StrategyInterface si;

public StrategyClient() {


}
/**
* @return
*/
public StrategyInterface getSi() {
return si;
}

/**
* @param si
*/
public void setSi(StrategyInterface si) {
this.si = si;
}
public void performOperation(String s)
{
si.writeToDB();
}

public static void main(String[] args) {
StrategyClient sc = new StrategyClient();
sc.setSi(new StrategyA());
sc.performOperation();

}

}


Top
 Profile  
 
 Post subject: unclear
PostPosted: Mon Oct 20, 2003 11:26 am 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
It's unclear exactly what you are trying to map ... Can you give a description of exactly what you want to be in the database?

I suspect you may find either the PersistentEnum type or the class type useful but I can't be sure because I don't know what you're trying to do.


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