@Before
 public void setUp() throws Exception {
   tArtist = new TableHelper(dbHelper, "ARTIST");
   tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
   tPainting = new TableHelper(dbHelper, "PAINTING");
   tPainting.setColumns("PAINTING_ID", "PAINTING_TITLE", "ARTIST_ID");
 }
  private void createTwoArtistsTwoPaintingsDataSet() throws Exception {

    tArtist.insert(1, "AA");
    tArtist.insert(2, "BB");

    tPainting.insert(1, 1, "X");
    tPainting.insert(2, 2, "Y");
  }
Пример #3
0
  @Before
  public void setUp() throws Exception {
    tClobMaster = new TableHelper(dbHelper, "CLOB_MASTER");
    tClobMaster.setColumns("CLOB_MASTER_ID", "CLOB_COLUMN", "NAME");

    tClobDetail = new TableHelper(dbHelper, "CLOB_DETAIL");
    tClobDetail.setColumns("CLOB_DETAIL_ID", "CLOB_MASTER_ID", "NAME");
  }
  protected void createArtistWithTwoPaintingsAndTwoInfosDataSet() throws Exception {
    tArtist.insert(11, "artist2");

    tPainting.insert(6, "p_artist2", 11, 1000);
    tPainting.insert(7, "p_artist3", 11, 2000);

    tPaintingInfo.insert(6, "xYs");
  }
 protected void creatArtistsDataSet() throws Exception {
   tArtist.insert(33001, "c");
   tArtist.insert(33002, "b");
   tArtist.insert(33003, "f");
   tArtist.insert(33004, "d");
   tArtist.insert(33005, "a");
   tArtist.insert(33006, "e");
 }
Пример #6
0
 protected void createDistinctClobFetchWithToManyJoin() throws Exception {
   tClobMaster.insert(1, "cm1 clob", "cm1");
   tClobMaster.insert(2, "cm2 clob", "cm2");
   tClobMaster.insert(3, "cm3 clob", "cm3");
   tClobDetail.insert(1, 1, "cd11");
   tClobDetail.insert(2, 2, "cd21");
   tClobDetail.insert(3, 2, "cd22");
   tClobDetail.insert(4, 3, "cd31");
 }
  @Override
  protected void setUpAfterInjection() throws Exception {
    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");

    tPainting = new TableHelper(dbHelper, "PAINTING");
    tPainting
        .setColumns("PAINTING_ID", "ARTIST_ID", "PAINTING_TITLE", "ESTIMATED_PRICE")
        .setColumnTypes(Types.INTEGER, Types.BIGINT, Types.VARCHAR, Types.DECIMAL);
  }
Пример #8
0
  @Test
  public void testPrefetch() throws Exception {
    createTwoArtists();
    tPainting.insert(45, 3, "One");
    tPainting.insert(48, 3, "Two");

    final Artist a3 =
        SelectById.query(Artist.class, 3)
            .prefetch(Artist.PAINTING_ARRAY.joint())
            .selectOne(context);

    interceptor.runWithQueriesBlocked(
        new UnitTestClosure() {

          @Override
          public void execute() {
            assertNotNull(a3);
            assertEquals("artist3", a3.getArtistName());
            assertEquals(2, a3.getPaintingArray().size());

            a3.getPaintingArray().get(0).getPaintingTitle();
            a3.getPaintingArray().get(1).getPaintingTitle();
          }
        });
  }
  @Test
  public void testRefreshingToOne() throws Exception {

    createOneArtistOnePaintingDataSet();

    Painting p = Cayenne.objectForPK(context, Painting.class, 1);

    // resolve artist once before running non-refreshing query, to check that we do
    // not refresh the object

    Artist a = Cayenne.objectForPK(context, Artist.class, 1);
    long v = a.getSnapshotVersion();
    int writeCalls = a.getPropertyWrittenDirectly();
    assertEquals("a1", a.getArtistName());

    assertEquals(1, tArtist.update().set("ARTIST_NAME", "a2").where("ARTIST_ID", 1).execute());

    RelationshipQuery toOne =
        new RelationshipQuery(p.getObjectId(), Painting.TO_ARTIST_PROPERTY, true);

    List<Artist> related = context.performQuery(toOne);
    assertEquals(1, related.size());
    assertTrue(related.contains(a));
    assertEquals("a2", a.getArtistName());
    assertTrue(
        "Looks like relationship query didn't cause a snapshot refresh",
        v < a.getSnapshotVersion());
    assertTrue(
        "Looks like relationship query didn't cause a snapshot refresh",
        writeCalls < a.getPropertyWrittenDirectly());
  }
  @Override
  protected void setUpAfterInjection() throws Exception {
    dbHelper.deleteAll("PAINTING_INFO");
    dbHelper.deleteAll("PAINTING");
    dbHelper.deleteAll("ARTIST_EXHIBIT");
    dbHelper.deleteAll("ARTIST_GROUP");
    dbHelper.deleteAll("ARTIST");
    dbHelper.deleteAll("EXHIBIT");
    dbHelper.deleteAll("GALLERY");

    tArtist = new TableHelper(dbHelper, "ARTIST");
    tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");

    tPainting = new TableHelper(dbHelper, "PAINTING");
    tPainting
        .setColumns("PAINTING_ID", "PAINTING_TITLE", "ARTIST_ID", "ESTIMATED_PRICE")
        .setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.BIGINT, Types.DECIMAL);

    tPaintingInfo = new TableHelper(dbHelper, "PAINTING_INFO");
    tPaintingInfo.setColumns("PAINTING_ID", "TEXT_REVIEW");

    tExhibit = new TableHelper(dbHelper, "EXHIBIT");
    tExhibit.setColumns("EXHIBIT_ID", "GALLERY_ID", "OPENING_DATE", "CLOSING_DATE");

    tArtistExhibit = new TableHelper(dbHelper, "ARTIST_EXHIBIT");
    tArtistExhibit.setColumns("ARTIST_ID", "EXHIBIT_ID");

    tGallery = new TableHelper(dbHelper, "GALLERY");
    tGallery.setColumns("GALLERY_ID", "GALLERY_NAME");
  }
  @Override
  protected void setUpAfterInjection() throws Exception {
    dbHelper.deleteAll("PAINTING_INFO");
    dbHelper.deleteAll("PAINTING");
    dbHelper.deleteAll("ARTIST_EXHIBIT");
    dbHelper.deleteAll("ARTIST_GROUP");
    dbHelper.deleteAll("ARTIST");
    dbHelper.deleteAll("EXHIBIT");
    dbHelper.deleteAll("GALLERY");

    tArtist = new TableHelper(dbHelper, "ARTIST");
    tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
  }
  @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");
  }
  public void testLocalObject_FFE_InvalidID() throws Exception {
    tArtist.insert(777, "AA");

    final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 777);

    Artist a3 = context2.localObject(a1);
    assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState());

    context1.invalidateObjects(a1);
    tArtist.deleteAll();

    assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState());

    try {
      a3.getArtistName();

      fail(
          "FaultFailureException wasn't thrown on attempt to "
              + "resolve HOLLOW object with no backing DB row");
    } catch (FaultFailureException e) {
      // expected
    }
  }
  public void testLocalObject_SameContext() throws Exception {
    tArtist.insert(456, "Bla");

    final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);

    interceptor.runWithQueriesBlocked(
        new UnitTestClosure() {

          public void execute() {
            Artist a2 = context1.localObject(a1);
            assertSame(a2, a1);
          }
        });
  }
  protected void createTwoArtistsWithExhibitsDataSet() throws Exception {
    tArtist.insert(11, "artist2");
    tArtist.insert(101, "artist3");

    tGallery.insert(25, "gallery1");
    tGallery.insert(31, "gallery2");
    tGallery.insert(45, "gallery3");

    Timestamp now = new Timestamp(System.currentTimeMillis());

    tExhibit.insert(1, 25, now, now);
    tExhibit.insert(2, 31, now, now);
    tExhibit.insert(3, 45, now, now);
    tExhibit.insert(4, 25, now, now);

    tArtistExhibit.insert(11, 2);
    tArtistExhibit.insert(11, 4);
    tArtistExhibit.insert(101, 1);
    tArtistExhibit.insert(101, 3);
    tArtistExhibit.insert(101, 4);
  }
  public void testLocalObject_NotInCache() throws Exception {
    tArtist.insert(456, "Bla");

    final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);

    interceptor.runWithQueriesBlocked(
        new UnitTestClosure() {

          public void execute() {
            Artist a3 = context2.localObject(a1);
            assertNotSame(a3, a1);
            assertEquals(a3.getObjectId(), a1.getObjectId());
            assertSame(context2, a3.getObjectContext());
          }
        });
  }
  public void testPrefetchingToOneNull() throws Exception {

    tPainting.insert(6, "p_Xty", null, 1000);

    SelectQuery q = new SelectQuery(Painting.class);
    q.addPrefetch(Painting.TO_ARTIST_PROPERTY);

    final List<Painting> paintings = context.performQuery(q);

    queryInterceptor.runWithQueriesBlocked(
        new UnitTestClosure() {

          public void execute() {
            assertEquals(1, paintings.size());

            Painting p2 = paintings.get(0);
            assertNull(p2.readProperty(Painting.TO_ARTIST_PROPERTY));
          }
        });
  }
Пример #18
0
 private void createTwoArtists() throws Exception {
   tArtist.insert(2, "artist2");
   tArtist.insert(3, "artist3");
 }
Пример #19
0
 protected void createDistinctClobFetchDataSet() throws Exception {
   tClobMaster.insert(1, "cm1 clob", "cm1");
   tClobMaster.insert(2, "cm2 clob", "cm2");
   tClobMaster.insert(3, "cm3 clob", "cm3");
 }
 protected void createTwoArtistsAndTwoPaintingsDataSet() throws Exception {
   tArtist.insert(11, "artist2");
   tArtist.insert(101, "artist3");
   tPainting.insert(6, "p_artist3", 101, 1000);
   tPainting.insert(7, "p_artist2", 11, 2000);
 }
  private void createTwoArtistsThreePaintingsDataSet() throws Exception {

    createTwoArtistsTwoPaintingsDataSet();
    tPainting.insert(3, 2, "X");
  }
 private void createFourPaintings() throws Exception {
   tPainting.insert(33001, null, "A", 3000);
   tPainting.insert(33002, null, "B", 2000);
   tPainting.insert(33003, null, "C", 1000);
   tPainting.insert(33004, null, "C", 500);
 }
 protected void createSingleArtistDataSet() throws Exception {
   tArtist.insert(33001, "aaa");
 }
 private void createTwoArtistsTwoPaintings() throws Exception {
   tArtist.insert(33001, "A");
   tArtist.insert(33002, "B");
   tPainting.insert(33005, 33001, "C", 500);
   tPainting.insert(33006, 33002, "C", 500);
 }
 @Before
 public void setUp() throws Exception {
   tArtist = new TableHelper(dbHelper, "ARTIST");
   tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
 }
  private void createOneArtistOnePaintingDataSet() throws Exception {

    tArtist.insert(1, "a1");
    tPainting.insert(1, "p1", 1);
  }