本文整理汇总了Java中com.avaje.ebean.EbeanServer类的典型用法代码示例。如果您正苦于以下问题:Java EbeanServer类的具体用法?Java EbeanServer怎么用?Java EbeanServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EbeanServer类属于com.avaje.ebean包,在下文中一共展示了EbeanServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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();
}
示例3: loadKundedbTestData
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
private void loadKundedbTestData(Map<String, List<Object>> data) {
// load initial test data
EbeanServer kundedb = Ebean.getServer("kundedb");
if (kundedb.find(Kunde.class).findRowCount() == 0) {
List<Object> kunder = data.get("kunder");
List<Object> datafiler = data.get("datafiler");
List<Object> kundefiler = data.get("kundefiler");
List<Object> posisjoner = data.get("posisjoner");
List<Object> produkter = data.get("produkter");
if ( kunder !=null && kunder.size() > 0 )kundedb.save(kunder);
if ( datafiler !=null && datafiler.size() > 0 )kundedb.save(datafiler);
if ( kundefiler!=null && kundefiler.size() > 0 )kundedb.save(kundefiler);
if ( posisjoner!=null && posisjoner.size() > 0 )kundedb.save(posisjoner);
if ( produkter !=null && produkter.size() > 0 )kundedb.save(produkter);
}
}
示例4: testCallable_withInOut
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
@Test
public void testCallable_withInOut() {
EbeanServer server = Ebean.getDefaultServer();
//create or replace function sp_insert (p_name VARCHAR, OUT p_id INTEGER)
CallableSql callableSql = server.createCallableSql("{call sp_insert2(?, ?)}");
callableSql.setParameter(1, "rob name");
callableSql.registerOut(1, Types.VARCHAR);
callableSql.registerOut(2, Types.INTEGER);
server.execute(callableSql);
String nameOut = (String)callableSql.getObject(1);
Integer intOut = (Integer)callableSql.getObject(2);
assertThat(nameOut).isNotNull();
assertThat(intOut).isNotNull();
}
示例5: run
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
@Override
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
// The existing database with migrations managed by Liquibase.
DataSourceFactory outdatedDb = configuration.getDatabaseConfig();
try (CloseableLiquibase outdatedLiquibase = createLiquibase(outdatedDb)) {
// A temporary database that starts out empty and then gets the autogenerated Ebean table definitions applied.
DataSourceFactory freshDb = EbeanConfigUtils.clone(outdatedDb);
String url = outdatedDb.getUrl();
freshDb.setUrl(url.substring(0, url.lastIndexOf("/")) + "/migrationdiff");
// Creating the Ebean server makes it apply its table definitions to the database immediately.
ServerConfig serverConfig = EbeanConfigUtils.createServerConfig(freshDb);
serverConfig.setDdlGenerate(true);
serverConfig.setDdlRun(true);
EbeanServer ebeanServer = EbeanServerFactory.create(serverConfig);
try (CloseableLiquibase freshLiquibase = createLiquibase(freshDb)) {
// Create and print the differences between the two databases, i.e. a migration that should be applied to update to the newest Ebean definitions.
DiffResult diff = outdatedLiquibase.diff(freshLiquibase.getDatabase(), outdatedLiquibase.getDatabase(), CompareControl.STANDARD);
DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diff, new DiffOutputControl(false, false, true));
diffToChangeLog.print(System.out);
}
}
}
示例6: createEbeanServerInstance
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
public EbeanServer createEbeanServerInstance(PluginDataResolver pluginDataResolver) {
File myDataDir;
try {
myDataDir = new File(pluginDataResolver.getPluginDatabaseDirectory());
} catch (IOException e) {
Loggers.SERVER.error("tcDebRepository EbeanServerProvider : Failed to get database directory location");
Loggers.SERVER.debug(e);
return null;
}
if (myDataDir.exists() && myDataDir.isDirectory() && myDataDir.canWrite()) {
ServerConfig config = new ServerConfig();
config.setName("db");
config.loadFromProperties();
DataSourceConfig dsConfig = config.getDataSourceConfig();
dsConfig.setUrl(
"jdbc:h2:file:" + myDataDir.getAbsolutePath() + File.separator + "tcDebRepositoryDB;DB_CLOSE_ON_EXIT=FALSE");
config.setDataSourceConfig(dsConfig);
Loggers.SERVER.debug(config.getDataSourceConfig().getUsername());
// set as default and register so that Model can be
// used if desired for save() and update() etc
config.setDefaultServer(true);
config.setRegister(true);
config.addPackage("debrepo.teamcity.ebean");
Loggers.SERVER.debug("EbeanServerProvider :: ebean Properties are: " + config.getProperties().toString());
return EbeanServerFactory.create(config);
}
return null;
}
示例7: init
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
public static void init(Plugin plugin, EbeanServer db) {
$.thr(!$.nil(inst), "init");
inst = new PlayerPointsAPI(db);
if (!nil(Bukkit.getPluginManager().getPlugin("PlaceholderAPI"))) {
val placeholder = new PPlaceholder(plugin);
placeholder.hook();
plugin.getLogger().info("Hook to PlaceholderAPI okay");
}
}
示例8: 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");
}
示例9: 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();
}
示例10: setupEBean
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
/**
* Some awkward ritual that Bukkit requires to initialize all the DB classes.
* Does nothing if they have already been set up.
*/
private void setupEBean() {
try {
EbeanServer db = getDatabase();
for (Class<?> c : getDatabaseClasses())
db.find(c).findRowCount();
} catch (Exception ignored) {
log.info("Initializing database tables.");
installDDL();
}
}
示例11: loadQubaTestData
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
private void loadQubaTestData(Map<String, List<Object>> data) {
// load initial test data
EbeanServer quba = Ebean.getServer("quba");
if (quba.find(QubaStation.class).findRowCount() == 0) {
List<Object> stations = data.get("stations");
quba.save(stations);
List<Object> stationProfiles = data.get("stationprofiles");
quba.save(stationProfiles);
List<Object> subjectives = data.get("subjectives");
// Lage ny subjective for Gullfaks for i dag, slik at vi har noe å
// sende til produksjon i web-klienten
QubaSubjective subjective = new QubaSubjective();
DateTime now = DateTime.now(PoseidonService.getTimeZone());
DateTime noon = now.withTime(12,0,0,0);
subjective.pk.stationid = 3L;
subjective.pk.pindexid = 31;
subjective.pk.runDate = noon.toDate();
subjective.pk.validDate= subjective.pk.runDate;
subjective.pk.levelid = 0;
subjectives.add(subjective);
quba.save(subjectives);
}
}
示例12: loadDistdbTestData
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
private void loadDistdbTestData(Map<String, List<Object>> data) {
// load initial test data
EbeanServer dist = Ebean.getServer("dist");
if (dist.find(DistLocation.class).findRowCount() == 0) {
List<Object> locations = data.get("locations");
dist.save(locations);
}
}
示例13: load
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
public static UseTokenWrapper load(Player p) {
return L2Pool.load(String.valueOf(p.getUniqueId()) + ":use_token", () -> {
EbeanServer db = Main.getDataSource();
KitUseToken useToken = db.find(KitUseToken.class, p.getUniqueId());
if (useToken == null || useToken.getUseToken() == null) {
return new UseTokenWrapper(new HashMap<>());
}
return new UseTokenWrapper((Map<String, Integer>) JSONValue.parse(useToken.getUseToken()));
});
}
示例14: save
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
public static void save(Player p, UseTokenWrapper wrapper) {
EbeanServer db = Main.getDataSource();
int result = db.createUpdate(KitUseToken.class, "update kit_use_token set use_token = :token where id = :id;")
.setParameter("token", JSONObject.toJSONString(wrapper.all))
.setParameter("id", p.getUniqueId())
.execute();
if (result < 1) {
db.createUpdate(KitUseToken.class, "insert into kit_use_token set id = :id, name = :name, use_token = :token;")
.setParameter("id", p.getUniqueId())
.setParameter("name", p.getName())
.setParameter("token", JSONObject.toJSONString(wrapper.all))
.execute();
}
}
示例15: save
import com.avaje.ebean.EbeanServer; //导入依赖的package包/类
public T save(T item) {
EbeanServer ws = this.daConfig.getWriteEbeanServer();
ws.beginTransaction();
ws.save(item);
ws.commitTransaction();
return item;
}