首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ActiveJdbc工具编译器在哪里获取有关数据库的信息?

问ActiveJdbc工具编译器在哪里获取有关数据库的信息?
EN

Stack Overflow用户
提问于 2014-09-08 13:05:50
回答 1查看 753关注 0票数 2

如果理解正确,ActiveJdbc编译器应该像下面这样作为输入空心类

代码语言:javascript
复制
public class Employee extends Model {}

然后用数据库元数据中的代码填充它。

但是它怎么知道数据库的位置呢?

我在这里只找到了一个提及数据库的地方,即刚开始。

代码语言:javascript
复制
Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/test", "user1", "xxxxx");

那么,插装编译器是否扫描对Base.open()调用的代码并将其解析为URL?

真让人难以相信。如果对不同的数据库有多个调用呢?

如果没有Base.open()调用怎么办?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-08 14:14:45

看看activejdbc-检测源,基本上是这样的:

  • 查找org.javalite.activejdbc.Model的非抽象子类,并为每个类查找
    • 向org.javalite.activejdbc.Model添加委托的方法,其中包括:
      • public static MetaModel getMetaModel()
      • public static List<String> attributes()
      • public static List<Association> associations()
      • public static int delete(String query, Object... params)
      • public static boolean exists(Object id)
      • public static int deleteAll()
      • public static int update(String updates, String conditions, Object ... params)
      • public static int updateAll(String updates, Object ... params)
      • 还有更多..。

​

代码语言:javascript
复制
- Add `public static String getClassName()` method that returns the fully-qualified name of the class.
- Add a line to the `activejdbc_models.properties` file containing `model.getName() + ":" + getDatabaseName(model) + "\n"`, where the first method returns the fully-qualified name of the class, and the second method returns the value of the `@DbName` annotation on the class or `"default"` if no annotation is found.

​

所有数据库元数据都是在运行时解析的,而不是在编译或检测阶段。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25724998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档