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


Java Customer.save方法代码示例

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


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

示例1: testInsert

import org.example.domain.Customer; //导入方法依赖的package包/类
@Test
public void testInsert() {
  
  Transaction txn = Customer.db().beginTransaction();
  try {
    txn.setBatchMode(true);
    txn.setBatchSize(10);
    
    // turn of getGeneratedKeys if we don't need to use the 
    // customer bean instances after we have inserted them
    txn.setBatchGetGeneratedKeys(false);
    
    for (int i = 0; i < 40; i++) {
      Customer c = new Customer();
      c.setName("batch insert test "+i);
      c.save();
    }
    
    txn.commit();
    
  } finally {
    txn.end();
  }
  
}
 
开发者ID:ebean-orm-examples,项目名称:avaje-ebeanorm-examples,代码行数:26,代码来源:BatchInsertTest.java

示例2: test

import org.example.domain.Customer; //导入方法依赖的package包/类
@Test
public void test() {
  
  Customer customer = new Customer();
  customer.setName("slash\\monkey");
  customer.save();

  List<Customer> list = Customer.find.where().eq("name", "slash\\monkey").findList();    
  Assert.assertEquals("equals with slash", 1, list.size());

  list = Customer.find.where().like("name", "slash\\mon%").findList();
  Assert.assertEquals("like with slash", 1, list.size());

  list = Customer.find.where().raw("name like 'slash\\mon%' escape''").findList();
  Assert.assertEquals("like with slash using raw", 1, list.size());

  list = Customer.find.where().raw("name like ? escape''", "slash\\mon%").findList();
  Assert.assertEquals("like with slash using raw", 1, list.size());

  list = Customer.find.where().raw("name like 'slash\\mon%'").findList();
  Assert.assertEquals("raw like with no escape - not found", 0, list.size());

}
 
开发者ID:ebean-orm-examples,项目名称:avaje-ebeanorm-examples,代码行数:24,代码来源:SlashInLikeTest.java

示例3: test

import org.example.domain.Customer; //导入方法依赖的package包/类
@Test
public void test() {

  Ebean.getServer(null);
  
  Customer customer = new Customer();
  customer.setName("Rob");
  customer.save();
  
  Transaction txn = Customer.db().beginTransaction();
  txn.setBatchMode(true);
  try {
  
    for (int i = 0; i < 2; i++) {
      Customer cust = new Customer();
      cust.setName("Batch insert "+i);
      cust.save();
    }
    
    txn.commit();
    
  } finally {
    txn.end();
  }
}
 
开发者ID:ebean-orm-examples,项目名称:avaje-ebeanorm-examples,代码行数:26,代码来源:AutoCommitTest.java

示例4: update

import org.example.domain.Customer; //导入方法依赖的package包/类
@Test
public void update() {//throws InterruptedException {

  Customer cust = server.find(Customer.class)
      .where().idEq(2)
      .setUseDocStore(true)
      .findOne();

  cust.setName("Cust NonAddress");
  cust.save();

  sleepToPropagate();

  //Thread.sleep(4000);

  List<Order> orders = server.find(Order.class)
      .where().eq("customer.id", cust.getId())
      .setUseDocStore(true)
      .findList();

  //Thread.sleep(4000);

  for (Order order : orders) {
    assertEquals(order.getCustomer().getName(), cust.getName());
  }

  List<Contact> contacts = server.find(Contact.class)
      .where().eq("customer.id", cust.getId())
      .setUseDocStore(true)
      .findList();

  for (Contact contact : contacts) {
    assertEquals(contact.getCustomer().getName(), cust.getName());
  }
}
 
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:36,代码来源:SyncCustNameUpdateTest.java

示例5: findIterate

import org.example.domain.Customer; //导入方法依赖的package包/类
@Test
public void findIterate() {

  Customer cust = new Customer();
  cust.setName("foo");
  cust.setStatus(Customer.Status.GOOD);
  cust.save();

  List<Long> ids = new QCustomer()
      .status.equalTo(Customer.Status.GOOD)
      .findIds();

  assertThat(ids).isNotEmpty();


  Map<List, Customer> map = new QCustomer()
      .status.equalTo(Customer.Status.GOOD)
      .findMap();

  assertThat(map.size()).isEqualTo(ids.size());

  QueryIterator<Customer> iterate = new QCustomer()
      .status.equalTo(Customer.Status.GOOD)
      .findIterate();

  try {
    while (iterate.hasNext()) {
      Customer customer = iterate.next();
      customer.getName();
    }
  } finally {
    iterate.close();
  }
}
 
开发者ID:ebean-orm,项目名称:ebean-querybean,代码行数:35,代码来源:QCustomerTest.java

示例6: testInsert

import org.example.domain.Customer; //导入方法依赖的package包/类
@Test
public void testInsert() {
  
  Customer customer = new Customer();
  customer.setName("John");
  
  Map<String,String> tags = new HashMap<>();
  tags.put("height","100");
  tags.put("length","400");
  tags.put("trim","large");
  
  customer.setTags(tags);
  customer.save();
  
  
  Customer customer2 = new Customer();
  customer2.setName("Ringo");
  
  Map<String,String> tags2 = new HashMap<>();
  tags2.put("height","150");
  tags2.put("length","400");
  
  customer2.setTags(tags2);
  customer2.save();
  
  List<Customer> all = Customer.find.all();
  for (Customer cust : all) {
    System.out.println(cust);
  }
  
  // find John but not Ringo ...
  List<Customer> some = Customer.find.where()
      .raw("defined(tags,'trim')")
      .findList();
  
  for (Customer largeHeight : some) {
    System.out.println(largeHeight);
  }
  
}
 
开发者ID:ebean-orm-examples,项目名称:avaje-ebeanorm-examples,代码行数:41,代码来源:HstoreTest.java

示例7: testModifyWithPutAndClear

import org.example.domain.Customer; //导入方法依赖的package包/类
@Test
public void testModifyWithPutAndClear() {
  
  Customer customer = new Customer();
  customer.setName("diff on map");
  
  Map<String,String> tags = new HashMap<>();
  tags.put("height","100");
  
  customer.setTags(tags);
  customer.save();

  Customer custToMod = Customer.find.byId(customer.getId());
  Assert.assertEquals(Long.valueOf(1), Long.valueOf(custToMod.getVersion()));
  
  Map<String, String> tags2 = custToMod.getTags();
  tags2.put("length", "200");
  tags2.put("height", "23");
  
  System.out.println("-- update after put new values...");
  custToMod.update();
  Assert.assertEquals(Long.valueOf(2), Long.valueOf(custToMod.getVersion()));
  
  custToMod.getTags().clear();
  System.out.println("-- update after a clear ...");
  custToMod.save();

  Assert.assertEquals(Long.valueOf(3), Long.valueOf(custToMod.getVersion()));

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

示例8: testInsert

import org.example.domain.Customer; //导入方法依赖的package包/类
@Transactional
@Test
public void testInsert() throws IOException {
  
  Customer customer = new Customer();
  customer.setName("Frankie");
  
  Map<String,String> tags = new HashMap<>();
  tags.put("height","100");
  tags.put("length","400");
  tags.put("trim","large");
  tags.put("colour","red");

  customer.setTags(tags);
  customer.save();
  
  Assert.assertNotNull(customer.getId());

  String json = Ebean.json().toJson(customer);
  System.out.println(json);

  Customer customer1 = Ebean.json().toBean(Customer.class, json);

  assertEquals(customer.getId(), customer1.getId());
  assertEquals(customer.getName(), customer1.getName());
  assertEquals(customer.getTags().size(), customer1.getTags().size());
  assertEquals(customer.getTags().get("height"), customer1.getTags().get("height"));
  assertEquals("400", customer1.getTags().get("length"));
  assertEquals("large", customer1.getTags().get("trim"));


  Customer customer2 = Customer.find.byId(customer.getId());

  assertEquals(customer.getId(), customer2.getId());
  assertEquals(customer.getName(), customer2.getName());
  assertEquals(customer.getTags().size(), customer2.getTags().size());
  assertEquals(customer.getTags().get("height"), customer2.getTags().get("height"));
  assertEquals("400", customer2.getTags().get("length"));
  assertEquals("large", customer2.getTags().get("trim"));

  customer.setTags(new HashMap<String, String>());
  String jsonWithEmpty = Ebean.json().toJson(customer);
  System.out.println("WITH EMPTY-> "+jsonWithEmpty);
  Customer customerWithEmpty = Ebean.json().toBean(Customer.class, jsonWithEmpty);
  assertEquals(0, customerWithEmpty.getTags().size());


  customer.setTags(null);
  String jsonWithNull = Ebean.json().toJson(customer);
  System.out.println("WITH NULL-> " + jsonWithNull);
  Customer customerWithNull = Ebean.json().toBean(Customer.class, jsonWithNull);
  assertNull(customerWithNull.getTags());
}
 
开发者ID:ebean-orm-examples,项目名称:avaje-ebeanorm-examples,代码行数:54,代码来源:BasicInsertTest.java

示例9: testUpdateWhenNoChange

import org.example.domain.Customer; //导入方法依赖的package包/类
@Test
public void testUpdateWhenNoChange() {
  
  Customer customer = new Customer();
  customer.setName("Frank");
  
  Map<String,String> tags = new HashMap<>();
  tags.put("height","100");
  tags.put("length","400");
  
  customer.setTags(tags);
  customer.save();
  
  Timestamp whenUpdated = customer.getWhenUpdated();
  
  Customer cust2 = Customer.find.byId(customer.getId());
  
  // no change so no update occurs
  cust2.save();
  
  Assert.assertEquals(whenUpdated, cust2.getWhenUpdated());
  
  // set to null so update will occur
  cust2.setTags(null);
  cust2.save();
  
  Assert.assertNotEquals(whenUpdated, cust2.getWhenUpdated());
  
  // check that the value is now null
  Customer cust3 = Customer.find.byId(customer.getId());
  Assert.assertNull(cust3.getTags());
  
}
 
开发者ID:ebean-orm-examples,项目名称:avaje-ebeanorm-examples,代码行数:34,代码来源:HstoreTest.java


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