### Cheerio Installation
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/cheerio/Readme.md
Install Cheerio using npm.
```bash
npm install cheerio
```
--------------------------------
### Instantiate JPAStreamer and Query Data
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/fetching-data.adoc
Example demonstrating the instantiation of JPAStreamer using a builder pattern and performing a query to count films starting with 'A'.
```java
public static void main(String[] args) {
JPAStreamer jpaStreamer = JPAStreamer.createJPAStreamerBuilder("sakila")
.build();
long count = jpaStreamer.stream(Film.class)
.filter(Film$.title.startsWith("A"))
.count();
System.out.format("There are %d films with a title that starts with A", count);
}
```
--------------------------------
### Install entities Package
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/entities/readme.md
Install the 'entities' package using npm.
```bash
npm install entities
```
--------------------------------
### Example Persistence Unit Configuration
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/fetching-data.adoc
An example XML configuration for a persistence unit named 'sakila'. This file is typically found in your project and describes database connection details.
```xml
MySQL Sakila Example Databaseorg.hibernate.jpa.HibernatePersistenceProvider
```
--------------------------------
### Install html-entities via npm
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/html-entities/README.md
Install the html-entities library using npm. This is the first step to using the library in your Node.js project.
```bash
$ npm install html-entities
```
--------------------------------
### Install antora-lunr Module
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/antora-lunr/README.md
Install the antora-lunr npm package locally or globally.
```bash
npm i antora-lunr
npm i -g antora-lunr
```
--------------------------------
### forEach() Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/terminal_operations.adoc
Performs an action for each element in the stream. The order of execution is not guaranteed.
```java
Stream.of("B", "A", "C" , "B")
.forEach(System.out::print);
```
--------------------------------
### count() Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/terminal_operations.adoc
Counts the number of elements in a stream.
```java
Stream.of("B", "A", "C" , "B")
.count();
```
```java
Stream.empty()
.count();
```
--------------------------------
### asLongStream() Example for IntStream
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/intermediate_operations.adoc
Converts an IntStream to a LongStream.
```java
IntStream.of(1, 2, 3, 4)
.asLongStream()
```
--------------------------------
### mapMulti Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/intermediate_operations.adoc
Demonstrates how mapMulti can duplicate elements based on a condition. Requires Java 16 or later.
```java
Stream.of(1.0, 2.0, 3.0, 4.0, 5.0)
.mapMulti((i, mapper) -> {
if (i % 2 == 0) {
mapper.accept(i);
mapper.accept(i);
}
});
```
--------------------------------
### Install Default Antora Site Generator
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/antora-lunr/README.md
Check if the default Antora site generator is installed locally or globally.
```bash
npm list --depth 0
npm list -g --depth 0
```
--------------------------------
### Filter Strings Starting with 'A' using Java Predicate
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/predicates.adoc
Demonstrates filtering a stream of strings using a standard Java Predicate to select elements that begin with the letter 'A'. This example shows basic Predicate usage.
```java
Predicate startsWithA = (String s) -> s.startsWith("A");
Stream.of("Snail", "Ape", "Bird", "Ant", "Alligator")
.filter(startsWithA)
.forEachOrdered(System.out::println);
```
--------------------------------
### Start Lunr.js Test Server
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/lunr/CONTRIBUTING.md
Launch a local development server to run tests in a web browser. The server will be accessible on port 3000, with tests available at the /test path.
```bash
make server
```
--------------------------------
### collect() to List Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/terminal_operations.adoc
Collects stream elements into a List.
```java
Stream.of("B", "A", "C" , "B")
.collect(Collectors.toList());
```
--------------------------------
### Using Metamodel Fields for Filtering
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/how-it-works/pages/how-it-works.adoc
Demonstrates how to use generated metamodel fields like 'Film$.title' to create predicates for filtering streams. This example counts films starting with 'A'.
```java
long nrOfFilmsStartingWithA = jpaStreamer.stream(Film.class)
.filter(Film$.title.startsWith("A")) // As title is of type StringField we get access to operators such as startsWith that returns a Predicate that evaluates to true or false.
.count();
```
--------------------------------
### asDoubleStream() Example for IntStream
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/intermediate_operations.adoc
Converts an IntStream to a DoubleStream.
```java
IntStream.of(1, 2, 3, 4)
.asDoubleStream()
```
--------------------------------
### boxed() Example for IntStream
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/intermediate_operations.adoc
Converts an IntStream to a Stream of Integer objects.
```java
IntStream.of(1, 2, 3, 4)
.boxed()
```
--------------------------------
### Define StreamConfiguration with Query Hints
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/fetching-data.adoc
Create a StreamConfiguration to pass query hints to the underlying JPA provider. This example sets a read-only hint and a query timeout.
```java
StreamConfiguration sc = StreamConfiguration.of(Film.class)
.withHint("javax.persistence.query.timeout", 50)
.withHint("org.hibernate.readOnly", true);
List films = jpaStreamer.stream(sc)
.filter(Film$.title.startsWith("A"))
.sorted(Film$.length)
.limit(10)
.collect(Collectors::toList);
```
--------------------------------
### Example Film Entity
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/reference-predicates.adoc
An example JPA entity 'Film' with a 'rating' field, used for demonstrating reference predicates.
```java
@Entity
@Table(name = "film", schema = "sakila")
public class Film {
// ...
@Column(name = "rating", nullable = true, columnDefinition = "enum('G','PG','PG-13','R','NC-17')")
private String rating;
// ...
}
```
--------------------------------
### collect() to Set Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/terminal_operations.adoc
Collects stream elements into a Set, removing duplicates.
```java
Stream.of("B", "A", "C" , "B")
.collect(Collectors.toSet());
```
--------------------------------
### collect() to Map Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/terminal_operations.adoc
Collects stream elements into a Map, using a key and value extractor.
```java
Stream.of("I", "am", "a", "stream")
.collect(
Collectors.toMap(
s -> s.toLowerCase(), // Key extractor
s -> s.length()) // Value extractor
)
```
--------------------------------
### Example of Optimized Query Generation
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/how-it-works/pages/how-it-works.adoc
This example demonstrates how JPA Streamer translates Stream API operations like filtering and sorting into an optimized SQL query. It highlights the use of generated fields for efficient database interaction.
```sql
select
film0_.film_id as film_id1_0_,
film0_.title as title2_0_,
film0_.length as length3_0_
from
film film0_
where
film0_.length > 100
order by
film0_.length desc,
film0_.title asc limit ?, ?
```
--------------------------------
### mapMultiToLong Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/intermediate_operations.adoc
Demonstrates mapMultiToLong for creating a LongStream by duplicating elements. Requires Java 16 or later.
```java
Stream.of(1.0, 2.0, 3.0, 4.0, 5.0)
.mapMulti((i, mapper) -> {
if (i % 2 == 0) {
mapper.accept(i.longValue());
mapper.accept(i.longValue());
}
});
```
--------------------------------
### JPA Entity Bean Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/how-it-works/pages/how-it-works.adoc
An example of a JPA entity bean class named 'Film'. This class defines the structure and columns of a database table.
```java
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Column;
@Entity
@Table(name = "film", schema = "sakila")
public class Film {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "film_id", nullable = false, updatable = false, columnDefinition = "smallint(5)")
private Integer filmId;
@Column(name = "title", nullable = false, columnDefinition = "varchar(255)")
private String title;
// ...
}
```
--------------------------------
### Empty attributes with emptyAttrs: true
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/dom-serializer/README.md
Example showing how an empty attribute is rendered when the `emptyAttrs` option is set to true.
```html
```
--------------------------------
### DOM Structure Output
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/domhandler/readme.md
Example output of the DOM structure generated by DomHandler after parsing HTML.
```javascript
[
{
data: "Xyz ",
type: "text",
},
{
type: "script",
name: "script",
attribs: {
language: "javascript",
},
children: [
{
data: "var foo = '';<",
type: "text",
},
],
},
{
data: "
```
--------------------------------
### Basic Cheerio Usage
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/cheerio/Readme.md
Demonstrates loading HTML, selecting elements, modifying text and classes, and rendering the HTML.
```javascript
const cheerio = require('cheerio');
const $ = cheerio.load('
```
--------------------------------
### Add Documents to Lunr Index
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/lunr/index.html
Add individual documents to the Lunr index. Each document requires a unique reference and fields defined during index setup.
```javascript
index.add({
id: 1,
title: 'Foo',
body: 'Foo foo foo!'
})
```
```javascript
index.add({
id: 2,
title: 'Bar',
body: 'Bar bar bar!'
})
```
--------------------------------
### Instantiate DomHandler
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/domhandler/readme.md
Shows how to instantiate the DomHandler with an optional callback and options.
```javascript
const handler = new DomHandler([ callback(err, dom), ] [ options ]);
// const parser = new Parser(handler[, options]);
```
--------------------------------
### Filter Films by Title Starting With (Ignore Case)
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/string-predicates.adoc
Use `startsWithIgnoreCase` to filter entities where a string property begins with a specified prefix, ignoring case differences. This is useful for flexible searching.
```java
jpaStreamer.stream(Film.class)
.filter(Film$.title.startsWithIgnoreCase("ala"))
.forEachOrdered(System.out::println);
```
--------------------------------
### Filter Films by Title Starting with 'A' using Standard Lambda (Not Recommended)
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/predicates.adoc
Illustrates filtering films using a standard Java lambda expression. This approach is not optimized by JPAstreamer and forces the entire table to be loaded into the JVM.
```java
films.stream()
.filter(f -> f.getTitle().startsWith("A"))
.forEachOrdered(System.out::println);
```
--------------------------------
### Importing Available Entity Classes
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/html-entities/README.md
Demonstrates how to import the different entity classes provided by the library, including XmlEntities, Html4Entities, Html5Entities, and AllHtmlEntities.
```javascript
const XmlEntities = require('html-entities').XmlEntities,
Html4Entities = require('html-entities').Html4Entities,
Html5Entities = require('html-entities').Html5Entities,
AllHtmlEntities = require('html-entities').AllHtmlEntities;
```
--------------------------------
### Example of negating a predicate twice
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/negating-predicates.adoc
Negating a predicate an even number of times returns the original predicate. For example, negating equal(1) twice is equivalent to equal(1).
```java
Film$.film_id.equal(1).negate().negate()
```
--------------------------------
### Filter Films by Length Between 60 and 120 (Start Inclusive, End Inclusive)
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/comparable-predicates.adoc
Prints all films with a length between 60 and 120, where both the start and end values are included in the range. This uses a specific Inclusion enum constant.
```java
jpaStreamer.stream(Film.class)
.filter(Film$.length.between(60, 120, Inclusion.START_INCLUSIVE_END_INCLUSIVE))
```
--------------------------------
### Rendering with options
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/dom-serializer/README.md
Demonstrates how to pass an options object to the render function to customize serialization behavior.
```javascript
render(node, {
xmlMode: true,
emptyAttrs: true,
selfClosingTags: true
});
```
--------------------------------
### Configure Antora UI for Supplemental Files
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/antora-lunr/README.md
Configure Antora to use supplemental UI files, including the Lunr search index.
```yaml
ui:
bundle:
url: https://gitlab.com/antora/antora-ui-default/-/jobs/artifacts/master/raw/build/ui-bundle.zip?job=bundle-stable
snapshot: true
supplemental_files: ./supplemental_ui
```
--------------------------------
### Run Sakila Docker Instance
Source: https://github.com/speedment/jpa-streamer/blob/master/integration-tests/README.adoc
Runs the Sakila database as a Docker container, exposing port 3306. Use the --platform flag for ARM64 architecture if needed.
```shell
docker run -d --publish 3306:3306 --name mysqld restsql/mysql-sakila
```
--------------------------------
### Cheerio Load Options for XML
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/cheerio/Readme.md
Configure parsing options for XML input by passing an options object to the .load() method.
```javascript
const $ = cheerio.load('
...
', {
xml: {
normalizeWhitespace: true,
},
});
```
--------------------------------
### Importing dom-serializer
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/dom-serializer/README.md
Demonstrates how to import the dom-serializer library using both ES Module and CommonJS syntax.
```javascript
import render from "dom-serializer";
```
```javascript
const render = require("dom-serializer").default;
```
--------------------------------
### Equivalent AND using stacked filters
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/combining-predicates.adoc
Demonstrates an alternative way to achieve the same result as `and()` by stacking two separate `filter` operations. This can be less efficient as it may result in two separate queries.
```java
jpaStreamer.stream(Film.class)
.filter(Film$.length.greaterThan(120))
.filter(Film$.rating.equal("PG-13"))
.forEachOrdered(System.out::println);
```
--------------------------------
### Generate Antora Site with Lunr Search Enabled
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/antora-lunr/README.md
Generate the Antora documentation site with search enabled, specifying Lunr as the engine.
```bash
DOCSEARCH_ENABLED=true DOCSEARCH_ENGINE=lunr antora site.yml
```
--------------------------------
### max() Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/terminal_operations.adoc
Finds the maximum element in a stream based on a Comparator. Returns an Optional.
```java
Stream.of("B", "A", "C" , "B")
.max(String::compareTo);
```
```java
Stream.empty()
.max(String::compareTo);
```
--------------------------------
### Basic HTML Parsing with Callbacks
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/htmlparser2/README.md
Demonstrates how to use the htmlparser2 Parser with event callbacks for handling tags, text, and closing tags. Useful for processing HTML incrementally.
```javascript
const htmlparser2 = require("htmlparser2");
const parser = new htmlparser2.Parser({
onopentag(name, attributes) {
/*
* This fires when a new tag is opened.
*
* If you don't need an aggregated `attributes` object,
* have a look at the `onopentagname` and `onattribute` events.
*/
if (name === "script" && attributes.type === "text/javascript") {
console.log("JS! Hooray!");
}
},
ontext(text) {
/*
* Fires whenever a section of text was processed.
*
* Note that this can fire at any point within text and you might
* have to stich together multiple pieces.
*/
console.log("-->", text);
},
onclosetag(tagname) {
/*
* Fires when a tag is closed.
*
* You can rely on this event only firing when you have received an
* equivalent opening tag before. Closing tags without corresponding
* opening tags will be ignored.
*/
if (tagname === "script") {
console.log("That's it?!");
}
},
});
parser.write(
"Xyz ";
const handler = new DomHandler((error, dom) => {
if (error) {
// Handle error
} else {
// Parsing completed, do something
console.log(dom);
}
});
const parser = new Parser(handler);
parser.write(rawHtml);
parser.end();
```
--------------------------------
### dropWhile() Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/intermediate_operations.adoc
Uses `dropWhile` to skip elements as long as the condition is true. Once the condition becomes false, all subsequent elements are included.
```java
Stream.of("B", "A", "C", "B")
.dropWhile(s -> "B".compareTo(s) >= 0)
```
--------------------------------
### Count Records with COUNT
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/sql-equivalents.adoc
Counts the number of records that satisfy a given filter. This example counts films longer than 120 minutes.
```java
long noLongFilms = jpaStreamer.stream(Film.class)
.filter(Film$.length.greaterThan(120))
.count();
```
--------------------------------
### Rendering the Root HTML
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/cheerio/Readme.md
Render the entire document's HTML by calling the `html` method on the root selection. This provides the complete HTML structure.
```javascript
const $ = cheerio.load('
Apple
Orange
Pear
');
$.root().html();
//=>
//
//
//
//
Apple
//
Orange
//
Pear
//
//
//
```
--------------------------------
### Get distinct elements from a Java Stream
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/intermediate_operations.adoc
Removes duplicate elements from a stream based on their equals() method. Use to ensure uniqueness of elements.
```java
Stream.of("B", "A", "C" , "B")
.distinct()
```
--------------------------------
### toList()
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/terminal_operations.adoc
Collects the stream elements into a `List`. Requires Java 16 or later.
```java
Stream.of("B", "A", "C", "B")
.toList();
```
--------------------------------
### Search the Index
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/lunr/README.md
Shows how to perform a search query against a Lunr.js index.
```javascript
idx.search("love")
```
--------------------------------
### Run Module Tests
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/antora-lunr/README.md
Execute the test suite for the antora-lunr module.
```bash
npm t
```
--------------------------------
### Skip Records with OFFSET
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/sql-equivalents.adoc
Skips a specified number of records before processing. This example skips the first 100 films and prints the rest in title order.
```java
films.stream()
.sorted(Film$.title)
.skip(100)
.forEachOrdered(System.out::println);
```
--------------------------------
### Generated JPA Query Example
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/how-it-works/pages/how-it-works.adoc
The SQL query generated by JPAstreamer from the preceding Java stream pipeline. It shows how stream operations are translated into SQL WHERE and other clauses.
```text
select
film0_.film_id as film_id1_0_,
film0_.description as descript2_0_,
film0_.last_update as last_upd3_0_,
film0_.length as length4_0_,
film0_.rating as rating5_0_,
film0_.rental_duration as rental_d6_0_,
film0_.rental_rate as rental_r7_0_,
film0_.replacement_cost as replacem8_0_,
film0_.special_features as special_9_0_,
film0_.title as title10_0_
from
film film0_
where
film0_.rating=?
```
--------------------------------
### JPAstreamer Metamodel Generation
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/how-it-works/pages/how-it-works.adoc
An example of a generated metamodel class 'Film$' corresponding to the 'Film' entity. It represents entity columns as 'Field' objects for predicate composition.
```java
public class Film$ {
public static final ComparableField filmId = ComparableField.create(
Film.class, // Declares which table the Field belongs to
"filmId", // The name of the field
Film::getFilmId, // A reference to the associated getter
false // A boolean that describes if the Field is nullable
);
public static final StringField title = StringField.create(
Film.class,
"title",
Film::getTitle,
false
);
// ...
}
```
--------------------------------
### Create Stream from Entity Class
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/fetching-data.adoc
The simplest way to create a Stream is by providing the entity class. This is equivalent to using StreamConfiguration.of(YourEntity.class).
```java
Stream stream = jpaStreamer.stream(Film.class);
```
--------------------------------
### Generated SQL Query
Source: https://github.com/speedment/jpa-streamer/blob/master/README.adoc
Example of the SQL query generated by JPAstreamer for the preceding Stream operations. This shows how Stream API calls are translated into efficient SQL.
```roomsql
select
film0_.film_id as film_id1_1_,
film0_.description as descript2_1_,
film0_.language_id as languag11_1_,
film0_.last_update as last_upd3_1_,
film0_.length as length4_1_,
film0_.rating as rating5_1_,
film0_.rental_duration as rental_d6_1_,
film0_.rental_rate as rental_r7_1_,
film0_.replacement_cost as replacem8_1_,
film0_.special_features as special_9_1_,
film0_.title as title10_1_
from
film film0_
where
film0_.rating=?
order by
film0_.length desc,
film0_.title asc
limit ?, ?
```
--------------------------------
### Processing HTML with WritableStream
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/htmlparser2/README.md
Shows how to use the WritableStream interface for processing HTML from a Node.js readable stream. Ideal for large HTML files.
```javascript
const { WritableStream } = require("htmlparser2/lib/WritableStream");
const parserStream = new WritableStream({
ontext(text) {
console.log("Streaming:", text);
},
});
const htmlStream = fs.createReadStream("./my-file.html");
htmlStream.pipe(parserStream).on("finish", () => console.log("done"));
```
--------------------------------
### Filter Films by Title Not Starting With (Ignore Case)
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/string-predicates.adoc
Use `notStartsWithIgnoreCase` to filter entities where a string property does not begin with a specified prefix, ignoring case. This provides case-insensitive exclusion.
```java
jpaStreamer.stream(Film.class)
.filter(Film$.title.notStartsWithIgnoreCase("ala"))
.forEachOrdered(System.out::println);
```
--------------------------------
### Import nth-check utilities
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/nth-check/README.md
Import the main nthCheck function along with parse and compile utilities from the 'nth-check' package.
```javascript
import nthCheck, { parse, compile } from "nth-check";
```
--------------------------------
### Filter Films by Length Not Between Range
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/comparable-predicates.adoc
Filters films where the length is outside a specified inclusive range. Ensure the start and end parameters are in the correct order to avoid always evaluating to true.
```java
jpaStreamer.stream(Film.class)
.filter(Film$.length.notBetween(60, 120, Inclusion.START_INCLUSIVE_END_INCLUSIVE))
.forEachOrdered(System.out::println);
```
--------------------------------
### Filter Films by Title Starting with 'A' using JPAstreamer Field
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/predicates.adoc
Shows how to filter a stream of Film objects by their title using a JPAstreamer StringField. This method allows JPAstreamer to optimize the query.
```java
jpaStreamer.stream(Film.class)
.filter(Film$.title.startsWith("A"))
.forEachOrdered(System.out::println);
```
--------------------------------
### Maven Build Helper Plugin Configuration
Source: https://github.com/speedment/jpa-streamer/blob/master/README.adoc
Configures the build-helper-maven-plugin to add generated sources directory. This is needed by some IDEs to recognize compile-time generated code.
```xml
org.codehaus.mojobuild-helper-maven-plugin3.2.0generate-sourcesadd-source${project.build.directory}/generated-sources/annotations
```
--------------------------------
### Using Cheerio Slim Export
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/cheerio/Readme.md
Use the slim export of Cheerio to reduce bundle size. This version always uses htmlparser2.
```javascript
const cheerio = require('cheerio/lib/slim');
```
--------------------------------
### Configure Maven Build Helper Plugin
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/quick-start/pages/quick-start.adoc
Configure the build-helper-maven-plugin to add the generated metamodel sources to your project. This ensures the compiler can find the generated classes.
```xml
org.codehaus.mojobuild-helper-maven-plugin3.2.0generate-sourcesadd-source${project.build.directory}/generated-sources/annotations
```
--------------------------------
### Check index against nth-check formula
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/nth-check/README.md
Use the nthCheck function to create a checker for a given CSS nth-formula. Note that the CSS rule starts counting at 1, but the returned function checks from index 0.
```javascript
const check = nthCheck("2n+3");
check(0); // `false`
check(1); // `false`
check(2); // `true`
check(3); // `false`
check(4); // `true`
check(5); // `false`
check(6); // `true`
```
--------------------------------
### Import css-select
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/css-select/README.md
Import the css-select module for use in your project. This is the primary way to access its functionality.
```javascript
const CSSselect = require("css-select");
```
--------------------------------
### Get Summary Statistics of Stream Elements
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/stream-fundamentals/pages/terminal_operations.adoc
Use `summaryStatistics()` to obtain a comprehensive set of statistics for an IntStream, including count, sum, min, average, and max. Handles empty streams by returning default statistical values.
```java
IntStream.of(1, 2, 3, 4)
.summaryStatistics();
```
--------------------------------
### Equivalent OR using stream concatenation
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/combining-predicates.adoc
Illustrates an alternative to `or()` by concatenating two streams and then applying `distinct()`. This approach requires JVM-level handling for distinctness and is generally less performant than using `Predicate::or`.
```java
StreamComposition.concatAndAutoClose(
jpaStreamer.stream(Film.class).filter(Film$.length.greaterThan(120)),
jpaStreamer.stream(Film.class).filter(Film$.rating.equal("PG-13"))
)
.distinct()
.forEachOrdered(System.out::println);
```
--------------------------------
### Configure Eager Joins with StreamConfiguration
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/sql-equivalents.adoc
Use StreamConfiguration to eagerly join related fields like 'actors' and 'language' to avoid N+1 SELECT issues.
```java
StreamConfiguration configuration = StreamConfiguration.of(Film.class)
.joining(Film$.actors)
.joining(Film$.language);
```
--------------------------------
### Create Stream with Filter and Collect
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/fetching-data.adoc
Demonstrates creating a stream from the Film table, filtering by name, and collecting the results. The terminal operation closes the stream and its EntityManager.
```java
final JPAStreamer jpaStreamer = JPAStreamer.of("sakila");
final List films = jpaStreamer.stream(Film.class)
.filter(Film$.name.equal("Casablanca"))
.collect(toList());
```
--------------------------------
### CSSselect.selectAll(query, elems, options)
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/css-select/README.md
Selects all elements from a list that match the given CSS selector query. Returns an array of matching elements.
```APIDOC
## CSSselect.selectAll(query, elems, options)
### Description
Selects all elements from a list that match the given CSS selector query.
### Parameters
#### Path Parameters
- **query** (string | function) - Required - The CSS selector string or a compiled function to match against.
- **elems** (array) - Required - The list of elements to search within.
- **options** (object) - Optional - Configuration options for the selection process.
### Returns
- array - An array of elements that match the query.
```
--------------------------------
### Negating startsWith Predicate
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/predicates/pages/negating-predicates.adoc
Negating startsWith(p) results in the notStartsWith(p) predicate.
```java
notStartsWith(p)
```
--------------------------------
### Combine OFFSET and LIMIT
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/sql-equivalents.adoc
Combines skip and limit operations to fetch a specific range of records. Note that the order of `.skip()` and `.limit()` is crucial and differs from SQL.
```java
films.stream()
.sorted(Film.TITLE)
.skip(100)
.limit(50)
.forEachOrdered(System.out::println);
```
--------------------------------
### CSSselect.selectOne(query, elems, options)
Source: https://github.com/speedment/jpa-streamer/blob/master/node_modules/css-select/README.md
Selects the first element from a list that matches the given CSS selector query. Returns the matching element or null if no match is found.
```APIDOC
## CSSselect.selectOne(query, elems, options)
### Description
Selects the first element from a list that matches the given CSS selector query.
### Parameters
#### Path Parameters
- **query** (string | function) - Required - The CSS selector string or a compiled function to match against.
- **elems** (array) - Required - The list of elements to search within.
- **options** (object) - Optional - Configuration options for the selection process.
### Returns
- object | null - The first element that matches the query, or `null` if no match is found.
```
--------------------------------
### Map Actors to Films
Source: https://github.com/speedment/jpa-streamer/blob/master/docs/modules/fetching-data/pages/stream-examples.adoc
Collects actors and their associated films into a Map. Use this to create a filmography where each actor is a key and their list of films is the value.
```java
Map> filmography = jpaStreamer.stream(of(Actor.class).joining(Actor$.films)) \
.collect(
Collectors.toMap(Function.identity(), \
Actor::getFilms
)
);
```