Search in sources :

Example 1 with DbService

use of act.db.DbService in project act-ebean by actframework.

the class EbeanDao method getService.

private EbeanService getService(String dbId, DbServiceManager mgr) {
    DbService svc = mgr.dbService(dbId);
    E.invalidConfigurationIf(null == svc, "Cannot find db service by id: %s", dbId);
    E.invalidConfigurationIf(!(svc instanceof EbeanService), "The db service[%s|%s] is not ebean service", dbId, svc.getClass());
    return $.cast(svc);
}
Also used : DbService(act.db.DbService)

Example 2 with DbService

use of act.db.DbService in project act-ebean by actframework.

the class EbeanDaoInjectionListener method onInjection.

@Override
public void onInjection(Object injectee, BeanSpec spec) {
    final EbeanDao dao = $.cast(injectee);
    if (dao.ebeanServerProvided()) {
        return;
    }
    List<Type> typeParameters = spec.typeParams();
    if (typeParameters.isEmpty()) {
        typeParameters = Generics.typeParamImplementations(spec.rawType(), EbeanDao.class);
    }
    if (null == typeParameters) {
        logger.warn("No type parameter information provided");
        return;
    }
    final $.T2<Class, String> resolved = resolve(typeParameters);
    DbService dbService = App.instance().dbServiceManager().dbService(resolved._2);
    if (dbService instanceof EbeanService) {
        final EbeanService service = $.cast(dbService);
        Act.eventBus().bind(SysEventId.DB_SVC_LOADED, new SysEventListenerBase() {

            @Override
            public void on(EventObject eventObject) throws Exception {
                dao.ebean(service.ebean());
                dao.modelType(resolved._1);
            }
        });
    }
}
Also used : org.osgl.$(org.osgl.$) DbService(act.db.DbService) SysEventListenerBase(act.event.SysEventListenerBase) EventObject(java.util.EventObject) Type(java.lang.reflect.Type)

Aggregations

DbService (act.db.DbService)2 SysEventListenerBase (act.event.SysEventListenerBase)1 Type (java.lang.reflect.Type)1 EventObject (java.util.EventObject)1 org.osgl.$ (org.osgl.$)1