锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
function window.onbeforeunload() {
if (event.clientX > document.body.clientHeight || event.clientY < 0 || event.altKey) {
alert("That's good.");
}
}
</script>
<--------灞忚斀F5銆丄lt錛婩4鐨勯敊-------->
<script>
function window.onbeforeunload() {
if((event.keyCode != 0) && (event.clientX > document.body.clientHeight || event.clientY < 0) || event.altKey) {
alert("That's good.");
}
}
</script>
涓涓ず渚嬬殑hibernate鐨勬槧灝勬枃浠?BR>
DAO浠g爜:
紺烘剰鎬х殑嫻嬭瘯浠g爜:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.EntityMode;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
public class DynamicClassTest extends TestCase {
public DynamicClassTest(String str) {
super(str);
}
protected void configure(Configuration cfg) {
cfg.setProperty(Environment.DEFAULT_ENTITY_MODE, EntityMode.MAP.toString());
}
public void testLazyDynamicClass() {
Session s = openSession();
assertTrue( "Incorrectly handled default_entity_mode", s.getEntityMode() == EntityMode.MAP );
Session other = s.getSession( EntityMode.MAP );
assertEquals( "openSession() using same entity-mode returned new session", s, other );
other = s.getSession( EntityMode.POJO );
other.close();
assertTrue( !other.isOpen() );
assertTrue( other.isConnected() ); // because it is linked to the "root" session's connection
s.close();
s = openSession();
Transaction t = s.beginTransaction();
Map cars = new HashMap();
cars.put("description", "Cars");
Map monaro = new HashMap();
monaro.put("productLine", cars);
monaro.put("name", "monaro");
monaro.put("description", "Holden Monaro");
Map hsv = new HashMap();
hsv.put("productLine", cars);
hsv.put("name", "hsv");
hsv.put("description", "Holden Commodore HSV");
List models = new ArrayList();
cars.put("models", models);
models.add(hsv);
models.add(monaro);
s.save("ProductLine", cars);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
cars = (Map) s.createQuery("from ProductLine pl order by pl.description").uniqueResult();
models = (List) cars.get("models");
assertFalse( Hibernate.isInitialized(models) );
assertEquals( models.size(), 2);
assertTrue( Hibernate.isInitialized(models) );
s.clear();
List list = s.createQuery("from Model m").list();
for ( Iterator i=list.iterator(); i.hasNext(); ) {
assertFalse( Hibernate.isInitialized( ( (Map) i.next() ).get("productLine") ) );
}
Map model = (Map) list.get(0);
assertTrue( ( (List) ( (Map) model.get("productLine") ).get("models") ).contains(model) );
s.clear();
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
cars = (Map) s.createQuery("from ProductLine pl order by pl.description").uniqueResult();
s.delete(cars);
t.commit();
s.close();
}
protected String[] getMappings() {
return new String[] { "dynamic/ProductLine.hbm.xml" };
}
public static Test suite() {
return new TestSuite(DynamicClassTest.class);
}
}
閰嶇疆鏂囦歡: <hibernate-mapping> <!-- This mapping demonstrates "dynamic" entities. <class entity-name="ProductLine"> <id name="id" <property name="description" <!-- don't use sets for associations, unless you want stack overflows! --> </class> <class entity-name="Model"> <id name="id" </hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"
-->
column="productId"
length="32"
type="string">
<generator class="uuid.hex"/>
</id>
not-null="true"
length="200"
type="string"/>
<!--榪欎竴鐐硅鐗瑰埆灝忓績, 鎴戝垰寮濮嬪仛璇曢獙鐨勬椂鍊欑敤鐨勫氨鏄疭et, 緇撴灉鎶涘嚭 stack overflows寮傚父, 瀹崇殑鎴戜袱涓皬鏃舵悶涓嶅畾, 鏈鍚庤繕鏄湅浜嗚繖涓猼est, 鎵嶇煡閬撶敤榪欐牱鐨勯檺鍒?->
<bag name="models"
cascade="all"
inverse="true">
<key column="productId"/>
<one-to-many class="Model"/>
</bag>
column="modelId"
length="32"
type="string">
<generator class="uuid.hex"/>
</id>
<property name="name"
not-null="true"
length="25"
type="string"/>
<property name="description"
not-null="true"
length="200"
type="string"/>
<many-to-one name="productLine"
column="productId"
not-null="true"
class="ProductLine"/>
</class>
]]>