Ejemplo n.º 1
0
 private Field findSqlMapExecutorDelegate(SqlMapClient sqlMapClient) {
   Class<?> searchType = sqlMapClient.getClass();
   while (!Object.class.equals(searchType) && searchType != null) {
     Field[] fields = searchType.getDeclaredFields();
     for (Field field : fields) {
       if (SqlMapExecutorDelegate.class.isAssignableFrom(field.getType())) return field;
     }
     searchType = searchType.getSuperclass();
   }
   return null;
 }
Ejemplo n.º 2
0
  public SqlMapRepositoryFactory(SqlMapClient sqlMapClient) {
    Assert.notNull(sqlMapClient, "SqlMapClient must not be null!");

    this.sqlMapClient = (SqlMapClientImpl) sqlMapClient;
    this.sqlMapClientTemplate = new SqlMapClientTemplate(sqlMapClient);

    if (ExtendedSqlMapClient.class.isAssignableFrom(sqlMapClient.getClass())) {
      this.sqlMapExecutorDelegate = ((ExtendedSqlMapClient) sqlMapClient).getDelegate();
    } else if (hasSqlMapExecutorDelegate(sqlMapClient)) {
      Field field = findSqlMapExecutorDelegate(sqlMapClient);
      field.setAccessible(true);

      this.sqlMapExecutorDelegate =
          (SqlMapExecutorDelegate) ReflectionUtils.getField(field, sqlMapClient);
    } else {
      throw new IllegalArgumentException("not found SqlMapExecutorDelegate in SqlMapClient.");
    }
  }