protected boolean matchContext(SqlReaderContext context, SqlCommand sql) { if(!Strings.isEmpty(sql.getDbType())) { final String currentDbType = context.getConfigContext().getDb().getType(); if(!currentDbType.equalsIgnoreCase(sql.getDbType())) { return false; } } if(!Strings.isEmpty(sql.getDataSourceName())) { final String currentDataSourceName = context.getConfigContext().getName(); if(!currentDataSourceName.equalsIgnoreCase(sql.getDataSourceName())) { return false; } } return true; }
@Override public boolean resolveInjectValue(BeanDefinition bd, Object bean, ReflectValued v, Annotation a, Out<Object> value) { if (!leap.orm.dao.DaoCommand.class.equals(v.getType())) { return false; } KeyAndDataSource kds; if (a.annotationType().equals(Inject.class)) { kds = resolveSqlIdentity(bd, v, (Inject) a); } else if (a.annotationType().equals(SqlKey.class)) { kds = resolveSqlIdentity(bd, v, (SqlKey) a); } else { return false; } SqlCommand sql = sqls.tryGetSqlCommand(kds.key); if (null == sql) { throw new BeanCreationException("Sql key '" + kds.key + "' not found, check the bean : " + bd); } Dao dao; if (!Strings.isEmpty(sql.getDataSourceName())) { dao = Dao.get(sql.getDataSourceName()); } else if (!Strings.isEmpty(kds.dataSource)) { dao = Dao.get(kds.dataSource); } else { dao = Dao.get(); } value.set(new SimpleDaoCommand(dao, sql)); return true; }