如果理解正确,ActiveJdbc编译器应该像下面这样作为输入空心类
public class Employee extends Model {}然后用数据库元数据中的代码填充它。
但是它怎么知道数据库的位置呢?
我在这里只找到了一个提及数据库的地方,即刚开始。
Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/test", "user1", "xxxxx");那么,插装编译器是否扫描对Base.open()调用的代码并将其解析为URL?
真让人难以相信。如果对不同的数据库有多个调用呢?
如果没有Base.open()调用怎么办?
发布于 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)
- 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.
所有数据库元数据都是在运行时解析的,而不是在编译或检测阶段。
https://stackoverflow.com/questions/25724998
复制相似问题