本文整理汇总了Java中com.avaje.ebean.EbeanServerFactory类的典型用法代码示例。如果您正苦于以下问题:Java EbeanServerFactory类的具体用法?Java EbeanServerFactory怎么用?Java EbeanServerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EbeanServerFactory类属于com.avaje.ebean包,在下文中一共展示了EbeanServerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SQLOfflineTeamHandler
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
public SQLOfflineTeamHandler()
{
ServerConfig config = new ServerConfig();
config.setDataSourceConfig(MWAPI.getConfig().getDataSourceConfig());
config.addClass(BasicTeam.class);
server = EbeanServerFactory.create(config);
try
{
server.find(BasicTeam.class).findRowCount();
}
catch (Exception e)
{
DdlGenerator gen = ((DefaultServer) server).getDdlGenerator();
gen.runScript(true, gen.generateCreateDdl());
}
}
示例2: SQLOfflineGameHandler
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
public SQLOfflineGameHandler()
{
ServerConfig config = new ServerConfig();
config.setDataSourceConfig(MWAPI.getConfig().getDataSourceConfig());
config.addClass(BasicGame.class);
config.addClass(MapScalarTypeConverter.class);
server = EbeanServerFactory.create(config);
try
{
server.find(BasicGame.class).findRowCount();
}
catch (Exception e)
{
DdlGenerator gen = ((DefaultServer) server).getDdlGenerator();
gen.runScript(true, gen.generateCreateDdl());
}
}
示例3: SQLOfflineUserHandler
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
public SQLOfflineUserHandler()
{
ServerConfig config = new ServerConfig();
config.setDataSourceConfig(MWAPI.getConfig().getDataSourceConfig());
config.addClass(BasicUser.class);
server = EbeanServerFactory.create(config);
try
{
server.find(BasicUser.class).findRowCount();
}
catch (Exception e)
{
DdlGenerator gen = ((DefaultServer) server).getDdlGenerator();
gen.runScript(true, gen.generateCreateDdl());
}
}
示例4: init
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
/**
* Initialize the database (by running patches if required)
*/
private void init(Configuration configuration) {
// Creates the listeners map
listeners = Collections.synchronizedMap(new HashMap<>());
// Register the Ebean server as the default one
ServerConfig serverConfig = getEbeanConfig().serverConfigs().get(getEbeanServerDefaultName());
serverConfig.setBackgroundExecutorShutdownSecs(getEbeanCacheShutdownDelay());
serverConfig.setBackgroundExecutorCorePoolSize(getEbeanCacheThreadPoolSize());
serverConfig.add(new CustomBeanPersistController(listeners));
Ebean.register(EbeanServerFactory.create(serverConfig), true);
// Unregister ebean from the Runtime (Shutdown hooks are bad !)
BizDockEbeanShutdownManager.killThisBloodyShutdownHook();
if (isPatcheable(configuration)) {
log.info("Running the patch for the release " + getRelease());
patch(log);
updateRelease();
} else {
log.info("The application is up to date, no patch to run");
}
}
示例5: InMemoryEbeanServer
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
public InMemoryEbeanServer() {
// Create in-memory database configuration.
DataSourceConfig dbConfig = new DataSourceConfig();
dbConfig.setUsername("sa");
dbConfig.setPassword("");
dbConfig.setUrl("jdbc:h2:mem:tests2;DB_CLOSE_DELAY=-1");
dbConfig.setDriver("org.h2.Driver");
ServerConfig config = new ServerConfig();
config.setName("h2");
config.setDataSourceConfig(dbConfig);
config.setDefaultServer(true);
for (Class<?> entity : EbeanEntities.getEntities()) {
config.addClass(entity);
}
config.setDdlGenerate(true);
config.setDdlRun(true);
server = EbeanServerFactory.create(config);
ddl = ((SpiEbeanServer) server).getDdlGenerator();
}
示例6: run
import com.avaje.ebean.EbeanServerFactory; //导入依赖的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);
}
}
}
示例7: run
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
@Override
public void run(HasDatabaseConfiguration configuration, Environment environment) throws Exception {
ExtendedDataSourceFactory dbConfig = configuration.getDatabaseConfig();
log.info("Connecting to database on '{}' with username '{}'.", dbConfig.getUrl(), dbConfig.getUser());
if (dbConfig.isMigrationsEnabled()) {
try {
applyMigrations(dbConfig, environment.metrics());
} catch (Exception e) {
log.error("Error applying database migrations! {}", e.getMessage());
throw e;
}
} else {
log.info("Database migrations disabled.");
}
ServerConfig serverConfig = EbeanConfigUtils.createServerConfig(dbConfig);
ebeanServer = EbeanServerFactory.create(serverConfig);
Preconditions.checkNotNull(ebeanServer);
environment.healthChecks().register("ebean-" + ebeanServer.getName(), new EbeanHealthCheck(ebeanServer));
}
示例8: createEbeanServerInstance
import com.avaje.ebean.EbeanServerFactory; //导入依赖的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;
}
示例9: init
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
final void init(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) {
this.loader = loader;
this.server = server;
this.file = file;
this.description = description;
this.dataFolder = dataFolder;
this.classLoader = classLoader;
this.configFile = new File(dataFolder, "config.yml");
this.logger = new PluginLogger(this);
if (description.isDatabaseEnabled()) {
ServerConfig db = new ServerConfig();
db.setDefaultServer(false);
db.setRegister(false);
db.setClasses(getDatabaseClasses());
db.setName(description.getName());
server.configureDbConfig(db);
DataSourceConfig ds = db.getDataSourceConfig();
ds.setUrl(replaceDatabaseString(ds.getUrl()));
dataFolder.mkdirs();
ClassLoader previous = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
ebean = EbeanServerFactory.create(db);
Thread.currentThread().setContextClassLoader(previous);
}
}
示例10: dataSourceProvided
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
@Override
protected void dataSourceProvided(DataSource dataSource, DataSourceConfig dsConfig) {
ebeanConfig = new EbeanConfigAdaptor().adaptFrom(this.config, dsConfig, this);
ebeanConfig.setDataSource(dataSource);
app().eventBus().trigger(new EbeanConfigLoaded(ebeanConfig));
ebean = EbeanServerFactory.create(ebeanConfig);
}
示例11: createDataSource
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
@Override
protected DataSource createDataSource() {
ebeanConfig = new EbeanConfigAdaptor().adaptFrom(this.config, this.config.dataSourceConfig, this);
app().eventBus().trigger(new EbeanConfigLoaded(ebeanConfig));
ebean = EbeanServerFactory.create(ebeanConfig);
return ebeanConfig.getDataSource();
}
示例12: setup
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
public static DataAccessConfigService setup(String readDataSourceName,
String readWriteDataSourceName) throws Exception {
DataAccessConfigService instance = new DataAccessConfigService(
EbeanServerFactory.create(readDataSourceName),
EbeanServerFactory.create(readWriteDataSourceName));
return instance;
}
示例13: initialize
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
/**
* Initializes this plugin with the given variables.
* <p>
* This method should never be called manually.
*
* @param loader PluginLoader that is responsible for this plugin
* @param server Server instance that is running this plugin
* @param description PluginDescriptionFile containing metadata on this plugin
* @param dataFolder Folder containing the plugin's data
* @param file File containing this plugin
* @param classLoader ClassLoader which holds this plugin
*/
protected final void initialize(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) {
if (!initialized) {
this.initialized = true;
this.loader = loader;
this.server = server;
this.file = file;
this.description = description;
this.dataFolder = dataFolder;
this.classLoader = classLoader;
this.configFile = new File(dataFolder, "config.yml");
this.logger = new PluginLogger(this);
if (description.isDatabaseEnabled()) {
ServerConfig db = new ServerConfig();
db.setDefaultServer(false);
db.setRegister(false);
db.setClasses(getDatabaseClasses());
db.setName(description.getName());
server.configureDbConfig(db);
DataSourceConfig ds = db.getDataSourceConfig();
ds.setUrl(replaceDatabaseString(ds.getUrl()));
dataFolder.mkdirs();
ClassLoader previous = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
ebean = EbeanServerFactory.create(db);
Thread.currentThread().setContextClassLoader(previous);
}
}
}
示例14: findAsOf_given_intersectionWithNoHistory_then_joinNormalAndNoEffectiveDatePredicate
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
@Test
public void findAsOf_given_intersectionWithNoHistory_then_joinNormalAndNoEffectiveDatePredicate() {
ServerConfig serverConfig = new ServerConfig();
serverConfig.setName("pg");
serverConfig.setDefaultServer(true);
serverConfig.loadFromProperties();
serverConfig.addClass(CustomerExcludeM2M.class);
serverConfig.addClass(FeatureExcludeM2M.class);
serverConfig.addClass(ContactExcludeM2M.class);
serverConfig.addClass(Address.class);
serverConfig.addClass(Country.class);
EbeanServer localServer = EbeanServerFactory.create(serverConfig);
long epochMilli = OffsetDateTime.now().minusHours(3).toInstant().toEpochMilli();
Timestamp asOf = new Timestamp(epochMilli);
LoggedSql.start();
localServer.find(CustomerExcludeM2M.class)
.asOf(asOf)
.fetch("features")
.where().eq("name", "jack")
.findUnique();
List<String> loggedSql = LoggedSql.stop();
assertThat(loggedSql).hasSize(1);
String sqlSelect = loggedSql.get(0);
assertThat(sqlSelect.contains(" --bind(jack asOf ")).isTrue();
assertThat(sqlSelect.contains(" from customer_with_history t0 ")).isTrue();
assertThat(sqlSelect.contains(" join customer_feature t1z_ ")).isTrue();
assertThat(sqlSelect.contains(" t0.sys_period @> ?::timestamptz")).isTrue();
assertThat(!sqlSelect.contains(" t1z_.sys_period @> ?::timestamptz")).isTrue();
}
示例15: initialize
import com.avaje.ebean.EbeanServerFactory; //导入依赖的package包/类
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
ServerConfig config = new ServerConfig();
config.setDefaultServer(true);
final DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig
.setUrl("jdbc:sqlite:C:/Users/markus/Entwickeln/Java/CraftBukkitTestServer/plugins/SmoothWorldUpdater/SmoothWorldUpdater.db");
dataSourceConfig.setDriver("org.sqlite.JDBC");
dataSourceConfig.setMinConnections(1);
dataSourceConfig.setMaxConnections(25);
dataSourceConfig.setUsername("");
dataSourceConfig.setPassword("");
dataSourceConfig.setIsolationLevel(TransactionIsolation
.getLevel("READ_UNCOMMITTED"));
config.setName("default");
config.setDataSourceConfig(dataSourceConfig);
config.addClass(de.hapm.swu.data.ChunkInfo.class);
config.addClass(de.hapm.swu.data.ChunkInfoId.class);
config.addClass(de.hapm.swu.data.BlockTypeInfo.class);
config.addClass(de.hapm.swu.data.WorldInfo.class);
server = EbeanServerFactory.create(config);
visualizer = new ChunkInfoVisualizer();
visualizer.setProvider(new EbeanChunkInfoProvider(server));
chunkInfoPanel.setVisualizer(visualizer);
chunkInfoPanel.start();
}
});
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
chunkInfoPanel = new ChunkInfoVisualizerPanel();
frame.getContentPane().add(chunkInfoPanel, BorderLayout.CENTER);
}