com.avaje.ebean.Ebean类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(196)

本文整理了Java中com.avaje.ebean.Ebean类的一些代码示例,展示了Ebean类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ebean类的具体详情如下:
包路径:com.avaje.ebean.Ebean
类名称:Ebean

Ebean介绍

[英]This Ebean object is effectively a singleton that holds a map of registered EbeanServers. It additionally provides a convenient way to use the 'default' EbeanServer.

If you are using a Dependency Injection framework such as Spring or Guice you will probably NOT use this Ebean singleton object. Instead you will configure and construct EbeanServer instances using ServerConfig and EbeanServerFactory and inject those EbeanServer instances into your data access objects.

In documentation "Ebean singleton" refers to this object.

  • There is one EbeanServer per Database (javax.sql.DataSource).
  • EbeanServers can be 'registered' with the Ebean singleton (put into its map). Registered EbeanServer's can later be retrieved via #getServer(String).
  • One EbeanServer can be referred to as the 'default' EbeanServer. For convenience, the Ebean singleton (this object) provides methods such as #find(Class) that proxy through to the 'default' EbeanServer. This can be useful for applications that use a single database.

For developer convenience Ebean has static methods that proxy through to the methods on the 'default' EbeanServer. These methods are provided for developers who are mostly using a single database. Many developers will be able to use the methods on Ebean rather than get a EbeanServer.

EbeanServers can be created and used without ever needing or using the Ebean singleton. Refer to ServerConfig#setRegister(boolean).

You can either programmatically create/register EbeanServers via EbeanServerFactory or they can automatically be created and registered when you first use the Ebean singleton. When EbeanServers are created automatically they are configured using information in the ebean.properties file.

// fetch shipped orders (and also their customer)}
// fetch order 10, modify and save

When you have multiple databases and need access to a specific one the #getServer(String) method provides access to the EbeanServer for that specific database.

// Get access to the Human Resources EbeanServer/Database

[中]这个Ebean对象实际上是一个保存已注册ebeanserver映射的单例对象。此外,它还提供了一种使用“默认”EbeanServer的方便方法。
如果您使用的是依赖项注入框架,比如Spring或Guice,那么您可能不会使用这个Ebean单例对象。相反,您将使用ServerConfig和EbeanServerFactory配置和构造EbeanServer实例,并将这些EbeanServer实例注入到数据访问对象中。
在文档中,“ebeansingleton”指的是这个对象。
*每个数据库有一个EbeanServer(javax.sql.DataSource)。
*ebeanserver可以通过ebeansingleton“注册”(放入其映射中)。注册的EbeanServer稍后可以通过#getServer(字符串)检索。
一个EbeanServer可以称为“默认”EbeanServer。为了方便起见,Ebean单例(this object)提供了#find(Class)等方法,可以代理到“default”EbeanServer。这对于使用单个数据库的应用程序非常有用。
为了方便开发人员,Ebean具有静态方法,这些方法可以代理到
default'*EbeanServer上的方法。这些方法是为主要使用单个数据库的开发人员提供的。许多开发人员将能够在Ebean上使用这些方法,而不是使用EbeanServer。
可以创建和使用ebeanserver,而无需使用Ebean单例。请参阅服务器配置#设置寄存器(布尔值)。
您可以通过EbeanServerFactory以编程方式创建/注册ebeanserver,也可以在首次使用Ebean单例时自动创建和注册它们。自动创建EBeanServer时,将使用ebean中的信息对其进行配置。属性文件。

// fetch shipped orders (and also their customer)}
// fetch order 10, modify and save

当您有多个数据库并且需要访问特定数据库时,#getServer(String)方法提供对该特定数据库的EbeanServer的访问。

// Get access to the Human Resources EbeanServer/Database

代码示例

代码示例来源:origin: com.typesafe.play/play-java-ebean

/**
 * Deletes this entity.
 */
public void delete() {
  Ebean.delete(this);
}

代码示例来源:origin: org.avaje.ebean/ebean

/**
 * Return a named EbeanServer that is typically different to the default server.
 * <p>
 * If you are using multiple databases then each database has a name and maps to a single
 * EbeanServer. You can use this method to get an EbeanServer for another database.
 *
 * @param server The name of the EbeanServer. If this is null then the default EbeanServer is returned.
 */
public static EbeanServer db(String server) {
 return Ebean.getServer(server);
}

代码示例来源:origin: com.typesafe.play/play-java-ebean

public F.Promise<Result> call(final Context ctx) throws Throwable {
  return Ebean.execute(new TxCallable<F.Promise<Result>>() {
    public F.Promise<Result> call() {
      try {
        return delegate.call(ctx);
      } catch(RuntimeException e) {
        throw e;
      } catch(Throwable t) {
        throw new RuntimeException(t);
      }
    }
  });
}

代码示例来源:origin: MrNeuronix/IRISv2

@Override
public synchronized void save()
{
  if (this.getId() == null)
  {
    Ebean.save(this);
  }
  else
  {
    Ebean.update(this);
  }
}

代码示例来源:origin: MrNeuronix/IRISv2

/**
 * Loads properties from database.
 *
 * @return true if load successfully.
 */
private boolean loadPropertiesFromDatabase() {
  List<ru.iris.common.database.model.Config> dbcfg = Ebean.find(ru.iris.common.database.model.Config.class).findList();
  for (ru.iris.common.database.model.Config line : dbcfg) {
    propertyMap.put(line.getParam(), line.getValue());
  }
  return true;
}

代码示例来源:origin: org.avaje.ebean/ebean

/**
 * Less Than or Equal to - property less than or equal to the given value.
 */
public static Expression le(String propertyName, Object value) {
 return Ebean.getExpressionFactory().le(propertyName, value);
}

代码示例来源:origin: MrNeuronix/IRISv2

public static void release(String title)
{
  Ebean.delete(Ebean.find(ScriptLock.class).where().eq("title", title).findUnique());
}

代码示例来源:origin: com.typesafe.play/play-java-ebean

/**
 * Saves (inserts) this entity.
 */
public void save() {
  Ebean.save(this);
}

代码示例来源:origin: org.avaje.ebeanorm/avaje-ebeanorm-api

/**
 * Create using the ServerConfig object to configure the server.
 */
public static EbeanServer create(ServerConfig config) {
 if (config.getName() == null) {
  throw new PersistenceException("The name is null (it is required)");
 }
 EbeanServer server = serverFactory.createServer(config);
 if (config.isDefaultServer()) {
  GlobalProperties.setSkipPrimaryServer(true);
 }
 if (config.isRegister()) {
  Ebean.register(server, config.isDefaultServer());
 }
 return server;
}

代码示例来源:origin: com.typesafe.play/play-java-ebean

/**
 * Updates this entity.
 */
public void update() {
  Ebean.update(this);
}

代码示例来源:origin: MrNeuronix/IRISv2

private void update(String state) {
  ModuleStatus status = Ebean.find(ModuleStatus.class).where().eq("internalName", internalName).findUnique();
  if (status != null) {
    status.setLastseen(new Timestamp(new Date().getTime()));
    status.setStatus(state);
    status.save();
  } else {
    LOGGER.error("Error update module status! Module not found in DB!");
  }
}

代码示例来源:origin: org.avaje.ebean/ebean

/**
 * Create the query by Example expression specifying more options.
 */
public static ExampleExpression exampleLike(Object example, boolean caseInsensitive, LikeType likeType) {
 return Ebean.getExpressionFactory().exampleLike(example, caseInsensitive, likeType);
}

代码示例来源:origin: org.avaje.ebeanorm/avaje-ebeanorm-api

/**
 * Save all the beans from a Collection.
 */
public static int save(Collection<?> c) throws OptimisticLockException {
 return save(c.iterator());
}

代码示例来源:origin: org.avaje.ebean/ebean

/**
 * Create using the ServerConfig object to configure the server.
 */
public static synchronized EbeanServer create(ServerConfig config) {
 if (config.getName() == null) {
  throw new PersistenceException("The name is null (it is required)");
 }
 EbeanServer server = createInternal(config);
 if (config.isDefaultServer()) {
  PrimaryServer.setSkip(true);
 }
 if (config.isRegister()) {
  Ebean.register(server, config.isDefaultServer());
 }
 return server;
}

代码示例来源:origin: com.typesafe.play/play-java-ebean

/**
 * Updates this entity, by specifying the entity ID.
 */
public void update(Object id) {
  _setId(id);
  Ebean.update(this);
}

代码示例来源:origin: MrNeuronix/IRISv2

public boolean checkExist() {
  ModuleStatus status = Ebean.find(ModuleStatus.class).where().eq("internalName", internalName).findUnique();
  return status != null;
}

代码示例来源:origin: org.avaje.ebean/ebean

/**
 * Return typically a different EbeanServer to the default.
 * <p>
 * This is equivalent to {@link Ebean#getServer(String)}
 *
 * @param server The name of the EbeanServer. If this is null then the default EbeanServer is
 *               returned.
 */
public EbeanServer db(String server) {
 return Ebean.getServer(server);
}

代码示例来源:origin: org.avaje.ebean/ebean

/**
 * Case insensitive Contains - property like %value%. Typically uses a lower()
 * function to make the expression case insensitive.
 */
public static Expression icontains(String propertyName, String value) {
 return Ebean.getExpressionFactory().icontains(propertyName, value);
}

代码示例来源:origin: org.avaje.ebeanorm/avaje-ebeanorm-api

/**
 * Delete all the beans from a Collection.
 */
public static int delete(Collection<?> c) throws OptimisticLockException {
 return delete(c.iterator());
}

代码示例来源:origin: org.avaje.ebean/ebean

public int execute() {
 if (server != null) {
  return server.execute(this);
 } else {
  // Hopefully this doesn't catch anyone out...
  return Ebean.execute(this);
 }
}

相关文章