Suzan Cioc
Suzan Cioc

Reputation: 30107

Where does ActiveJdbc instrumentation compiler take information about database?

If understood correctly, ActiveJdbc compiler should take as input hollow class like this

public class Employee extends Model {}

and fill it with some code from database metadata.

But how can it know where database is located?

I found only one place here http://javalite.io/getting_started where database is mentionned, namely

Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/test", "user1", "xxxxx");

So, does instrumentation compiler scans code for calls to Base.open() and parses it for URL?

I can't believe it. What if there are multiple calls to different databases?

What if there is no Base.open() call?

Upvotes: 2

Views: 782

Answers (1)

ericbn
ericbn

Reputation: 10968

Looking at the activejdbc-instrumentation source, what is does basically is:

  • Find non-abstract subclasses of org.javalite.activejdbc.Model and for each class
    • Add methods that delegate to org.javalite.activejdbc.Model, which include:
      • 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)
      • and more ...
    • 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.

All database metadata is resolved in runtime, not during compilation or instrumentation phase.

Upvotes: 2

Related Questions