Author: max.andersen(a)jboss.com
Date: 2006-09-21 02:50:54 -0400 (Thu, 21 Sep 2006)
New Revision: 10506
Added:
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/Group.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/SessionAttribute.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/StatisticsBrowserTest.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/User.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/UserGroup.hbm.xml
Log:
HBX-759
basic test class for testing browser
Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/Group.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/Group.java 2006-09-21
06:48:20 UTC (rev 10505)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/Group.java 2006-09-21
06:50:54 UTC (rev 10506)
@@ -0,0 +1,35 @@
+//$Id: Group.java 5686 2005-02-12 07:27:32Z steveebersole $
+package org.hibernate.tool.stat;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Gavin King
+ */
+public class Group {
+ private String name;
+ private Set users = new HashSet();
+ Group() {}
+ public Group(String n) {
+ name = n;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public Set getUsers() {
+ return users;
+ }
+ public void setUsers(Set users) {
+ this.users = users;
+ }
+ public void addUser(User user) {
+ users.add(user);
+
+ }
+}
Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/SessionAttribute.java
===================================================================
---
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/SessionAttribute.java 2006-09-21
06:48:20 UTC (rev 10505)
+++
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/SessionAttribute.java 2006-09-21
06:50:54 UTC (rev 10506)
@@ -0,0 +1,38 @@
+//$Id: SessionAttribute.java 5686 2005-02-12 07:27:32Z steveebersole $
+package org.hibernate.tool.stat;
+
+import java.io.Serializable;
+
+/**
+ * @author Gavin King
+ */
+public class SessionAttribute {
+ private Long id;
+ private String name;
+ private String stringData;
+
+ SessionAttribute() {}
+ public SessionAttribute(String name) {
+ this.name = name;
+ }
+ public SessionAttribute(String name, String str) {
+ this.name = name;
+ this.stringData = str;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getStringData() {
+ return stringData;
+ }
+ public void setStringData(String stringData) {
+ this.stringData = stringData;
+ }
+
+ public Long getId() {
+ return id;
+ }
+}
Added:
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/StatisticsBrowserTest.java
===================================================================
---
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/StatisticsBrowserTest.java 2006-09-21
06:48:20 UTC (rev 10505)
+++
trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/StatisticsBrowserTest.java 2006-09-21
06:50:54 UTC (rev 10506)
@@ -0,0 +1,54 @@
+package org.hibernate.tool.stat;
+
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.classic.Session;
+import org.hibernate.test.TestCase;
+
+public class StatisticsBrowserTest extends TestCase {
+
+ public StatisticsBrowserTest(String name) {
+ super( name );
+ }
+
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.USE_STRUCTURED_CACHE, "true" );
+ }
+
+ public void testBrowser() throws Exception {
+ getSessions().getStatistics().setStatisticsEnabled( true );
+ new StatisticsBrowser().showStatistics( getSessions().getStatistics(), false );
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+
+ for(int i=0; i<100; i++) {
+ Group group = new Group( "Hibernate" + i );
+ group.addUser(new User("gavin" + i, "figo123"));
+ group.addUser(new User("cbauer" + i, "figo123"));
+ group.addUser(new User("steve" + i, "figo123"));
+ group.addUser(new User("max" + i, "figo123"));
+ group.addUser(new User("anthony" + i, "figo123"));
+
+ s.saveOrUpdate( group );
+ if(i % 20==0) s.flush();
+ }
+ s.flush();
+ s.clear();
+ s.createQuery( "from java.lang.Object" ).list();
+ tx.commit();
+ s.close();
+
+ Thread.sleep( 100000 );
+
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/stat/";
+ }
+ protected String[] getMappings() {
+ return new String[] { "UserGroup.hbm.xml"};
+ }
+
+}
Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/User.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/User.java 2006-09-21
06:48:20 UTC (rev 10505)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/User.java 2006-09-21
06:50:54 UTC (rev 10506)
@@ -0,0 +1,37 @@
+//$Id: User.java 5686 2005-02-12 07:27:32Z steveebersole $
+package org.hibernate.tool.stat;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Gavin King
+ */
+public class User {
+ private String name;
+ private String password;
+ private Set session = new HashSet();
+ User() {}
+ public User(String n, String pw) {
+ name=n;
+ password = pw;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getPassword() {
+ return password;
+ }
+ public void setPassword(String password) {
+ this.password = password;
+ }
+ public Set getSession() {
+ return session;
+ }
+ public void setSession(Set session) {
+ this.session = session;
+ }
+}
Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/UserGroup.hbm.xml
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/UserGroup.hbm.xml 2006-09-21
06:48:20 UTC (rev 10505)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/stat/UserGroup.hbm.xml 2006-09-21
06:50:54 UTC (rev 10506)
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+-->
+
+<hibernate-mapping package="org.hibernate.tool.stat">
+
+ <class name="Group" table="groups">
+ <cache usage="read-write"/>
+ <id name="name"/>
+ <set name="users" cascade="save-update">
+ <cache usage="read-write"/>
+ <key column="groupName"/>
+ <one-to-many class="User"/>
+ </set>
+ </class>
+
+ <class name="User" table="users">
+ <cache usage="read-write"/>
+ <id name="name"/>
+ <property name="password"/>
+ <set name="session"
cascade="persist,save-update,delete,delete-orphan">
+ <key column="userName" not-null="true"/>
+ <one-to-many class="SessionAttribute"/>
+ </set>
+ </class>
+
+ <class name="SessionAttribute" table="session_attributes">
+ <id name="id" access="field">
+ <generator class="native"/>
+ </id>
+ <property name="name" not-null="true"
update="false"/>
+ <property name="stringData"/>
+ </class>
+
+
+
+</hibernate-mapping>
Show replies by date