I am unable to get activejdbc working with aws serverless.
I added my connection params as ENV variables and Base.findAll() works, but I am unable to get the models to work, i get the following error
"org.javalite.activejdbc.InitException: you are trying to work with models, but no models are found. Maybe you have no models in project, or you did not instrument the models. It is expected that you have a file activejdbc_models.properties on classpath\n\tat org.javalite.activejdb
I checked my jar file, and it does have a 'activejdbc_models.properties' file, and the instrumentation seems to have worked.
Is this path a dead end? should I just shift to direct jdbc? or can I get actveJDBC to work with lambda.
Update Ran javap on one of my model classes Address, here is the output
Compiled from "Address.java"
public class com.kwiqhealth.models.Address extends org.javalite.activejdbc.Model {
public com.kwiqhealth.models.Address();
public static org.javalite.activejdbc.MetaModel getMetaModel();
public static org.javalite.activejdbc.MetaModel metaModel();
public static <T extends org.javalite.activejdbc.Model> T findOrCreateIt(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findOrInit(java.lang.Object...);
public static java.util.Set<java.lang.String> attributeNames();
public static java.util.List<org.javalite.activejdbc.associations.Association> associations();
public static int delete(java.lang.String, java.lang.Object...);
public static boolean exists(java.lang.Object);
public static int deleteAll();
public static int update(java.lang.String, java.lang.String, java.lang.Object...);
public static int updateAll(java.lang.String, java.lang.Object...);
protected static org.javalite.validation.NumericValidationBuilder validateNumericalityOf(java.lang.String...);
public static org.javalite.validation.ValidationBuilder addValidator(org.javalite.validation.Validator);
protected static void addScope(java.lang.String, java.lang.String);
public static void removeValidator(org.javalite.validation.Validator);
public static java.util.List<org.javalite.validation.Validator> getValidators(java.lang.Class<? extends org.javalite.activejdbc.Model>);
protected static org.javalite.validation.ValidationBuilder validateRegexpOf(java.lang.String, java.lang.String);
protected static org.javalite.validation.ValidationBuilder validateEmailOf(java.lang.String);
protected static org.javalite.validation.ValidationBuilder validateRange(java.lang.String, java.lang.Number, java.lang.Number);
protected static org.javalite.validation.ValidationBuilder validatePresenceOf(java.lang.String...);
protected static org.javalite.validation.ValidationBuilder validateWith(org.javalite.validation.Validator);
protected static void convertWith(org.javalite.conversion.Converter, java.lang.String...);
protected static void dateFormat(java.lang.String, java.lang.String...);
protected static void dateFormat(java.text.DateFormat, java.lang.String...);
protected static void timestampFormat(java.lang.String, java.lang.String...);
protected static void timestampFormat(java.text.DateFormat, java.lang.String...);
protected static void blankToNull(java.lang.String...);
protected static void zeroToNull(java.lang.String...);
public static boolean belongsTo(java.lang.Class<? extends org.javalite.activejdbc.Model>);
public static void callbackWith(org.javalite.activejdbc.CallbackListener...);
public static <T extends org.javalite.activejdbc.Model> T create(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T createIt(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findById(java.lang.Object);
public static <T extends org.javalite.activejdbc.Model> T findByCompositeKeys(java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> where(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.ScopeBuilder<T> scopes(java.lang.String...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.ScopeBuilder<T> scope(java.lang.String);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> find(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T findFirst(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> T first(java.lang.String, java.lang.Object...);
public static void findWith(org.javalite.activejdbc.ModelListener, java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> findBySQL(java.lang.String, java.lang.Object...);
public static <T extends org.javalite.activejdbc.Model> org.javalite.activejdbc.LazyList<T> findAll();
public static java.lang.Long count();
public static java.lang.Long count(java.lang.String, java.lang.Object...);
public static java.lang.String getTableName();
public static boolean isCached();
public static void purgeCache();
}
OK, considering you output from the javap
command, your classes are instrumented. However, there is still something broken with your build, as it seems you are publishing non-instrumented classes to the AWS Lambda, hence your exception. I created a very simple test to run ActiveJDBC in Lambda:
@Override
public String handleRequest(Map<String,String> event, Context context) {
context.getLogger().log("Starting to connect...");
Base.open("org.mariadb.jdbc.Driver", "jdbc:mysql://database-1.xxxxx.us-east-2.rds.amazonaws.com/test", "admin", "xcxxxx");
context.getLogger().log("connected!!");
// Base.exec("create database test");
// Base.exec("CREATE TABLE people (id int(11) NOT NULL auto_increment PRIMARY KEY, name VARCHAR(56) NOT NULL, last_name VARCHAR(56), dob DATE, graduation_date DATE, created_at DATETIME, updated_at DATETIME) ENGINE=InnoDB DEFAULT CHARSET=utf8");
context.getLogger().log("Found records in table: " + Base.count("people"));
context.getLogger().log("Found records in table (with model): " + Person.count());
Base.close();
context.getLogger().log("Executed and closed");
return "Lambda done executing..." ;
}
When I executed the Lambda, the CloudWatch provided the following logs:
The line that was logged after a model was executed. As you can see, there is no conflict between JavaLite ActiveJDBC and AWS Lambda. You need to look into an issue with your build.