use of org.datanucleus.samples.annotations.one_many.bidir_2.Window in project cardgame1 by joey101937.
the class CampaignManager method goToCardAdder.
public static void goToCardAdder() {
Board board = Board.getMainBoard();
board.running = false;
Window window = board.window;
JFrame frame = window.frame;
if (frame == null) {
System.out.println("frame is null");
System.exit(1);
} else {
frame.dispose();
board.running = false;
if (level <= 4)
new CardAdderFrame(4);
else
new CardAdderFrame(2);
// available = true;
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_2.Window in project cardgame1 by joey101937.
the class CampaignManager method returnToInterface.
/**
* ends the current game instance and returns to campaign interface
*/
public static void returnToInterface() {
Board board = Board.getMainBoard();
board.running = false;
Window window = board.window;
JFrame frame = window.frame;
if (frame == null) {
System.out.println("frame is null");
System.exit(1);
} else {
frame.dispose();
board.running = false;
new CampaignInterface();
// available = true;
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_2.Window in project tests by datanucleus.
the class ManagedRelationshipTest method testOneToManyJoinBidirPersistElement.
/**
* Test for management of relations with a 1-N JoinTable bidir where the objects are persisted
* and only the FK side is set.
*/
public void testOneToManyJoinBidirPersistElement() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "true");
Transaction tx = pm.currentTransaction();
try {
tx.begin();
House house = new House(14, "Smith Street");
Window window1 = new Window(100, 200, house);
Window window2 = new Window(600, 200, house);
assertNotNull("Window1 has null House but should be not-null before persist", window1.getHouse());
assertNotNull("Window2 has null House but should be not-null before persist", window2.getHouse());
assertEquals("House has Windows yet should be empty before persist", 0, house.getWindows().size());
pm.makePersistent(window1);
pm.makePersistent(window2);
pm.flush();
// Check that the relation sides are both set
assertSame("Window1 has incorrect House after persist/flush", house, window1.getHouse());
assertSame("Window2 has incorrect House after persist/flush", house, window2.getHouse());
assertEquals("House has incorrect Windows after persist/flush", 2, house.getWindows().size());
tx.commit();
} catch (Exception e) {
LOG.error("Exception thrown persisting 1-N JoinTable bidir with only FK side set", e);
fail("Error in test : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(House.class);
clean(Window.class);
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_2.Window in project tests by datanucleus.
the class ManagedRelationshipTest method testOneToManyJoinBidirPersistCollection.
/**
* Test for management of relations with a 1-N jointable bidir where the objects are persisted
* and only the collection side is set.
*/
public void testOneToManyJoinBidirPersistCollection() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "true");
Transaction tx = pm.currentTransaction();
try {
tx.begin();
House house = new House(15, "King Street");
Window window1 = new Window(150, 200, null);
Window window2 = new Window(350, 400, null);
house.addWindow(window1);
house.addWindow(window2);
assertNull("Window1 has non-null House but should be null before persist", window1.getHouse());
assertNull("Window2 has non-null House but should be null before persist", window2.getHouse());
assertNotNull("House has null Windows yet should be non-null before persist", house.getWindows());
pm.makePersistent(house);
pm.flush();
// Check that the relation sides are both set
assertNotNull("Window1 has null House but should be not-null after persist/flush", window1.getHouse());
assertNotNull("Window2 has null House but should be not-null after persist/flush", window2.getHouse());
assertNotNull("House has null Windows yet should be non-null after persist/flush", house.getWindows());
tx.commit();
} catch (Exception e) {
LOG.error("Exception thrown persisting 1-N JoinTable bidir with only collection side set", e);
fail("Error in test : " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(House.class);
clean(Window.class);
}
}
use of org.datanucleus.samples.annotations.one_many.bidir_2.Window in project tests by datanucleus.
the class ManagedRelationshipTest method testOneToManyJoinBidirPersistInconsistent.
/**
* Test for management of relations with a 1-N jointable bidir where the objects are persisted
* and the owner side of elements is inconsistent with the container.
*/
public void testOneToManyJoinBidirPersistInconsistent() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
pm.setProperty(PropertyNames.PROPERTY_MANAGE_RELATIONSHIPS, "true");
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// house1 -> window1, window2 BUT window1 -> house2, window2 -> house2
House house1 = new House(15, "King Street");
House house2 = new House(23, "Queen Street");
Window window1 = new Window(150, 200, null);
Window window2 = new Window(350, 400, null);
house1.addWindow(window1);
house1.addWindow(window2);
window1.setHouse(house2);
window2.setHouse(house2);
pm.makePersistent(house1);
pm.flush();
fail("Should have thrown exception when persisting inconsistent 1-N JoinTable bidir relation");
tx.commit();
} catch (Exception e) {
// Success
return;
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(House.class);
clean(Window.class);
}
}
Aggregations