Search code examples
gemfiregeodespring-data-gemfirespring-boot-data-geode

How can i get complete data from apache geode if geode is having partial data and other data is present in external datasource


I have an apache geode setup. I have connected geode with external datasource which is postgres. There is a scenario where i have few data present in apache geode and rest all is in postgres. I am using query service to fetch data and when i fire query then i want that apache geode should provide me data present in its server and from postgres as well(for data not present in apache geode ). How can i proceed with that?

I have my cache loaded which loads data if it is not present in Apache Geode.

''' @Service public class QuoteLoader implements CacheLoader<String, Employee> {

private static Logger logger = LoggerFactory.getLogger(QuoteLoader.class);

@Autowired
EmployeeImpl employeeImpl;

@Autowired
EmployeeRepository employeeRepository;

public QuoteLoader() {
}

@Override
public void init(Properties props) {
}

@Override
public void close() {
}

@Override
public Employee load(LoaderHelper<String, Employee> helper) throws CacheLoaderException {
    
    Employee value = null;
    try {
        value = employeeImpl.getEmployeeById(Long.valueOf(helper.getKey()));
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("Error Occured", e);
    }
    return value;
}

} '''


Solution

  • The query engine simply executes the OQL and returns the result, no CacheLoader is invoked whatsoever during the query execution. The CacheLoader is only invoked if there's a cache miss while executing a Region.get(key) operation.

    This, if you think about it, makes total sense... a query is an arbitrary string that can return any results (including none), so the query engine can't know whether an entry is expected to be part of the result or not if the actual entry is not already present in the Geode region.