[gee-svn] SF.net SVN: gabel: [136] trunk/gee/war/WEB-INF
Status: Alpha
Brought to you by:
alllee
|
From: <al...@us...> - 2006-03-04 18:50:31
|
Revision: 136 Author: alllee Date: 2006-03-04 10:50:24 -0800 (Sat, 04 Mar 2006) ViewCVS: http://svn.sourceforge.net/gabel/?rev=136&view=rev Log Message: ----------- fixing persistent classes. Having problems mapping generic classes the way I want to - I'd like to make it easy to subclass ExperimentConfigurationEntity as a generic class and get a lot of default behavior for free by parameterizing the superclass with the particular ExperimentRoundParameters type that your specific ExperimentConfiguration will use and maintain a collection of. That way each subclass wouldn't have to reimplement getAllParameters() to return the specific a specifically-typed Collection that you want, instead the framework provides all that for you. Unfortunately this may not be possible.. Modified Paths: -------------- trunk/gee/src/java/edu/indiana/psych/gee/AbstractExperiment.java trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfiguration.java trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfigurationEntity.java trunk/gee/src/java/edu/indiana/psych/gee/ExperimentParametersEntity.java trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerConfiguration.java trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperimentParameters.java trunk/gee/war/WEB-INF/hibernate.cfg.xml Modified: trunk/gee/src/java/edu/indiana/psych/gee/AbstractExperiment.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/AbstractExperiment.java 2006-03-04 07:38:23 UTC (rev 135) +++ trunk/gee/src/java/edu/indiana/psych/gee/AbstractExperiment.java 2006-03-04 18:50:24 UTC (rev 136) @@ -52,7 +52,7 @@ "not support hot-reconfiguration yet"); } this.configuration = configuration; - allParameters = configuration.getAllExperimentRoundParameters(); + allParameters = configuration.getAllParameters(); } public synchronized void start() throws ExperimentLifecycleException { Modified: trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfiguration.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfiguration.java 2006-03-04 07:38:23 UTC (rev 135) +++ trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfiguration.java 2006-03-04 18:50:24 UTC (rev 136) @@ -34,15 +34,8 @@ public boolean isTriggeredExperiment(); - /** - * Returns the directory containing all experiment configuration files for - * the Experiment with this ExperimentConfiguration. - * @return - */ - public File getExperimentConfigurationDirectory(); + public List<T> getAllParameters(); - public List<T> getAllExperimentRoundParameters(); - public ExperimentRoundParameters getCurrentParameters(); public String getDescription(); Modified: trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfigurationEntity.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfigurationEntity.java 2006-03-04 07:38:23 UTC (rev 135) +++ trunk/gee/src/java/edu/indiana/psych/gee/ExperimentConfigurationEntity.java 2006-03-04 18:50:24 UTC (rev 136) @@ -6,10 +6,18 @@ import java.util.List; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.MappedSuperclass; import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; +import edu.indiana.psych.gee.forager.*; + /** * $Id$ * @@ -22,23 +30,34 @@ */ @Entity -@MappedSuperclass +@Table(name="experiment_configuration") +@Inheritance(strategy=InheritanceType.JOINED) public abstract class ExperimentConfigurationEntity<T extends ExperimentRoundParameters> implements ExperimentConfiguration { private final static String DEFAULT_SERVER_ADDRESS = "groups.psych.indiana.edu"; + + private long id = -1; + + private String description; + private String experimentName; + private String clientJarName; - private T currentParameters; - private final List<T> allParameters = new ArrayList<T>(); + + private ForagerExperimentParameters currentParameters; +// private List<T> allParameters; + private List<ForagerExperimentParameters> allParameters; private InetSocketAddress serverAddress; - private int port; + private int serverPort; private String serverName; + private boolean triggeredExperiment; public ExperimentConfigurationEntity(String serverName, int port) { - this.serverName = serverName; - this.port = port; + setServerName(serverName); + setServerPort(port); } + @Transient public synchronized InetSocketAddress getServerAddress() { // FIXME: return configuration address instead? if (serverAddress == null) { @@ -55,28 +74,56 @@ // be configurable. return DEFAULT_SERVER_ADDRESS; } + + @Id @GeneratedValue + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } public int getServerPort() { - return port; + return serverPort; } + + public void setServerPort(int serverPort) { + this.serverPort = serverPort; + } + + public String getServerName() { + return serverName; + } + public void setServerName(String serverName) { + this.serverName = serverName; + } + public boolean isTriggeredExperiment() { // TODO Auto-generated method stub - return false; + return triggeredExperiment; } - public File getExperimentConfigurationDirectory() { - // TODO Auto-generated method stub - return null; - } + public void setTriggeredExperiment(boolean triggeredExperiment) { + this.triggeredExperiment = triggeredExperiment; + } - @OneToMany(targetEntity=ExperimentParametersEntity.class) - @JoinColumn(name="configuration_id") - public List<T> getAllExperimentRoundParameters() { + +// @OneToMany(targetEntity=ExperimentParametersEntity.class) +// @OneToMany(targetEntity=ForagerExperimentParameters.class) + // @JoinColumn(name="configuration_id") + @Transient + public List<ForagerExperimentParameters> getAllParameters() { return allParameters; } + + public void setAllParameters(List<ForagerExperimentParameters> allParameters) { + this.allParameters = allParameters; + } - public synchronized T getCurrentParameters() { + @Transient + public synchronized ForagerExperimentParameters getCurrentParameters() { if (currentParameters == null) { if (allParameters.isEmpty()) { throw new ExperimentLifecycleException("No experiment round parameters available for : " + getExperimentName()); Modified: trunk/gee/src/java/edu/indiana/psych/gee/ExperimentParametersEntity.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/ExperimentParametersEntity.java 2006-03-04 07:38:23 UTC (rev 135) +++ trunk/gee/src/java/edu/indiana/psych/gee/ExperimentParametersEntity.java 2006-03-04 18:50:24 UTC (rev 136) @@ -1,9 +1,13 @@ package edu.indiana.psych.gee; import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.MappedSuperclass; +import javax.persistence.Table; +import javax.persistence.Transient; /** * $Id: Exp$ @@ -15,13 +19,23 @@ */ @Entity -@MappedSuperclass +@Table(name="experiment_parameters") +@Inheritance(strategy=InheritanceType.JOINED) public abstract class ExperimentParametersEntity implements ExperimentRoundParameters { + private long id = -1; + private ExperimentConfiguration configuration; - @ManyToOne(targetEntity=ExperimentConfigurationEntity.class) - @JoinColumn(name="configuration_id", nullable=false) + @Id @GeneratedValue + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + public ExperimentConfiguration getConfiguration() { return configuration; } Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerConfiguration.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerConfiguration.java 2006-03-04 07:38:23 UTC (rev 135) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerConfiguration.java 2006-03-04 18:50:24 UTC (rev 136) @@ -1,9 +1,14 @@ package edu.indiana.psych.gee.forager; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; +import javax.persistence.Transient; import edu.indiana.psych.gee.ExperimentConfigurationEntity; import edu.indiana.psych.gee.forager.client.ForagerApplet; @@ -19,12 +24,13 @@ * @version $Revision$ */ @Entity +@Inheritance(strategy=InheritanceType.JOINED) +@DiscriminatorValue("forager") +@PrimaryKeyJoinColumn(name="forager_configuration_id") @Table(name="forager_configuration") public class ForagerConfiguration extends ExperimentConfigurationEntity<ForagerExperimentParameters> { + - - private long id = -1; - public ForagerConfiguration(String serverName, int port) { super(serverName, port); } @@ -48,21 +54,10 @@ return new ForagerConfiguration(getDefaultServerAddress(), 25000); } + @Transient public Duration getDelayBetweenRounds() { return Duration.create(30); } - - @Id @GeneratedValue - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - - } Modified: trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperimentParameters.java =================================================================== --- trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperimentParameters.java 2006-03-04 07:38:23 UTC (rev 135) +++ trunk/gee/src/java/edu/indiana/psych/gee/forager/ForagerExperimentParameters.java 2006-03-04 18:50:24 UTC (rev 136) @@ -5,10 +5,17 @@ import java.util.List; import java.util.Properties; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.GeneratedValue; +import javax.persistence.JoinColumn; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.ManyToOne; +import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; +import javax.persistence.ManyToOne; import javax.persistence.Transient; import org.hibernate.annotations.Proxy; @@ -19,32 +26,26 @@ import edu.indiana.psych.gee.time.Duration; @Entity +@Inheritance(strategy=InheritanceType.JOINED) +@DiscriminatorValue("forager") +@PrimaryKeyJoinColumn(name="forager_parameters_id") +@Proxy(proxyClass=ExperimentRoundParameters.class) @Table(name="forager_parameters") -@Proxy(proxyClass=ExperimentRoundParameters.class) public class ForagerExperimentParameters extends ExperimentParametersEntity { - private final ForagerConfiguration foragerConfiguration; + private ForagerAgentConfiguration agentConfiguration; - /** - * @param configuration - */ + private String name; + private int foodSpoilDuration; + private double foodRate; + + ForagerExperimentParameters(ForagerConfiguration configuration) { - foragerConfiguration = configuration; + setConfiguration(configuration); } - long id = -1; - String name; - int foodSpoilDuration; - double foodRate; - ForagerAgentConfiguration agentConfiguration; - - @Id @GeneratedValue - public long getId() { - return id; - } - public int getMinimumParticipants() { // FIXME: replace with configuration value. return 5; @@ -69,11 +70,13 @@ return "Very special instructions"; } + @Transient public Properties getProperties() { // TODO Auto-generated method stub return new Properties(); } + @Transient public Dimension getBoardSize() { // TODO Auto-generated method stub return new Dimension(600, 600); @@ -88,20 +91,25 @@ return 5; } + @Transient public Visibility getSubjectVisibility() { return Visibility.FULL; } + @Transient public Visibility getFoodVisibility() { return Visibility.FULL; } + @Transient public Duration getRoundDuration() { return Duration.create(240); } - public ExperimentConfiguration getConfiguration() { - return foragerConfiguration; + @ManyToOne(targetEntity=ForagerConfiguration.class) + @JoinColumn(name="configuration_id", nullable=false) + public ForagerConfiguration getConfiguration() { + return (ForagerConfiguration) super.getConfiguration(); } @Transient @@ -117,10 +125,6 @@ this.name = name; } - public void setId(long id) { - this.id = id; - } - public int getFoodSpoilDuration() { return foodSpoilDuration; } Modified: trunk/gee/war/WEB-INF/hibernate.cfg.xml =================================================================== --- trunk/gee/war/WEB-INF/hibernate.cfg.xml 2006-03-04 07:38:23 UTC (rev 135) +++ trunk/gee/war/WEB-INF/hibernate.cfg.xml 2006-03-04 18:50:24 UTC (rev 136) @@ -9,7 +9,9 @@ <session-factory> <mapping package="edu.indiana.psych.gee"/> <mapping class="edu.indiana.psych.gee.ConsentForm"/> + <mapping class="edu.indiana.psych.gee.ExperimentParametersEntity"/> <mapping package="edu.indiana.psych.gee.forager"/> + <mapping class="edu.indiana.psych.gee.forager.ForagerExperimentParameters"/> <mapping class="edu.indiana.psych.gee.forager.ForagerConfiguration"/> </session-factory> </hibernate-configuration> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |