Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into BAEL-5229
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzer committed Feb 10, 2022
2 parents 8a7ee4a + 4bac926 commit fbf8a78
Show file tree
Hide file tree
Showing 187 changed files with 3,553 additions and 671 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ HELP.md

### VS Code ###
.vscode/

18 changes: 9 additions & 9 deletions apache-olingo/Samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ This following table contains test URLs that can be used with the Olingo V2 demo

| URL | Description |
|------------------------------------------|-------------------------------------------------|
| `http://localhost:8180/odata/$metadata` | fetch OData metadata document |
| `http://localhost:8180/odata/CarMakers?$top=10&$skip=10` | Get 10 entities starting at offset 10 |
| `http://localhost:8180/odata/CarMakers?$count` | Return total count of entities in this set |
| `http://localhost:8180/odata/CarMakers?$filter=startswith(Name,'B')` | Return entities where the *Name* property starts with 'B' |
| `http://localhost:8180/odata/CarModels?$filter=Year eq 2008 and CarMakerDetails/Name eq 'BWM'` | Return *CarModel* entities where the *Name* property of its maker starts with 'B' |
| `http://localhost:8180/odata/CarModels(1L)?$expand=CarMakerDetails` | Return the *CarModel* with primary key '1', along with its maker|
| `http://localhost:8180/odata/CarModels(1L)?$select=Name,Sku` | Return the *CarModel* with primary key '1', returing only its *Name* and *Sku* properties |
| `http://localhost:8180/odata/CarModels?$orderBy=Name asc,Sku desc` | Return *CarModel* entities, ordered by the their *Name* and *Sku* properties |
| `http://localhost:8180/odata/CarModels?$format=json` | Return *CarModel* entities, using a JSON representation|
| `http://localhost:8080/odata/$metadata` | fetch OData metadata document |
| `http://localhost:8080/odata/CarMakers?$top=10&$skip=10` | Get 10 entities starting at offset 10 |
| `http://localhost:8080/odata/CarMakers?$count` | Return total count of entities in this set |
| `http://localhost:8080/odata/CarMakers?$filter=startswith(Name,'B')` | Return entities where the *Name* property starts with 'B' |
| `http://localhost:8080/odata/CarModels?$filter=Year eq 2008 and CarMakerDetails/Name eq 'BWM'` | Return *CarModel* entities where the *Name* property of its maker starts with 'B' |
| `http://localhost:8080/odata/CarModels(1L)?$expand=CarMakerDetails` | Return the *CarModel* with primary key '1', along with its maker|
| `http://localhost:8080/odata/CarModels(1L)?$select=Name,Sku` | Return the *CarModel* with primary key '1', returing only its *Name* and *Sku* properties |
| `http://localhost:8080/odata/CarModels?$orderBy=Name asc,Sku desc` | Return *CarModel* entities, ordered by the their *Name* and *Sku* properties |
| `http://localhost:8080/odata/CarModels?$format=json` | Return *CarModel* entities, using a JSON representation|



Expand Down
20 changes: 10 additions & 10 deletions apache-olingo/olingo2/pom.xml → apache-olingo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.examples.olingo2</groupId>
<artifactId>olingo2</artifactId>
<name>olingo2</name>
<description>Sample Olingo 2 Project</description>
<groupId>com.baeldung.examples.olingo</groupId>
<artifactId>apache-olingo</artifactId>
<name>apache-olingo</name>
<description>Sample Apache Olingo Project</description>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
<relativePath>../parent-boot-2</relativePath>
</parent>

<dependencies>
Expand Down Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-core</artifactId>
<version>${olingo2.version}</version>
<version>${olingo.version}</version>
<!-- Avoid jax-rs version conflict by excluding Olingo's version -->
<exclusions>
<exclusion>
Expand All @@ -55,12 +55,12 @@
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-jpa-processor-core</artifactId>
<version>${olingo2.version}</version>
<version>${olingo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-jpa-processor-ref</artifactId>
<version>${olingo2.version}</version>
<version>${olingo.version}</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.persistence</groupId>
Expand All @@ -80,7 +80,7 @@
</build>

<properties>
<olingo2.version>2.0.11</olingo2.version>
<olingo.version>2.0.11</olingo.version>
</properties>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* ODataJPAServiceFactory implementation for our sample domain
* @author Philippe
*
*/
@Component
public class CarsODataJPAServiceFactory extends ODataJPAServiceFactory {

Expand All @@ -44,7 +39,7 @@ public CarsODataJPAServiceFactory() {

/**
* This method will be called by Olingo on every request to
* initialize the ODataJPAContext that will be used.
* initialize the ODataJPAContext that will be used.
*/
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
Expand All @@ -54,14 +49,14 @@ public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeExcepti
ODataContext octx = ctx.getODataContext();
HttpServletRequest request = (HttpServletRequest)octx.getParameter(ODataContext.HTTP_SERVLET_REQUEST_OBJECT);
EntityManager em = (EntityManager)request.getAttribute(JerseyConfig.EntityManagerFilter.EM_REQUEST_ATTRIBUTE);

// Here we're passing the EM that was created by the EntityManagerFilter (see JerseyConfig)
ctx.setEntityManager(new EntityManagerWrapper(em));
ctx.setPersistenceUnitName("default");

// We're managing the EM's lifecycle, so we must inform Olingo that it should not
// try to manage transactions and/or persistence sessions
ctx.setContainerManaged(true);
ctx.setContainerManaged(true);
return ctx;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.baeldung.examples.olingo2;
package com.baeldung.examples.olingo2;

import java.io.IOException;
import org.apache.olingo.odata2.api.ODataServiceFactory;
import org.apache.olingo.odata2.core.rest.ODataRootLocator;
import org.apache.olingo.odata2.core.rest.app.ODataApplication;
import org.glassfish.jersey.server.ResourceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
Expand All @@ -15,28 +21,15 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;

import org.apache.olingo.odata2.api.ODataServiceFactory;
import org.apache.olingo.odata2.core.rest.ODataRootLocator;
import org.apache.olingo.odata2.core.rest.app.ODataApplication;
import org.glassfish.jersey.server.ResourceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* Jersey JAX-RS configuration
* @author Philippe
*
*/
@Component
@ApplicationPath("/odata")
public class JerseyConfig extends ResourceConfig {
public JerseyConfig(CarsODataJPAServiceFactory serviceFactory, EntityManagerFactory emf) {


public JerseyConfig(CarsODataJPAServiceFactory serviceFactory, EntityManagerFactory emf) {

ODataApplication app = new ODataApplication();

app
.getClasses()
.forEach( c -> {
Expand All @@ -46,11 +39,11 @@ public JerseyConfig(CarsODataJPAServiceFactory serviceFactory, EntityManagerFact
register(c);
}
});
register(new CarsRootLocator(serviceFactory));

register(new CarsRootLocator(serviceFactory));
register( new EntityManagerFilter(emf));
}

/**
* This filter handles the EntityManager transaction lifecycle.
* @author Philippe
Expand All @@ -72,7 +65,7 @@ public EntityManagerFilter(EntityManagerFactory emf) {
}

@Override
public void filter(ContainerRequestContext ctx) throws IOException {
public void filter(ContainerRequestContext ctx) {
log.info("[I60] >>> filter");
EntityManager em = this.emf.createEntityManager();
httpRequest.setAttribute(EM_REQUEST_ATTRIBUTE, em);
Expand All @@ -85,7 +78,7 @@ public void filter(ContainerRequestContext ctx) throws IOException {
}

@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {

log.info("[I68] <<< filter");
EntityManager em = (EntityManager) httpRequest.getAttribute(EM_REQUEST_ATTRIBUTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@SpringBootApplication
public class Olingo2SampleApplication extends SpringBootServletInitializer {

public static void main(String[] args) {
public static void main(String[] args) {
SpringApplication.run(Olingo2SampleApplication.class);
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@RunWith(SpringRunner.class)
@SpringBootTest
public class Olingo2SampleApplicationUnitTest {
public class Olingo2SampleApplicationIntegrationTest {

@Test
public void contextLoads() {
Expand Down
2 changes: 1 addition & 1 deletion apache-shiro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<properties>
<apache-shiro-core-version>1.5.3</apache-shiro-core-version>
<log4j-version>1.2.17</log4j-version>
<log4j.version>2.17.1</log4j.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.baeldung.differences.rdd;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
Expand All @@ -12,21 +12,27 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.File;

public class TransformationsUnitTest {

public static final String COMMA_DELIMITER = ",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";

private static JavaSparkContext sc;
private static JavaRDD<String> tourists;

@BeforeClass
public static void init() {
SparkConf conf = new SparkConf().setAppName("uppercaseCountries")
.setMaster("local[*]");
sc = new JavaSparkContext(conf);
tourists = sc.textFile("data/Tourist.csv")
.filter(line -> !line.startsWith("Region")); //filter header row

// delete previous output dir and files
FileUtils.deleteQuietly(new File("data/output"));
}

@AfterClass
public static void cleanup() {
sc.close();
Expand All @@ -39,9 +45,9 @@ public void whenMapUpperCase_thenCountryNameUppercased() {
return columns[1].toUpperCase();
})
.distinct();

upperCaseCountries.saveAsTextFile("data/output/uppercase.txt");

upperCaseCountries.foreach(country -> {
//replace non alphanumerical characters
country = country.replaceAll("[^a-zA-Z]", "");
Expand All @@ -52,9 +58,9 @@ public void whenMapUpperCase_thenCountryNameUppercased() {
@Test
public void whenFilterByCountry_thenShowRequestedCountryRecords() {
JavaRDD<String> touristsInMexico = tourists.filter(line -> line.split(COMMA_DELIMITER)[1].equals("Mexico"));

touristsInMexico.saveAsTextFile("data/output/touristInMexico.txt");

touristsInMexico.foreach(record -> {
assertEquals("Mexico", record.split(COMMA_DELIMITER)[1]);
});
Expand Down
Empty file removed book
Empty file.
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.baeldung.collections.iterators;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;

/**
* Source code https://github.com/eugenp/tutorials
*
* @author Santosh Thakur
*/

public class Iterators {

private static final Logger LOG = LoggerFactory.getLogger(Iterators.class);

public static int failFast1() {
ArrayList<Integer> numbers = new ArrayList<>();

Expand Down Expand Up @@ -44,7 +43,7 @@ public static int failFast2() {
}
}

System.out.println("using iterator's remove method = " + numbers);
LOG.debug("using iterator's remove method = {}", numbers);

iterator = numbers.iterator();
while (iterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
import org.junit.Test;
import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.info.GraphLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.BitSet;

import static org.assertj.core.api.Assertions.assertThat;

public class BitSetUnitTest {

private static final Logger LOG = LoggerFactory.getLogger(BitSetUnitTest.class);

@Test
public void givenBoolArray_whenMemoryLayout_thenConsumeMoreThanOneBit() {
boolean[] bits = new boolean[1024 * 1024];

System.out.println(ClassLayout.parseInstance(bits).toPrintable());
LOG.debug(ClassLayout.parseInstance(bits).toPrintable());
}

@Test
public void givenBitSet_whenMemoryLayout_thenConsumeOneBitPerFlag() {
BitSet bitSet = new BitSet(1024 * 1024);

System.out.println(GraphLayout.parseInstance(bitSet).toPrintable());
LOG.debug(GraphLayout.parseInstance(bitSet).toPrintable());
}

@Test
Expand Down Expand Up @@ -157,7 +161,7 @@ public void givenBitSet_whenStream_thenStreamsAllSetBits() {
BitSet bitSet = new BitSet();
bitSet.set(15, 25);

bitSet.stream().forEach(System.out::println);
bitSet.stream().forEach(bit -> LOG.debug(String.valueOf(bit)));
assertThat(bitSet.stream().count()).isEqualTo(10);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Loading

0 comments on commit fbf8a78

Please sign in to comment.