Esempio n. 1
0
 protected void saveCachedMap(Object key, CompositeMap map) {
   if (mCache != null && map != null) mCache.setValue(key, map);
   if (mSourceFileManager != null) {
     File source = map.getSourceFile();
     if (source != null) {
       ISourceFile sf = mSourceFileManager.addSourceFile(source);
       sf.addUpdateListener(new CachedSourceFileCleaner(mCache, key));
     }
   }
 }
Esempio n. 2
0
 public CompositeMap loadFromClassPath(String full_name, String file_ext)
     throws IOException, SAXException {
   if (!mCacheEnabled || mCache == null) return loadFromClassPath_NC(full_name, file_ext);
   String name = full_name + '#' + file_ext;
   CompositeMap m = (CompositeMap) mCache.getValue(name);
   if (m == null) {
     m = loadFromClassPath_NC(full_name, file_ext);
     saveCachedMap(name, m);
   }
   return (CompositeMap) m.clone();
 }
Esempio n. 3
0
 protected CompositeMap getCachedMap(Object key) {
   return mCache == null ? null : (CompositeMap) mCache.getValue(key);
 }
  public void query(CompositeMap context_map) throws Exception {
    super.doPopulate();
    ILogger logger =
        LoggingContext.getLogger(context_map, DatabaseConstant.AURORA_DATABASE_LOGGING_TOPIC);
    SqlServiceContext context =
        (SqlServiceContext) DynamicObject.cast(context_map, SqlServiceContext.class);

    String cache_key = null;
    boolean is_cache = false;
    ICache cache_for_data = null;
    if (cacheKey != null) {
      is_cache = true;
      cache_for_data = CacheUtil.getNamedCache(mObjectReg, KEY_DATA_CACHE_NAME);
      cache_key = TextParser.parse(cacheKey, context_map);
      CompositeMap data = (CompositeMap) cache_for_data.getValue(cache_key);
      if (data != null) {
        logger.config("Cached data found with key " + cache_key);
        // write cache to context
        CompositeMap root_node =
            getMapFromRootPath(
                context.getModel(), TextParser.parse(this.rootPath, context.getObjectContext()));
        root_node.copy(data);
        return;
      } else {
        logger.config(
            "Cached data not found with key " + cache_key + ", doing normal database query");
      }
    }

    prepare(context_map);

    // context.setTrace(trace);
    ServiceOption option = ServiceOption.createInstance();
    option.setQueryMode(mode);
    option.setAutoCount(autoCount);
    option.setConnectionName(connectionName);
    option.setFieldCase(fieldNameCaseValue);
    option.setRecordName(recordName);
    transferServiceOption(option, ServiceOption.KEY_DEFAULT_WHERE_CLAUSE);
    transferServiceOption(option, ServiceOption.KEY_QUERY_ORDER_BY);
    context.setServiceOption(option);

    IResultSetConsumer consumer = null;
    //        CompositeMapCreator compositeCreator = null;
    try {
      // get parameter
      CompositeMap param = context.getCurrentParameter();
      if (parameter != null) {
        Object obj = param.getObject(parameter);
        if (obj != null) {
          if (!(obj instanceof CompositeMap))
            throw new IllegalArgumentException(
                "query parameter should be instance of CompositeMap, but actually got "
                    + obj.getClass().getName());
          param = (CompositeMap) obj;
        }
      }

      // page settings
      FetchDescriptor desc = FetchDescriptor.createFromParameter(context.getParameter());
      desc.setFetchAll(fetchAll);
      if (pageSize != null) desc.setPageSize(pageSize.intValue());

      // ResultSet consumer
      if (this.rsConsummer != null) consumer = this.rsConsummer;
      else {
        consumer = (IResultSetConsumer) context.getInstanceOfType(IResultSetConsumer.class);
        if (consumer == null) {
          consumer = new CompositeMapCreator();
          mOCManager.populateObject(mEntryConfig, consumer);
        }
      }
      if (consumer instanceof IContextAcceptable)
        ((IContextAcceptable) consumer).setContext(context_map);
      // set root path
      if (consumer instanceof IRootMapAcceptable) {
        CompositeMap result =
            getMapFromRootPath(
                context.getModel(), TextParser.parse(this.rootPath, context.getObjectContext()));
        if (result != null) ((IRootMapAcceptable) consumer).setRoot(result);
      }
      context.setResultsetConsumer(consumer);
      doQuery(param, consumer, desc);

      // write data to cache
      if (is_cache) {
        CompositeMap d = (CompositeMap) consumer.getResult();
        CompositeMap copied_data = (CompositeMap) d.clone();
        copied_data.setParent(null);
        cache_for_data.setValue(cache_key, copied_data);
      }
      /*
      if( transform_list != null && consumer instanceof  IRootMapAcceptable){
          CompositeMap root = ((IRootMapAcceptable)consumer).getRoot();
          Transformer.doBatchTransform( root, transform_list );
      }
      */
    } finally {
      context.setServiceOption(null);
      context.setResultsetConsumer(null);
      cleanUp(context_map);
    }
  }