@Test
  public void testBasicOperations() {

    Account e = buildAccount(-1);

    // Get the default EbeanServer and save
    EbeanServer server = Ebean.getServer(null);
    server.save(e);
    Assert.assertNotNull(e.getId());

    e.setEmail("banana");
    server.update(e);

    // find by id
    Account e2 = server.find(Account.class, e.getId());
    Assert.assertNotNull("we found it in the db", e2);
    Assert.assertTrue("different instance", e2 != e);
    Assert.assertEquals("updated description", "banana", e2.getEmail());

    server.delete(e2);

    Account e3 = server.find(Account.class, e.getId());
    Assert.assertNull("its been deleted", e3);

    Query<Card> query = Ebean.find(Card.class);
  }
  @Transactional
  public void doSomething(EBasicVer v) {

    EbeanServer server = Ebean.getServer(null);

    inMethodTransaction = server.currentTransaction();

    Transaction t = server.createTransaction();
    SqlUpdate u =
        server.createSqlUpdate("update e_basicver set last_update = last_update+1 where id = ?");
    u.setParameter(1, v.getId());
    int count = server.execute(u, t);
    Assert.assertEquals(1, count);

    t.commit();

    v.setName("some change");
    try {
      Ebean.save(v);
      // never get here
      Assert.assertTrue(false);
    } catch (PersistenceException e) {
      throw e;
    }
  }
  public static void createDB() throws IOException {

    EbeanServer server = Ebean.getServer(serverName);

    ServerConfig config = new ServerConfig();

    DdlGenerator ddl = new DdlGenerator((SpiEbeanServer) server, new PostgresPlatform(), config);

    // Create
    ddl.runScript(false, ddl.generateCreateDdl());
  }
  @Ignore
  @Test
  public void testBulkUpdate() throws IOException {

    ResetBasicData.reset();

    EbeanServer server = Ebean.getServer(null);
    JsonContext jsonContext = server.json();

    StringWriter writer = new StringWriter();
    JsonGenerator generator = jsonContext.createGenerator(writer);

    List<Customer> customers = Ebean.find(Customer.class).findList();

    for (Customer customer : customers) {

      customer.setName(customer.getName() + "esMod");
      PathProperties updateProps = PathProperties.parse("name");

      generator.writeStartObject();
      generator.writeFieldName("update");
      generator.writeStartObject();
      generator.writeStringField("_id", customer.getId().toString());
      generator.writeStringField("_type", "customer");
      generator.writeStringField("_index", "customer");
      generator.writeEndObject();
      generator.writeEndObject();
      generator.writeRaw("\n");

      generator.writeStartObject();
      generator.writeFieldName("doc");
      jsonContext.toJson(customer, generator, updateProps);
      generator.writeEndObject();
      generator.writeRaw("\n");
    }

    generator.close();
    String json = writer.toString();

    post("http://localhost:9200/_bulk", json);

    // curl -s -XPOST localhost:9200/_bulk

    //    { "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
    //    { "doc" : {"field2" : "value2"} }

  }
  @Ignore
  @Test
  public void test() throws IOException {

    ResetBasicData.reset();

    EbeanServer server = Ebean.getServer(null);
    JsonContext jsonContext = server.json();

    List<Customer> customers = Ebean.find(Customer.class).findList();

    PathProperties paths = PathProperties.parse("name, status, anniversary");
    for (Customer customer : customers) {

      String json = jsonContext.toJson(customer, paths);
      put("http://localhost:9200/customer/customer/" + customer.getId(), json);
    }
  }
  @Test
  public void testBatch() {
    int rowsNumber = 100;

    EbeanServer server = Ebean.getServer(null);
    Transaction transaction = server.beginTransaction();
    transaction.setBatchMode(true);
    transaction.setBatchSize(30);
    try {
      for (int i = 0; i < rowsNumber; i++) {
        server.save(buildAccount(i));
      }
      server.commitTransaction();
    } finally {
      server.endTransaction();
    }
    List<Account> all = server.find(Account.class).select("name").findList();
    Assert.assertEquals("Batch update", rowsNumber, all.size());
  }