Ejemplo n.º 1
0
  public static void main(String[] args) {
    ServerRuntime cayenneRuntime =
        new ServerRuntime("cayenne-CESDomain.xml", new CayenneExtrasModule());
    //        ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-CESDomain.xml");
    ObjectContext context = cayenneRuntime.getContext();

    LineItem li = context.newObject(LineItem.class);
    Item i = context.newObject(Item.class);
    CostElement ce1 = context.newObject(CostElement.class);
    CostElement ce2 = context.newObject(CostElement.class);
    CostElement ce3 = context.newObject(CostElement.class);
    BudgetYear by1 = context.newObject(BudgetYear.class);
    BudgetYear by2 = context.newObject(BudgetYear.class);
    BudgetYear by3 = context.newObject(BudgetYear.class);

    li.addToItems(i);
    i.addToCostElements(ce1);
    ce1.addToCostElements(ce2);
    ce2.addToCostElements(ce3);
    ce3.setQuantity(by1);
    ce3.setTotalCost(by2);
    ce3.setUnitCost(by3);
    by1.setLineItem(li);
    by2.setLineItem(li);
    by3.setLineItem(li);

    //        ce2.setItem(i);
    //        ce3.setItem(i);

    context.commitChanges();

    context.deleteObject(li);

    context.commitChanges();
  }
  public void testSerializeNestedChannel() throws Exception {

    ObjectContext child = runtime.newContext(context);

    ObjectContext deserializedContext = Util.cloneViaSerialization(child);

    assertNotNull(deserializedContext.getChannel());
    assertNotNull(deserializedContext.getEntityResolver());
  }
  @Override
  protected void setUpAfterInjection() throws Exception {
    CayenneRuntime.bindThreadInjector(runtime.getInjector());

    dbHelper.deleteAll("PAINTING_INFO");
    dbHelper.deleteAll("PAINTING");
    dbHelper.deleteAll("ARTIST_EXHIBIT");
    dbHelper.deleteAll("ARTIST_GROUP");
    dbHelper.deleteAll("ARTIST");

    tArtist = new TableHelper(dbHelper, "ARTIST");
    tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
  }
Ejemplo n.º 4
0
  @Test
  public void testPkFilteringLogic() throws Exception {
    DataMap map = runtime.getDataDomain().getDataMap("testmap");
    DbEntity artistExhibit = map.getDbEntity("ARTIST_EXHIBIT");
    DbEntity exhibit = map.getDbEntity("EXHIBIT");

    // sanity check
    assertNotNull(artistExhibit);
    assertNotNull(exhibit);
    assertNotNull(generator.dbEntitiesRequiringAutoPK);

    // real test
    assertTrue(generator.dbEntitiesRequiringAutoPK.contains(exhibit));
    assertFalse(generator.dbEntitiesRequiringAutoPK.contains(artistExhibit));
  }
  public void testLocalObject_TempId_NestedContext() throws Exception {

    final Artist a1 = context1.newObject(Artist.class);

    final ObjectContext nestedContext = runtime.newContext(context1);

    interceptor.runWithQueriesBlocked(
        new UnitTestClosure() {

          public void execute() {

            Artist a3 = nestedContext.localObject(a1);
            assertNotSame(a3, a1);
            assertEquals(a3.getObjectId(), a1.getObjectId());
            assertSame(nestedContext, a3.getObjectContext());
          }
        });
  }
Ejemplo n.º 6
0
  @Override
  public Map<String, DataSource> dataSources() {

    Map<String, DataSource> dataSources = new HashMap<>();

    for (DataNode n : runtime.getDataDomain().getDataNodes()) {

      // this method is used to seed a special kind of JdbcConnector.
      // But note that the DataSource here is attached to the DataNode
      // transaction, so reading source data will happen over the same
      // connection as writing target data. Hopefully such multiplexing
      // the connection works ok...

      dataSources.put(n.getName(), n.getDataSource());
    }

    return dataSources;
  }
Ejemplo n.º 7
0
 @Before
 public void setUp() throws Exception {
   generator = new DbGenerator(adapter, runtime.getDataDomain().getDataMap("testmap"), logger);
 }
Ejemplo n.º 8
0
 @Override
 public EntityResolver entityResolver() {
   return runtime.getChannel().getEntityResolver();
 }
Ejemplo n.º 9
0
 @Override
 public ObjectContext newContext() {
   return runtime.newContext();
 }