コード例 #1
0
  /** Only used by cache implementations */
  protected void cacheInit() {
    if (simpleCache != null || cacheWithWhereClause != null) return;
    String where = context.getEntityAttribute("where");

    String cacheKey = context.getEntityAttribute(CACHE_KEY);
    String lookupKey = context.getEntityAttribute(CACHE_LOOKUP);
    if (cacheKey != null && lookupKey == null) {
      throw new DataImportHandlerException(
          DataImportHandlerException.SEVERE,
          "'cacheKey' is specified for the entity " + entityName + " but 'cacheLookup' is missing");
    }
    if (where == null && cacheKey == null) {
      simpleCache = new HashMap<String, List<Map<String, Object>>>();
    } else {
      if (where != null) {
        String[] splits = where.split("=");
        cachePk = splits[0];
        cacheVariableName = splits[1].trim();
      } else {
        cachePk = cacheKey;
        cacheVariableName = lookupKey;
      }
      cacheWithWhereClause = new HashMap<String, Map<Object, List<Map<String, Object>>>>();
    }
  }
コード例 #2
0
 /**
  * If the where clause is present the cache is sql Vs Map of key Vs List of Rows. Only used by
  * cache implementations.
  *
  * @param query the query string for which cached data is to be returned
  * @return the cached row corresponding to the given query after all variables have been resolved
  */
 protected Map<String, Object> getIdCacheData(String query) {
   Map<Object, List<Map<String, Object>>> rowIdVsRows = cacheWithWhereClause.get(query);
   List<Map<String, Object>> rows = null;
   Object key = context.resolve(cacheVariableName);
   if (key == null) {
     throw new DataImportHandlerException(
         DataImportHandlerException.WARN,
         "The cache lookup value : "
             + cacheVariableName
             + " is resolved to be null in the entity :"
             + context.getEntityAttribute("name"));
   }
   if (rowIdVsRows != null) {
     rows = rowIdVsRows.get(key);
     if (rows == null) return null;
     dataSourceRowCache = new ArrayList<Map<String, Object>>(rows);
     return getFromRowCacheTransformed();
   } else {
     rows = getAllNonCachedRows();
     if (rows.isEmpty()) {
       return null;
     } else {
       rowIdVsRows = new HashMap<Object, List<Map<String, Object>>>();
       for (Map<String, Object> row : rows) {
         Object k = row.get(cachePk);
         if (k == null) {
           throw new DataImportHandlerException(
               DataImportHandlerException.WARN,
               "No value available for the cache key : "
                   + cachePk
                   + " in the entity : "
                   + context.getEntityAttribute("name"));
         }
         if (!k.getClass().equals(key.getClass())) {
           throw new DataImportHandlerException(
               DataImportHandlerException.WARN,
               "The key in the cache type : "
                   + k.getClass().getName()
                   + "is not same as the lookup value type "
                   + key.getClass().getName()
                   + " in the entity "
                   + context.getEntityAttribute("name"));
         }
         if (rowIdVsRows.get(k) == null) rowIdVsRows.put(k, new ArrayList<Map<String, Object>>());
         rowIdVsRows.get(k).add(row);
       }
       cacheWithWhereClause.put(query, rowIdVsRows);
       if (!rowIdVsRows.containsKey(key)) return null;
       dataSourceRowCache = new ArrayList<Map<String, Object>>(rowIdVsRows.get(key));
       if (dataSourceRowCache.isEmpty()) {
         dataSourceRowCache = null;
         return null;
       }
       return getFromRowCacheTransformed();
     }
   }
 }
コード例 #3
0
 /** first time init call. do one-time operations here */
 protected void firstInit(Context context) {
   entityName = context.getEntityAttribute("name");
   String s = context.getEntityAttribute(ON_ERROR);
   if (s != null) onError = s;
   isFirstInit = false;
 }