Skip to content

The traditional source of truth for applications is DBMS(SQL/NoSQL) and they rely on ORMs which natively support searching, sorting, filtering, pagination and more. As technologies evolved, applications moved beyond DBs and started to rely on APIs(typically REST endpoints) of other SaaS application. We all know the brighter side of SaaS offering…

License

Notifications You must be signed in to change notification settings

techconative/inmemory-posf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

In Memory POSF

Modern day applications can have various sources of data that can extend beyond traditional DBMS. Often, these datasources don't include any advanced features that a typical ORM provides, such as: (POSF)

  • Pagination
  • Ordering
  • Searching, and
  • Filtering

In Memory POSF helps integrate these features into your application when interacting with any such data sources.
It is source agnostic and can be applied on any situation when the above operations are required on structured(JSON) data is necessary.

Usage

1. Import the library into your project

The library is published on Central repository. Import it using your build system.

maven

<!-- pom.xml -->
<dependency>
  <groupId>com.techconative</groupId>
  <artifactId>inmemory-posf</artifactId>
  <version>1.0.0</version>
</dependency>

gradle

// build.gradle
dependencies {
  implementation 'com.techconative.inmemory-posf:1.0.0'
}

2. Define criteria

POSFCriteria class lets you set the criteria.

Sample criteria

POSFCriteria criteria = new POSFCriteria();

// 1.  Filtering and search
criteria.setFilter("multiMedia.[].name=CCCC&*=Vega|vegas&userId=4051");

/* 2. Order filtered data
 * Column name to order by
*/ 
criteria.setColumn("id");
// Ordering criteria. Accepts ASC / DESC.
criteria.setSort(OrderingCriteria.ASC);

/* 3. Paginate ordered data
 * Number of items that need to to displayed in a page. 
 * If it is 0 then it will return all records.
*/  
criteria.setLimit(10);

// 4. Offset page to be returned after paginating the data.
criteria.setPageNumber(1);

Below are the conventions for the various operations supported:

I. Filter and Search

Filtering is per column name while search is performed across columns.
Multiple values can be supplied at the same time.

Operators
Operator Usage
& separates multiple filters
= separates key values (key are column name to be filtered)
* Represents any column including nested keys as well
| separates multiple values in criteria
[] list of objects
. nested object

Setting filter/search criteria :

criteria.setFilter("multiMedia.[].name=CCCC&*=Vega\|vegas&userId=4051");

More criteria patterns:

name=sanjay\|neha  
createdAt="2020-01-02T10:54:07.609+00:00  
multiMedia.[].like=10  
*=Vega\|vegas  
counters.[].yearMonth.[].dateCounter.[].likes=10&*=Vega\|vegas  

II. Ordering

Ordering has two criteria:

  • column specifies the column used for ordering.
  • sort specifies the order to use.
criteria.setColumn("columnName");
criteria.setSort(OrderingCriteria.ASC);   // OrderingCriteria.DESC for descending

III. Pagination

Paginating has two criteria:

  • limit specifies the max number of results in a page
  • pageNumber selects the page number to return after pagination
criteria.setLimit(10);
criteria.setPageNumber(1);

3. POSF as a service

  • Extend the class POSFService from the package com.techconative.posf.service and override the getRawData() method.
  • getRawData() method must return a list of objects for which POSF operations are to be performed.

Supply your data through getRawData():

@Override
protected List<Feed> getRawData() {
try {
return mapper.readValue(
this.getClass()
.getClassLoader()
.getResourceAsStream("Feeds_with_500_Records.json"),
new TypeReference<List<Feed>>() {});
} catch (IOException e) {
throw new RuntimeException(e);
}
}

4. Apply criteria and fetch processed data

IPaginationService service = new FeedService();
PageResult pageResult = service.getPageResult(criteria);    // processing data with defined criteria
List<Feed> resultData = pageResult.getData();               // retrieve processed data

Alternate approach to using POSF library

If you have limitations in extending our service class don't worry, you can still use our library.

  • POSFUtil's static method processData() can be invoked with your list of objects and criteria.

Sample usage:

List rawData;
POSFCriteria criteria;
/*
 * Your Implemenation
 */
PageResult pageResult = POSFUtil.processData(rawData, criteria);    // processing data with defined criteria
List<Feed> resultData = pageResult.getData();                       // retrieve processed data

An open source initiative from http://techconative.com

About

The traditional source of truth for applications is DBMS(SQL/NoSQL) and they rely on ORMs which natively support searching, sorting, filtering, pagination and more. As technologies evolved, applications moved beyond DBs and started to rely on APIs(typically REST endpoints) of other SaaS application. We all know the brighter side of SaaS offering…

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •