当前位置: 首页>>代码示例>>Java>>正文


Java EbeanServer.publish方法代码示例

本文整理汇总了Java中com.avaje.ebean.EbeanServer.publish方法的典型用法代码示例。如果您正苦于以下问题:Java EbeanServer.publish方法的具体用法?Java EbeanServer.publish怎么用?Java EbeanServer.publish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.avaje.ebean.EbeanServer的用法示例。


在下文中一共展示了EbeanServer.publish方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDelete_whenPublished

import com.avaje.ebean.EbeanServer; //导入方法依赖的package包/类
@Test
public void testDelete_whenPublished() {

  Link link1 = new Link("Ld2");
  link1.save();
  EbeanServer server = Ebean.getDefaultServer();
  server.publish(Link.class, link1.getId());

  link1 = Ebean.find(Link.class).setId(link1.getId()).asDraft().findUnique();
  assertThat(link1.isDraft()).isTrue();

  // this is a soft delete (no automatic publish here, only updates draft)
  link1.delete();

  Link live = Ebean.find(Link.class).setId(link1.getId()).findUnique();
  assertThat(live).isNotNull();
  assertThat(live.isDraft()).isFalse();
  assertThat(live.isDeleted()).isFalse(); // soft delete state not published yet

  // this is a permanent delete (effectively has automatic publish)
  server.deletePermanent(link1);

  live = Ebean.find(Link.class).setId(link1.getId()).findUnique();
  assertThat(live).isNull();
}
 
开发者ID:ebean-orm-examples,项目名称:example-draftable,代码行数:26,代码来源:DocLinkTest.java

示例2: testDirtyState

import com.avaje.ebean.EbeanServer; //导入方法依赖的package包/类
@Test
public void testDirtyState() {

  Timestamp when = new Timestamp(System.currentTimeMillis());
  String comment = "Really interesting";

  Link link1 = new Link("Ls1");
  link1.setComment(comment);
  link1.setWhenPublish(when);
  link1.save();

  Link draft1 = Ebean.find(Link.class).setId(link1.getId()).asDraft().findUnique();
  assertThat(draft1.isDirty()).isTrue();

  EbeanServer server = Ebean.getDefaultServer();

  Link linkLive = server.publish(Link.class, link1.getId(), null);
  assertThat(linkLive.getComment()).isEqualTo(comment);
  assertThat(linkLive.getWhenPublish()).isEqualTo(when);

  Link draft1b = Ebean.find(Link.class).setId(link1.getId()).asDraft().findUnique();
  assertThat(draft1b.isDirty()).isFalse();
  assertThat(draft1b.getComment()).isNull();
  assertThat(draft1b.getWhenPublish()).isNull();

}
 
开发者ID:ebean-orm-examples,项目名称:example-draftable,代码行数:27,代码来源:DocLinkTest.java

示例3: testDraftRestore

import com.avaje.ebean.EbeanServer; //导入方法依赖的package包/类
@Test
public void testDraftRestore() {

  Link link1 = new Link("Ldr1");
  link1.setLocation("firstLocation");
  link1.save();

  EbeanServer server = Ebean.getDefaultServer();

  Link live = server.publish(Link.class, link1.getId(), null);
  assertThat(live.isDraft()).isFalse();

  Link draftLink = Ebean.find(Link.class)
      .setId(link1.getId())
      .asDraft()
      .findUnique();

  draftLink.setLocation("secondLocation");
  draftLink.save();

  server.draftRestore(Link.class, link1.getId(), null);

  draftLink = Ebean.find(Link.class)
      .setId(link1.getId())
      .asDraft()
      .findUnique();

  assertThat(draftLink.getLocation()).isEqualTo("firstLocation");

}
 
开发者ID:ebean-orm-examples,项目名称:example-draftable,代码行数:31,代码来源:DocLinkTest.java

示例4: testDraftRestoreViaQuery

import com.avaje.ebean.EbeanServer; //导入方法依赖的package包/类
@Test
public void testDraftRestoreViaQuery() {

  Link link1 = new Link("Ldr1");
  link1.setLocation("firstLocation");
  link1.setComment("Banana");
  link1.save();

  EbeanServer server = Ebean.getDefaultServer();

  server.publish(Link.class, link1.getId(), null);

  Link draftLink = Ebean.find(Link.class)
      .setId(link1.getId())
      .asDraft()
      .findUnique();

  draftLink.setLocation("secondLocation");
  draftLink.setComment("A good change");
  draftLink.save();

  Query<Link> query = server.find(Link.class).where().eq("id", link1.getId()).query();
  List<Link> links = server.draftRestore(query);

  assertThat(links).hasSize(1);
  assertThat(links.get(0).getLocation()).isEqualTo("firstLocation");
  assertThat(links.get(0).isDirty()).isEqualTo(false);
  assertThat(links.get(0).getComment()).isNull();

}
 
开发者ID:ebean-orm-examples,项目名称:example-draftable,代码行数:31,代码来源:DocLinkTest.java

示例5: testSaveWithCascade

import com.avaje.ebean.EbeanServer; //导入方法依赖的package包/类
@Test
  public void testSaveWithCascade() {

    Organisation org = new Organisation("Org2");
    org.save();

    Document doc = new Document();
    doc.setTitle("Title1");
    doc.setOrganisation(org);
    doc.setBody("Body1");

    doc.getMedia().add(createMedia("media1"));
    doc.getMedia().add(createMedia("media2"));
    doc.save();

    EbeanServer server = Ebean.getDefaultServer();


    server.publish(Document.class, doc.getId(), null);

    Document fetchDoc = Ebean.find(Document.class).setId(doc.getId()).asDraft().findUnique();
    List<DocumentMedia> media = fetchDoc.getMedia();

    assertThat(media.size()).isEqualTo(2);

//    // delete one of the 'child' @DraftElement rows ...
//    SqlUpdate sqlUpdate = Ebean.createSqlUpdate("delete from document_media_draft where id = ?");
//    sqlUpdate.setParameter(1, doc.getMedia().get(0).getId());
//    sqlUpdate.execute();

    doc.getMedia().get(1).setDescription("mod");
    doc.getMedia().add(createMedia("media3"));
    doc.getMedia().remove(0);
    doc.setBody("Body2");
    doc.save();

    // publish will perform an insert, update and delete on child DocumentMedia
    // during the publish below with media1 being deleted
    Document liveBean = server.publish(Document.class, doc.getId(), null);
    assertThat(liveBean.getBody()).isEqualTo("Body2");
    assertThat(liveBean.getMedia().size()).isEqualTo(2);
    assertThat(liveBean.getMedia()).extracting("name").contains("media2","media3");

  }
 
开发者ID:ebean-orm-examples,项目名称:example-draftable,代码行数:45,代码来源:OrganisationTest.java

示例6: testSave

import com.avaje.ebean.EbeanServer; //导入方法依赖的package包/类
@Test
public void testSave() {

  Link link1 = new Link("LinkOne");
  link1.save();

  Link link2 = new Link("LinkTwo");
  link2.save();

  Link link3 = new Link("LinkThree");
  link3.save();

  EbeanServer server = Ebean.getDefaultServer();
  server.publish(Link.class, link1.getId(), null);
  server.publish(Link.class, link2.getId(), null);
  server.publish(Link.class, link3.getId(), null);

  Doc doc1 = new Doc("DocOne");
  doc1.getLinks().add(link1);
  doc1.getLinks().add(link2);
  doc1.save();

  Doc draftDoc1 = server.find(Doc.class)
      .setId(doc1.getId())
      .asDraft()
      .findUnique();

  assertThat(draftDoc1.getLinks()).hasSize(2);

  Doc liveDoc1 = server.publish(Doc.class, doc1.getId(), null);

  assertThat(liveDoc1.getLinks()).hasSize(2);
  assertThat(liveDoc1.getLinks()).extracting("id").contains(link1.getId(), link2.getId());


  draftDoc1.getLinks().remove(0);
  draftDoc1.getLinks().add(link3);

  draftDoc1.save();

  // publish with insert and delete of Links M2M relationship
  Doc liveDoc2 = server.publish(Doc.class, doc1.getId(), null);
  assertThat(liveDoc2.getLinks()).hasSize(2);
  assertThat(liveDoc2.getLinks()).extracting("id").contains(link2.getId(), link3.getId());

  // delete the draft and live beans (with associated children)
  draftDoc1.delete();
}
 
开发者ID:ebean-orm-examples,项目名称:example-draftable,代码行数:49,代码来源:DocLinkTest.java

示例7: testPublishViaQuery

import com.avaje.ebean.EbeanServer; //导入方法依赖的package包/类
@Test
public void testPublishViaQuery() {

  Link link1 = new Link("L1");
  link1.save();

  Link link2 = new Link("L2");
  link2.save();

  Link link3 = new Link("L3");
  link3.save();

  EbeanServer server = Ebean.getDefaultServer();

  List<Object> ids = new ArrayList<Object>();
  ids.add(link1.getId());
  ids.add(link2.getId());
  ids.add(link3.getId());

  Query<Link> pubQuery = server.find(Link.class)
      .where().idIn(ids)
      .order().asc("id");


  List<Link> pubList = server.publish(pubQuery);

  assertThat(pubList).hasSize(3);
  assertThat(pubList).extracting("id").contains(link1.getId(), link2.getId(), link3.getId());

}
 
开发者ID:ebean-orm-examples,项目名称:example-draftable,代码行数:31,代码来源:LinkQueryPublishTest.java

示例8: testSave

import com.avaje.ebean.EbeanServer; //导入方法依赖的package包/类
@Test
public void testSave() {

  Organisation org = new Organisation("OrgOne");
  org.save();

  assertNotNull(org.getId());

  Document doc = new Document();
  doc.setTitle("NewTitle");
  doc.setOrganisation(org);
  doc.setBody("Hello");

  doc.save();

  doc.setBody("Change content");
  doc.save();


  EbeanServer server = Ebean.getDefaultServer();

  Document draftDoc = server.find(Document.class)
      .asDraft()
      .setId(doc.getId())
      .findUnique();

  assertNotNull(draftDoc);

  Document liveDoc = server.find(Document.class)
      .setId(doc.getId())
      .findUnique();
  assertNull(liveDoc);


  server.publish(Document.class, doc.getId(), null);

  doc.setTitle("Mod1");
  doc.save();

  server.publish(Document.class, doc.getId(), null);

}
 
开发者ID:ebean-orm-examples,项目名称:example-draftable,代码行数:43,代码来源:OrganisationTest.java


注:本文中的com.avaje.ebean.EbeanServer.publish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。