diff --git a/.gitignore b/.gitignore index 0b6bd24070..06c5242898 100644 --- a/.gitignore +++ b/.gitignore @@ -64,13 +64,13 @@ core-java-io/hard_link.txt core-java-io/target_link.txt core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF ethereum/logs/ -jmeter/src/main/resources/*-JMeter.csv -jmeter/src/main/resources/*-Basic*.csv -jmeter/src/main/resources/*-JMeter*.csv -jmeter/src/main/resources/*ReportsDashboard*.csv -jmeter/src/main/resources/dashboard/*ReportsDashboard*.csv -jmeter/src/main/resources/*FileExtractionExample.csv -jmeter/src/main/resources/*_Summary-Report.csv +testing-modules/jmeter/src/main/resources/*-JMeter.csv +testing-modules/jmeter/src/main/resources/*-Basic*.csv +testing-modules/jmeter/src/main/resources/*-JMeter*.csv +testing-modules/jmeter/src/main/resources/*ReportsDashboard*.csv +testing-modules/jmeter/src/main/resources/dashboard/*ReportsDashboard*.csv +testing-modules/jmeter/src/main/resources/*FileExtractionExample.csv +testing-modules/jmeter/src/main/resources/*_Summary-Report.csv ninja/devDb.mv.db @@ -128,3 +128,6 @@ persistence-modules/neo4j/data/** /deep-shallow-copy/.mvn/wrapper /deep-shallow-copy/mvnw /deep-shallow-copy/mvnw.cmd + +#spring-5-webflux-2 +**/testdb.mv.db \ No newline at end of file diff --git a/apache-poi-3/README.md b/apache-poi-3/README.md index 9e9d6a94eb..b7272d5e69 100644 --- a/apache-poi-3/README.md +++ b/apache-poi-3/README.md @@ -1,3 +1,4 @@ ## Relevant Articles - [How To Convert Excel Data Into List Of Java Objects](https://www.baeldung.com/java-convert-excel-data-into-list) - [Expand Columns with Apache POI](https://www.baeldung.com/java-apache-poi-expand-columns) +- [Apply Bold Text Style for an Entire Row Using Apache POI](https://www.baeldung.com/appache-poi-apply-bold-text-style-entire-row) diff --git a/core-java-modules/core-java-21/README.md b/core-java-modules/core-java-21/README.md index ffb999a4ba..fcb9faaace 100644 --- a/core-java-modules/core-java-21/README.md +++ b/core-java-modules/core-java-21/README.md @@ -3,3 +3,4 @@ - [String Templates in Java 21](https://www.baeldung.com/java-21-string-templates) - [Unnamed Classes and Instance Main Methods in Java 21](https://www.baeldung.com/java-21-unnamed-class-instance-main) - [Unnamed Patterns and Variables in Java 21](https://www.baeldung.com/java-unnamed-patterns-variables) +- [JFR View Command in Java 21](https://www.baeldung.com/java-flight-recorder-view) diff --git a/core-java-modules/core-java-8-datetime-2/README.md b/core-java-modules/core-java-8-datetime-2/README.md index 799e5f6a49..e689e7257f 100644 --- a/core-java-modules/core-java-8-datetime-2/README.md +++ b/core-java-modules/core-java-8-datetime-2/README.md @@ -10,4 +10,7 @@ - [Representing Furthest Possible Date in Java](https://www.baeldung.com/java-date-represent-max) - [Retrieving Unix Time in Java](https://www.baeldung.com/java-retrieve-unix-time) - [Calculate Months Between Two Dates in Java](https://www.baeldung.com/java-months-difference-two-dates) +- [Format LocalDate to ISO 8601 With T and Z](https://www.baeldung.com/java-format-localdate-iso-8601-t-z) +- [Check if Two Date Ranges Overlap](https://www.baeldung.com/java-check-two-date-ranges-overlap) +- [Difference between ZoneOffset.UTC and ZoneId.of(“UTC”)](https://www.baeldung.com/java-zoneoffset-utc-zoneid-of) - [[<-- Prev]](/core-java-modules/core-java-datetime-java8-1) diff --git a/core-java-modules/core-java-arrays-convert/README.md b/core-java-modules/core-java-arrays-convert/README.md index 118d8e00ed..01a65670b2 100644 --- a/core-java-modules/core-java-arrays-convert/README.md +++ b/core-java-modules/core-java-arrays-convert/README.md @@ -12,3 +12,4 @@ This module contains articles about arrays conversion in Java - [Convert an ArrayList of String to a String Array in Java](https://www.baeldung.com/java-convert-string-arraylist-array) - [Convert Char Array to Int Array in Java](https://www.baeldung.com/java-convert-char-int-array) - [How to Convert Byte Array to Char Array](https://www.baeldung.com/java-convert-byte-array-char) +- [Convert byte[] to Byte[] and Vice Versa in Java](https://www.baeldung.com/java-byte-array-wrapper-primitive-type-convert) diff --git a/core-java-modules/core-java-collections-5/README.md b/core-java-modules/core-java-collections-5/README.md index cf731e8f09..4f174b5163 100644 --- a/core-java-modules/core-java-collections-5/README.md +++ b/core-java-modules/core-java-collections-5/README.md @@ -13,4 +13,5 @@ - [Time Complexity of Java Collections Sort in Java](https://www.baeldung.com/java-time-complexity-collections-sort) - [Check if List Contains at Least One Enum](https://www.baeldung.com/java-list-check-enum-presence) - [Comparison of for Loops and Iterators](https://www.baeldung.com/java-for-loops-vs-iterators) +- [PriorityQueue iterator() Method in Java](https://www.baeldung.com/java-priorityqueue-iterator) - More articles: [[<-- prev]](/core-java-modules/core-java-collections-4) diff --git a/core-java-modules/core-java-collections-list-6/README.md b/core-java-modules/core-java-collections-list-6/README.md index 30ae5eb2dd..bf634fb79c 100644 --- a/core-java-modules/core-java-collections-list-6/README.md +++ b/core-java-modules/core-java-collections-list-6/README.md @@ -3,3 +3,4 @@ - [Removing the Last Node in a Linked List](https://www.baeldung.com/java-linked-list-remove-last-element) - [Call a Method on Each Element of a List in Java](https://www.baeldung.com/java-call-method-each-list-item) - [Sorting One List Based on Another List in Java](https://www.baeldung.com/java-sorting-one-list-using-another) +- [Reset ListIterator to First Element of the List in Java](https://www.baeldung.com/java-reset-listiterator) diff --git a/core-java-modules/core-java-collections-maps-7/README.md b/core-java-modules/core-java-collections-maps-7/README.md index 73b36394a3..54668e13e5 100644 --- a/core-java-modules/core-java-collections-maps-7/README.md +++ b/core-java-modules/core-java-collections-maps-7/README.md @@ -5,6 +5,6 @@ - [How to Get First or Last Entry From a LinkedHashMap in Java](https://www.baeldung.com/java-linkedhashmap-first-last-key-value-pair) - [How to Write and Read a File with a Java HashMap](https://www.baeldung.com/java-hashmap-write-read-file) - [Limiting the Max Size of a HashMap in Java](https://www.baeldung.com/java-hashmap-size-bound) -- [How to Sort LinkedHashMap By Values in Java](https://www.baeldung.com/java-sort-linkedhashmap-using-values) +- [How to Sort LinkedHashMap by Values in Java](https://www.baeldung.com/java-sort-linkedhashmap-using-values) - [How to Increment a Map Value in Java](https://www.baeldung.com/java-increment-map-value) - More articles: [[<-- prev]](/core-java-modules/core-java-collections-maps-6) diff --git a/core-java-modules/core-java-console/README.md b/core-java-modules/core-java-console/README.md index 77ad16d015..cab2cc24be 100644 --- a/core-java-modules/core-java-console/README.md +++ b/core-java-modules/core-java-console/README.md @@ -8,3 +8,4 @@ - [System.console() vs. System.out](https://www.baeldung.com/java-system-console-vs-system-out) - [How to Log to the Console in Color](https://www.baeldung.com/java-log-console-in-color) - [Create Table Using ASCII in a Console in Java](https://www.baeldung.com/java-console-ascii-make-table) +- [Printing Message on Console without Using main() Method in Java](https://www.baeldung.com/java-no-main-print-message-console) diff --git a/core-java-modules/core-java-date-operations-4/README.md b/core-java-modules/core-java-date-operations-4/README.md index b7817ebd1e..bfc460f5eb 100644 --- a/core-java-modules/core-java-date-operations-4/README.md +++ b/core-java-modules/core-java-date-operations-4/README.md @@ -2,4 +2,5 @@ This module contains articles about date operations in Java. ### Relevant Articles: +- [Calculate Number of Weekdays Between Two Dates in Java](https://www.baeldung.com/java-count-weekdays-between-two-dates) diff --git a/core-java-modules/core-java-datetime-conversion-2/src/main/java/com/baeldung/stringdatetoxmlgregoriancalendar/StringDateToXMLGregorianCalendarConverter.java b/core-java-modules/core-java-datetime-conversion-2/src/main/java/com/baeldung/stringdatetoxmlgregoriancalendar/StringDateToXMLGregorianCalendarConverter.java new file mode 100644 index 0000000000..2ec1efecd0 --- /dev/null +++ b/core-java-modules/core-java-datetime-conversion-2/src/main/java/com/baeldung/stringdatetoxmlgregoriancalendar/StringDateToXMLGregorianCalendarConverter.java @@ -0,0 +1,42 @@ +package com.baeldung.stringdatetoxmlgregoriancalendar; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.util.Date; +import java.util.GregorianCalendar; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; + +public class StringDateToXMLGregorianCalendarConverter { + public static XMLGregorianCalendar usingDatatypeFactoryForDate(String dateAsString) throws DatatypeConfigurationException { + return DatatypeFactory.newInstance().newXMLGregorianCalendar(dateAsString); + } + + public static XMLGregorianCalendar usingLocalDate(String dateAsString) throws DatatypeConfigurationException { + LocalDate localDate = LocalDate.parse(dateAsString); + return DatatypeFactory.newInstance().newXMLGregorianCalendar(localDate.toString()); + } + + public static XMLGregorianCalendar usingSimpleDateFormat(String dateTimeAsString) throws DatatypeConfigurationException, ParseException { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + Date date = simpleDateFormat.parse(dateTimeAsString); + return DatatypeFactory.newInstance().newXMLGregorianCalendar(simpleDateFormat.format(date)); + } + + public static XMLGregorianCalendar usingGregorianCalendar(String dateTimeAsString) throws DatatypeConfigurationException, ParseException { + GregorianCalendar calendar = new GregorianCalendar(); + calendar.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(dateTimeAsString)); + return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); + } + + public static XMLGregorianCalendar usingJodaTime(String dateTimeAsString) throws DatatypeConfigurationException { + DateTime dateTime = DateTime.parse(dateTimeAsString, DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss")); + return DatatypeFactory.newInstance().newXMLGregorianCalendar(dateTime.toGregorianCalendar()); + } +} diff --git a/core-java-modules/core-java-datetime-conversion-2/src/test/java/com/baeldung/stringdatetoxmlgregoriancalendar/StringDateToXMLGregorianCalendarConverterUnitTest.java b/core-java-modules/core-java-datetime-conversion-2/src/test/java/com/baeldung/stringdatetoxmlgregoriancalendar/StringDateToXMLGregorianCalendarConverterUnitTest.java new file mode 100644 index 0000000000..b3c15a3fd4 --- /dev/null +++ b/core-java-modules/core-java-datetime-conversion-2/src/test/java/com/baeldung/stringdatetoxmlgregoriancalendar/StringDateToXMLGregorianCalendarConverterUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.stringdatetoxmlgregoriancalendar; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.text.ParseException; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.junit.jupiter.api.Test; + +public class StringDateToXMLGregorianCalendarConverterUnitTest { + private static final String dateAsString = "2014-04-24"; + private static final String dateTimeAsString = "2014-04-24T15:45:30"; + + @Test + void givenStringDate_whenUsingDatatypeFactory_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException { + XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingDatatypeFactoryForDate(dateAsString); + assertEquals(24,xmlGregorianCalendar.getDay()); + assertEquals(4,xmlGregorianCalendar.getMonth()); + assertEquals(2014,xmlGregorianCalendar.getYear()); + } + + @Test + void givenStringDateTime_whenUsingApacheCommonsLang3_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException { + XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingLocalDate(dateAsString); + assertEquals(24,xmlGregorianCalendar.getDay()); + assertEquals(4,xmlGregorianCalendar.getMonth()); + assertEquals(2014,xmlGregorianCalendar.getYear()); + } + + @Test + void givenStringDateTime_whenUsingSimpleDateFormat_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException, ParseException { + XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingSimpleDateFormat(dateTimeAsString); + assertEquals(24,xmlGregorianCalendar.getDay()); + assertEquals(4,xmlGregorianCalendar.getMonth()); + assertEquals(2014,xmlGregorianCalendar.getYear()); + assertEquals(15,xmlGregorianCalendar.getHour()); + assertEquals(45,xmlGregorianCalendar.getMinute()); + assertEquals(30,xmlGregorianCalendar.getSecond()); + } + + @Test + void givenStringDateTime_whenUsingGregorianCalendar_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException, ParseException { + XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingGregorianCalendar(dateTimeAsString); + assertEquals(24,xmlGregorianCalendar.getDay()); + assertEquals(4,xmlGregorianCalendar.getMonth()); + assertEquals(2014,xmlGregorianCalendar.getYear()); + assertEquals(15,xmlGregorianCalendar.getHour()); + assertEquals(45,xmlGregorianCalendar.getMinute()); + assertEquals(30,xmlGregorianCalendar.getSecond()); + } + + @Test + void givenStringDateTime_whenUsingJodaTime_thenConvertToXMLGregorianCalendar() throws DatatypeConfigurationException { + XMLGregorianCalendar xmlGregorianCalendar = StringDateToXMLGregorianCalendarConverter.usingJodaTime(dateTimeAsString); + assertEquals(24,xmlGregorianCalendar.getDay()); + assertEquals(4,xmlGregorianCalendar.getMonth()); + assertEquals(2014,xmlGregorianCalendar.getYear()); + assertEquals(15,xmlGregorianCalendar.getHour()); + assertEquals(45,xmlGregorianCalendar.getMinute()); + assertEquals(30,xmlGregorianCalendar.getSecond()); + } +} diff --git a/core-java-modules/core-java-datetime-string-2/README.md b/core-java-modules/core-java-datetime-string-2/README.md index 6ff19a44ab..c6f06da8fb 100644 --- a/core-java-modules/core-java-datetime-string-2/README.md +++ b/core-java-modules/core-java-datetime-string-2/README.md @@ -5,3 +5,4 @@ This module contains articles about parsing and formatting Java date and time ob ### Relevant Articles: - [Convert String to Instant](https://www.baeldung.com/java-string-to-instant) - [Sort Date Strings in Java](https://www.baeldung.com/java-sort-date-strings) +- [Using Current Time as Filename in Java](https://www.baeldung.com/java-current-time-filename) diff --git a/core-java-modules/core-java-function/README.md b/core-java-modules/core-java-function/README.md index eb27aea153..b750ad8a5a 100644 --- a/core-java-modules/core-java-function/README.md +++ b/core-java-modules/core-java-function/README.md @@ -6,3 +6,4 @@ - [Java 8 Predicate Chain](https://www.baeldung.com/java-predicate-chain) - [Use Cases for Static Methods in Java](https://www.baeldung.com/java-static-methods-use-cases) - [TriFunction Interface in Java](https://www.baeldung.com/java-trifunction) +- [Lazy Field Initialization with Lambdas](https://www.baeldung.com/java-lambda-lazy-field-initialization) diff --git a/core-java-modules/core-java-io-4/README.md b/core-java-modules/core-java-io-4/README.md index 7856fbaf41..4b2bba6a50 100644 --- a/core-java-modules/core-java-io-4/README.md +++ b/core-java-modules/core-java-io-4/README.md @@ -9,7 +9,7 @@ This module contains articles about core Java input and output (IO) - [SequenceInputStream Class in Java](https://www.baeldung.com/java-sequenceinputstream) - [Read a File Into a Map in Java](https://www.baeldung.com/java-read-file-into-map) - [Read User Input Until a Condition Is Met](https://www.baeldung.com/java-read-input-until-condition) -- [Java Scanner.skip method with examples](https://www.baeldung.com/java-scanner-skip) +- [Java Scanner.skip Method with Examples](https://www.baeldung.com/java-scanner-skip) - [Generate the MD5 Checksum for a File in Java](https://www.baeldung.com/java-md5-checksum-file) - [Getting the Filename From a String Containing an Absolute File Path](https://www.baeldung.com/java-filename-full-path) - [Mocking Java InputStream Object](https://www.baeldung.com/java-mocking-inputstream) diff --git a/core-java-modules/core-java-io-5/README.md b/core-java-modules/core-java-io-5/README.md index 141d840498..f0dafe2e4b 100644 --- a/core-java-modules/core-java-io-5/README.md +++ b/core-java-modules/core-java-io-5/README.md @@ -7,5 +7,6 @@ This module contains articles about core Java input and output (IO) - [How to Remove Line Breaks From a File in Java](https://www.baeldung.com/java-file-remove-line-breaks) - [Difference Between ZipFile and ZipInputStream in Java](https://www.baeldung.com/java-zipfile-vs-zipinputstream) - [How to Write Strings to OutputStream in Java](https://www.baeldung.com/java-write-string-outputstream) +- [Read a File and Split It Into Multiple Files in Java](https://www.baeldung.com/java-read-file-split-into-several) - [[<-- Prev]](/core-java-modules/core-java-io-4) diff --git a/core-java-modules/core-java-io-apis/README.md b/core-java-modules/core-java-io-apis/README.md index b00b0a6022..faf7067f74 100644 --- a/core-java-modules/core-java-io-apis/README.md +++ b/core-java-modules/core-java-io-apis/README.md @@ -11,5 +11,5 @@ This module contains articles about core Java input/output(IO) APIs. - [Quick Use of FilenameFilter](https://www.baeldung.com/java-filename-filter) - [Guide to BufferedReader](https://www.baeldung.com/java-buffered-reader) - [Difference Between FileReader and BufferedReader in Java](https://www.baeldung.com/java-filereader-vs-bufferedreader) -- [Java: Read Multiple Inputs on Same Line](https://www.baeldung.com/java-read-multiple-inputs-same-line) -- [Write Console Output to Text File in Java](https://www.baeldung.com/java-write-console-output-file) \ No newline at end of file +- [Read Multiple Inputs on the Same Line in Java](https://www.baeldung.com/java-read-multiple-inputs-same-line) +- [Write Console Output to Text File in Java](https://www.baeldung.com/java-write-console-output-file) diff --git a/core-java-modules/core-java-lang-6/README.md b/core-java-modules/core-java-lang-6/README.md index 6343f38e91..f50e0b0cd5 100644 --- a/core-java-modules/core-java-lang-6/README.md +++ b/core-java-modules/core-java-lang-6/README.md @@ -13,3 +13,4 @@ This module contains articles about core features in the Java language - [Compress and Uncompress Byte Array Using Deflater/Inflater](https://www.baeldung.com/java-compress-uncompress-byte-array) - [Static Final Variables in Java](https://www.baeldung.com/java-static-final-variables) - [What Is the Error: “Non-static method cannot be referenced from a static context”?](https://www.baeldung.com/java-non-static-method-cannot-be-referenced-from-a-static-context) +- [Recursively Sum the Integers in an Array](https://www.baeldung.com/java-recursive-sum-integer-array) diff --git a/core-java-modules/core-java-lang-math-3/README.md b/core-java-modules/core-java-lang-math-3/README.md index 97d99ad468..e0d7ccdcf5 100644 --- a/core-java-modules/core-java-lang-math-3/README.md +++ b/core-java-modules/core-java-lang-math-3/README.md @@ -14,4 +14,7 @@ - [Clamp Function in Java](https://www.baeldung.com/java-clamp-function) - [Creating a Magic Square in Java](https://www.baeldung.com/java-magic-square) - [Check if a Point Is Between Two Points Drawn on a Straight Line in Java](https://www.baeldung.com/java-check-point-straight-line) +- [Validate if a String Is a Valid Geo Coordinate](https://www.baeldung.com/java-geo-coordinates-validation) +- [Rotate a Vertex Around a Certain Point in Java](https://www.baeldung.com/java-rotate-vertex-around-point) +- [Calculating the Power of Any Number in Java Without Using Math pow() Method](https://www.baeldung.com/java-calculating-the-power-without-math-pow) - More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math-2) diff --git a/core-java-modules/core-java-numbers-7/README.md b/core-java-modules/core-java-numbers-7/README.md index af5334eea6..e86d199d97 100644 --- a/core-java-modules/core-java-numbers-7/README.md +++ b/core-java-modules/core-java-numbers-7/README.md @@ -1,3 +1,4 @@ ## Relevant Articles - [Check if a double Is an Integer in Java](https://www.baeldung.com/java-check-double-integer) - [Print a Double Value Without Scientific Notation in Java](https://www.baeldung.com/java-print-double-number-no-scientific-notation) +- [Check if a Float Value is Equivalent to an Integer Value in Java](https://www.baeldung.com/java-float-integer-equal) diff --git a/core-java-modules/core-java-numbers-conversions/README.md b/core-java-modules/core-java-numbers-conversions/README.md index e2031f0ee1..9f2a1d07b8 100644 --- a/core-java-modules/core-java-numbers-conversions/README.md +++ b/core-java-modules/core-java-numbers-conversions/README.md @@ -2,7 +2,7 @@ - [Convert a Number to a Letter in Java](https://www.baeldung.com/java-convert-number-to-letter) - [Convert Long to BigDecimal in Java](https://www.baeldung.com/java-convert-long-bigdecimal) - [Convert int to Long in Java](https://www.baeldung.com/java-convert-int-long) -- [How To Convert Double To Float In Java](https://www.baeldung.com/java-convert-double-float) +- [How to Convert Double to Float in Java](https://www.baeldung.com/java-convert-double-float) - [Converting from float to BigDecimal in Java](https://www.baeldung.com/java-convert-float-bigdecimal) - [Convert Positive Integer to Negative and Vice Versa in Java](https://www.baeldung.com/java-negating-integer) - [Rounding Up a Number to Nearest Multiple of 5 in Java](https://www.baeldung.com/java-round-nearest-multiple-five) diff --git a/core-java-modules/core-java-regex-2/README.md b/core-java-modules/core-java-regex-2/README.md index 404b33b65f..5f08a521c1 100644 --- a/core-java-modules/core-java-regex-2/README.md +++ b/core-java-modules/core-java-regex-2/README.md @@ -9,5 +9,5 @@ - [Regular Expression: \z vs \Z Anchors in Java](https://www.baeldung.com/java-regular-expression-z-vs-z-anchors) - [Extract Text Between Square Brackets](https://www.baeldung.com/java-get-content-between-square-brackets) - [Get the Indexes of Regex Pattern Matches in Java](https://www.baeldung.com/java-indexes-regex-pattern-matches) -- [Check if a String is Strictly Alphanumeric With Java](https://www.baeldung.com/java-check-string-contains-only-letters-numbers) +- [Check if a String Is Strictly Alphanumeric With Java](https://www.baeldung.com/java-check-string-contains-only-letters-numbers) - More articles: [[<-- prev]](/core-java-modules/core-java-regex) diff --git a/core-java-modules/core-java-security-4/README.md b/core-java-modules/core-java-security-4/README.md index 8f5ee308bd..5e12606bbf 100644 --- a/core-java-modules/core-java-security-4/README.md +++ b/core-java-modules/core-java-security-4/README.md @@ -7,4 +7,5 @@ This module contains articles about core Java Security - [Extract CN From X509 Certificate in Java](https://www.baeldung.com/java-extract-common-name-x509-certificate) - [Check Certificate Name and Alias in Keystore File](https://www.baeldung.com/java-keystore-check-certificate-name-alias) - [Using a Custom TrustStore in Java](https://www.baeldung.com/java-custom-truststore) +- [Enable Java SSL Debug Logging](https://www.baeldung.com/java-ssl-debug-logging) - More articles: [[<-- prev]](/core-java-modules/core-java-security-3) diff --git a/core-java-modules/core-java-string-operations-7/README.md b/core-java-modules/core-java-string-operations-7/README.md index de45ee0cec..c100b66ff7 100644 --- a/core-java-modules/core-java-string-operations-7/README.md +++ b/core-java-modules/core-java-string-operations-7/README.md @@ -3,11 +3,14 @@ - [How to Center Text Output in Java](https://www.baeldung.com/java-center-text-output) - [Capitalize the First Letter of Each Word in a String](https://www.baeldung.com/java-string-initial-capital-letter-every-word) - [Check if a String Contains Only Unicode Letters](https://www.baeldung.com/java-string-all-unicode-characters) -- [Create a Mutable String in Java](https://www.baeldung.com/java-mutable-string) +- [Create a “Mutable” String in Java](https://www.baeldung.com/java-mutable-string) - [Check if a String Contains a Number Value in Java](https://www.baeldung.com/java-string-number-presence) - [Difference Between String isEmpty() and isBlank()](https://www.baeldung.com/java-string-isempty-vs-isblank) - [String’s Maximum Length in Java](https://www.baeldung.com/java-strings-maximum-length) - [Java’s String.length() and String.getBytes().length](https://www.baeldung.com/java-string-length-vs-getbytes-length) - [Replace Non-Printable Unicode Characters in Java](https://www.baeldung.com/java-replace-non-printable-unicode-characters) - [Check If a Java StringBuilder Object Contains a Character](https://www.baeldung.com/java-check-stringbuilder-object-contains-character) +- [Comparing One String With Multiple Values in One Expression in Java](https://www.baeldung.com/java-compare-string-multiple-values-one-expression) - [UTF-8 Validation in Java](https://www.baeldung.com/java-utf-8-validation) +- [Simple Morse Code Translation in Java](https://www.baeldung.com/java-morse-code-english-translate) +- [How to Determine if a String Contains Invalid Encoded Characters](https://www.baeldung.com/java-check-string-contains-invalid-encoded-characters) diff --git a/core-java-modules/core-java-uuid/pom.xml b/core-java-modules/core-java-uuid/pom.xml index e6710dbdf2..76154033c2 100644 --- a/core-java-modules/core-java-uuid/pom.xml +++ b/core-java-modules/core-java-uuid/pom.xml @@ -29,6 +29,16 @@ tsid-creator 5.2.3 + + commons-codec + commons-codec + 1.16.0 + + + org.apache.commons + commons-lang3 + 3.14.0 + diff --git a/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/DecodeUUIDStringFromBase64UnitTest.java b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/DecodeUUIDStringFromBase64UnitTest.java new file mode 100644 index 0000000000..177f231b53 --- /dev/null +++ b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/DecodeUUIDStringFromBase64UnitTest.java @@ -0,0 +1,64 @@ +package com.baeldung.uuid; + +import static org.apache.commons.codec.binary.Base64.decodeBase64; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.nio.ByteBuffer; +import java.util.Base64; +import java.util.UUID; + +import org.apache.commons.lang3.Conversion; +import org.junit.jupiter.api.Test; + +public class DecodeUUIDStringFromBase64UnitTest { + private final UUID originalUUID = UUID.fromString("cc5f93f7-8cf1-4a51-83c6-e740313a0c6c"); + + @Test + public void shouldDecodeUUIDUsingByteArrayAndBase64Decoder() { + String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw"; + byte[] decodedBytes = Base64.getDecoder() + .decode(expectedEncodedString); + UUID uuid = convertToUUID(decodedBytes); + assertEquals(originalUUID, uuid); + } + + @Test + public void shouldDecodeUUIDUsingByteBufferAndBase64UrlDecoder() { + String expectedEncodedString = "zF-T94zxSlGDxudAMToMbA"; + byte[] decodedBytes = Base64.getUrlDecoder() + .decode(expectedEncodedString); + ByteBuffer byteBuffer = ByteBuffer.wrap(decodedBytes); + long mostSignificantBits = byteBuffer.getLong(); + long leastSignificantBits = byteBuffer.getLong(); + UUID uuid = new UUID(mostSignificantBits, leastSignificantBits); + assertEquals(originalUUID, uuid); + } + + @Test + public void shouldDecodeUUIDUsingApacheUtils() { + String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw"; + byte[] decodedBytes = decodeBase64(expectedEncodedString); + UUID uuid = Conversion.byteArrayToUuid(decodedBytes, 0); + assertEquals(originalUUID, uuid); + } + + private UUID convertToUUID(byte[] src) { + long mostSignificantBits = convertBytesToLong(src, 0); + long leastSignificantBits = convertBytesToLong(src, 8); + + return new UUID(mostSignificantBits, leastSignificantBits); + } + + private long convertBytesToLong(byte[] uuidBytes, int start) { + long result = 0; + + for(int i = 0; i < 8; i++) { + int shift = i * 8; + long bits = (255L & (long)uuidBytes[i + start]) << shift; + long mask = 255L << shift; + result = result & ~mask | bits; + } + + return result; + } +} diff --git a/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/EncodeUUIDToBase64StringUnitTest.java b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/EncodeUUIDToBase64StringUnitTest.java new file mode 100644 index 0000000000..a1ba921d4a --- /dev/null +++ b/core-java-modules/core-java-uuid/src/test/java/com/baeldung/uuid/EncodeUUIDToBase64StringUnitTest.java @@ -0,0 +1,62 @@ +package com.baeldung.uuid; + +import static org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.nio.ByteBuffer; +import java.util.Base64; +import java.util.UUID; + +import org.apache.commons.lang3.Conversion; +import org.junit.jupiter.api.Test; + +public class EncodeUUIDToBase64StringUnitTest { + private final UUID originalUUID = UUID.fromString("cc5f93f7-8cf1-4a51-83c6-e740313a0c6c"); + + @Test + public void shouldEncodeUUIDUsingByteArrayAndBase64Encoder() { + String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw"; + byte[] uuidBytes = convertToByteArray(originalUUID); + String encodedUUID = Base64.getEncoder().withoutPadding() + .encodeToString(uuidBytes); + assertEquals(expectedEncodedString, encodedUUID); + } + + @Test + public void shouldEncodeUUIDUsingByteBufferAndBase64UrlEncoder() { + String expectedEncodedString = "zF-T94zxSlGDxudAMToMbA"; + ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); + byteBuffer.putLong(originalUUID.getMostSignificantBits()); + byteBuffer.putLong(originalUUID.getLeastSignificantBits()); + String encodedUUID = Base64.getUrlEncoder().withoutPadding() + .encodeToString(byteBuffer.array()); + assertEquals(expectedEncodedString, encodedUUID); + } + + @Test + public void shouldEncodeUUIDUsingApacheUtils() { + String expectedEncodedString = "UUrxjPeTX8xsDDoxQOfGgw"; + byte[] bytes = Conversion.uuidToByteArray(originalUUID, new byte[16], 0, 16); + String encodedUUID = encodeBase64URLSafeString(bytes); + assertEquals(expectedEncodedString, encodedUUID); + } + + private byte[] convertToByteArray(UUID uuid) { + byte[] result = new byte[16]; + + long mostSignificantBits = uuid.getMostSignificantBits(); + fillByteArray(0, 8, result, mostSignificantBits); + + long leastSignificantBits = uuid.getLeastSignificantBits(); + fillByteArray(8, 16, result, leastSignificantBits); + + return result; + } + + private static void fillByteArray(int start, int end, byte[] result, long bits) { + for (int i = start; i < end; i++) { + int shift = i * 8; + result[i] = (byte) ((int) (255L & bits >> shift)); + } + } +} diff --git a/json-modules/gson-2/README.md b/json-modules/gson-2/README.md index 912f8b0a20..4d7d917cc0 100644 --- a/json-modules/gson-2/README.md +++ b/json-modules/gson-2/README.md @@ -6,3 +6,4 @@ This module contains articles about Gson - [Solving Gson Parsing Errors](https://www.baeldung.com/gson-parsing-errors) - [Difference between Gson @Expose and @SerializedName](https://www.baeldung.com/gson-expose-vs-serializedname) - [Resolving Gson’s “Multiple JSON Fields” Exception](https://www.baeldung.com/java-gson-multiple-json-fields-exception) +- [Using Static Methods Instead of Deprecated JsonParser](https://www.baeldung.com/java-static-methods-jsonparser-replacement) diff --git a/libraries-data/README.md b/libraries-data/README.md index 7e87475328..9a8b1fbe4c 100644 --- a/libraries-data/README.md +++ b/libraries-data/README.md @@ -9,4 +9,5 @@ This module contains articles about libraries for data processing in Java. - [A Guide to Apache Crunch](https://www.baeldung.com/apache-crunch) - [Intro to Apache Storm](https://www.baeldung.com/apache-storm) - [Guide to JMapper](https://www.baeldung.com/jmapper) -More articles: [[next -->]](/../libraries-data-2) \ No newline at end of file +- [What Does It Mean to Hydrate an Object?](https://www.baeldung.com/java-object-hydration) +- More articles: [[next -->]](/../libraries-data-2) diff --git a/maven-modules/maven-build-lifecycle/README.md b/maven-modules/maven-build-lifecycle/README.md new file mode 100644 index 0000000000..0fe002223f --- /dev/null +++ b/maven-modules/maven-build-lifecycle/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Difference Between mvn install and mvn verify](https://www.baeldung.com/maven-install-versus-verify) diff --git a/patterns-modules/design-patterns-creational-2/README.md b/patterns-modules/design-patterns-creational-2/README.md index b7fdb556d1..3be51963c3 100644 --- a/patterns-modules/design-patterns-creational-2/README.md +++ b/patterns-modules/design-patterns-creational-2/README.md @@ -1,3 +1,4 @@ ## Relevant Articles - [The Factory Design Pattern in Java](https://www.baeldung.com/java-factory-pattern) - [Drawbacks of the Singleton Design Pattern](https://www.baeldung.com/java-patterns-singleton-cons) +- [Builder Pattern and Inheritance](https://www.baeldung.com/java-builder-pattern-inheritance) diff --git a/persistence-modules/java-calcite/README.md b/persistence-modules/java-calcite/README.md new file mode 100644 index 0000000000..4f0c24a09c --- /dev/null +++ b/persistence-modules/java-calcite/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Introduction to Apache Calcite](https://www.baeldung.com/apache-calcite) diff --git a/persistence-modules/spring-boot-persistence-4/README.md b/persistence-modules/spring-boot-persistence-4/README.md index bb2da31d9c..ab69839542 100644 --- a/persistence-modules/spring-boot-persistence-4/README.md +++ b/persistence-modules/spring-boot-persistence-4/README.md @@ -1,2 +1,3 @@ ## Relevant Articles - [Scroll API in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-scroll-api) +- [List vs. Set in @OneToMany JPA](https://www.baeldung.com/spring-jpa-onetomany-list-vs-set) diff --git a/persistence-modules/spring-data-jpa-repo-3/README.md b/persistence-modules/spring-data-jpa-repo-3/README.md index 623ac66bb3..03b0e7f76b 100644 --- a/persistence-modules/spring-data-jpa-repo-3/README.md +++ b/persistence-modules/spring-data-jpa-repo-3/README.md @@ -8,4 +8,5 @@ This module contains articles about Spring Data JPA. - [Hibernate Natural IDs in Spring Boot](https://www.baeldung.com/spring-boot-hibernate-natural-ids) - [Correct Use of flush() in JPA](https://www.baeldung.com/spring-jpa-flush) - [Difference Between findBy and findOneBy in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-findby-vs-findoneby) +- [How to Get Last Record in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-last-record) - More articles: [[<-- prev]](../spring-data-jpa-repo-2) diff --git a/persistence-modules/spring-data-jpa-repo-4/pom.xml b/persistence-modules/spring-data-jpa-repo-4/pom.xml index c823391d9f..9b03f7fdfb 100644 --- a/persistence-modules/spring-data-jpa-repo-4/pom.xml +++ b/persistence-modules/spring-data-jpa-repo-4/pom.xml @@ -30,6 +30,11 @@ org.springframework.boot spring-boot-starter-data-jpa + + io.hypersistence + hypersistence-utils-hibernate-55 + ${hypersistance-utils-hibernate-55.version} + com.h2database h2 @@ -47,6 +52,30 @@ guava ${guava.version} + + org.projectlombok + lombok + + + org.postgresql + postgresql + ${postgresql.version} + + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + ch.qos.logback + logback-core + ${logback.version} + + + ch.qos.logback + logback-classic + ${logback.version} + @@ -98,4 +127,9 @@ + + 3.7.0 + 42.7.1 + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/Address.java b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/Address.java new file mode 100644 index 0000000000..976a232082 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/Address.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.data.persistence.json; + +import lombok.*; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode +public class Address { + + private String postCode; + + private String city; + +} diff --git a/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/AddressAttributeConverter.java b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/AddressAttributeConverter.java new file mode 100644 index 0000000000..736f5e8ec2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/AddressAttributeConverter.java @@ -0,0 +1,36 @@ +package com.baeldung.spring.data.persistence.json; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +@Converter +@Slf4j +public class AddressAttributeConverter implements AttributeConverter { + + private static final ObjectMapper objectMapper = new ObjectMapper(); + + @Override + public String convertToDatabaseColumn(Address address) { + try { + return objectMapper.writeValueAsString(address); + } catch (JsonProcessingException jpe) { + log.warn("Cannot convert Address into JSON"); + return null; + } + } + + @Override + public Address convertToEntityAttribute(String value) { + try { + return objectMapper.readValue(value, Address.class); + } catch (JsonProcessingException e) { + log.warn("Cannot convert JSON into Address"); + return null; + } + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/JsonAttributeApplication.java b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/JsonAttributeApplication.java new file mode 100644 index 0000000000..708b43a534 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/JsonAttributeApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.spring.data.persistence.json; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class JsonAttributeApplication { + + public static void main(String[] args) { + SpringApplication.run(JsonAttributeApplication.class, args); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentEntity.java b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentEntity.java new file mode 100644 index 0000000000..c5fd31ddd3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentEntity.java @@ -0,0 +1,31 @@ +package com.baeldung.spring.data.persistence.json; + +import javax.persistence.*; + +import io.hypersistence.utils.hibernate.type.json.JsonBinaryType; +import lombok.*; +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; + +@Entity +@Table(name = "student") +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(of = {"id"}) +@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class) +public class StudentEntity { + + @Id + @Column(name = "student_id", length = 8) + private String id; + + @Column(name = "admit_year", length = 4) + private String admitYear; + + @Type(type = "jsonb") + @Column(name = "address", columnDefinition = "jsonb") + private Address address; + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentRepository.java b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentRepository.java new file mode 100644 index 0000000000..bae8ab6ad9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentRepository.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.data.persistence.json; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface StudentRepository extends CrudRepository { + + @Query(value = "SELECT * FROM student WHERE address->>'postCode' = :postCode", nativeQuery = true) + List findByAddressPostCode(@Param("postCode") String postCode); + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentStrEntity.java b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentStrEntity.java new file mode 100644 index 0000000000..552cdeaed6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentStrEntity.java @@ -0,0 +1,27 @@ +package com.baeldung.spring.data.persistence.json; + +import javax.persistence.*; + +import lombok.*; + +@Entity +@Table(name = "student_str") +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(of = {"id"}) +public class StudentStrEntity { + + @Id + @Column(name = "student_id", length = 8) + private String id; + + @Column(name = "admit_year", length = 4) + private String admitYear; + + @Convert(converter = AddressAttributeConverter.class) + @Column(name = "address", length = 500) + private Address address; + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentStrRepository.java b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentStrRepository.java new file mode 100644 index 0000000000..ce40166b22 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-4/src/main/java/com/baeldung/spring/data/persistence/json/StudentStrRepository.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.data.persistence.json; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface StudentStrRepository extends CrudRepository { + + @Query(value = "SELECT * FROM student WHERE address->>'postCode' = :postCode", nativeQuery = true) + List findByAddressPostCode(@Param("postCode") String postCode); + +} diff --git a/persistence-modules/spring-data-jpa-repo-4/src/test/java/com/baeldung/spring/data/persistence/json/JsonAttributeLiveTest.java b/persistence-modules/spring-data-jpa-repo-4/src/test/java/com/baeldung/spring/data/persistence/json/JsonAttributeLiveTest.java new file mode 100644 index 0000000000..1242b3f2f4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-4/src/test/java/com/baeldung/spring/data/persistence/json/JsonAttributeLiveTest.java @@ -0,0 +1,76 @@ +package com.baeldung.spring.data.persistence.json; + +import org.junit.jupiter.api.*; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.inject.Inject; +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = JsonAttributeApplication.class) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class JsonAttributeLiveTest { + + @Inject + private StudentStrRepository studentStrRepository; + + @Inject + private StudentRepository studentRepository; + + @Test + @Order(10) + void whenSaveAnStudentStrEntityAndFindById_thenTheRecordPresentsInDb() { + String studentId = "23876371"; + String postCode = "KT6 7BB"; + + Address address = new Address(postCode, "London"); + StudentStrEntity studentStrEntity = StudentStrEntity.builder() + .id(studentId) + .admitYear("2023") + .address(address) + .build(); + + StudentStrEntity savedStudentStrEntity = studentStrRepository.save(studentStrEntity); + + Optional studentEntityOptional = studentStrRepository.findById(studentId); + assertThat(studentEntityOptional.isPresent()).isTrue(); + + studentStrEntity = studentEntityOptional.get(); + assertThat(studentStrEntity.getId()).isEqualTo(studentId); + assertThat(studentStrEntity.getAddress().getPostCode()).isEqualTo(postCode); + } + + @Test + @Order(20) + void whenSaveAnStudentEntityAndFindById_thenTheRecordPresentsInDb() { + String studentId = "23876371"; + String postCode = "KT6 7BB"; + + Address address = new Address(postCode, "London"); + StudentEntity studentEntity = StudentEntity.builder() + .id(studentId) + .admitYear("2023") + .address(address) + .build(); + + StudentEntity savedStudentEntity = studentRepository.save(studentEntity); + + Optional studentEntityOptional = studentRepository.findById(studentId); + assertThat(studentEntityOptional.isPresent()).isTrue(); + + studentEntity = studentEntityOptional.get(); + assertThat(studentEntity.getId()).isEqualTo(studentId); + assertThat(studentEntity.getAddress().getPostCode()).isEqualTo(postCode); + } + + @Test + @Order(50) + void whenFindByAddressPostCode_thenReturnListIsNotEmpty() { + String postCode = "KT6 7BB"; + List studentStrEntityList = studentStrRepository.findByAddressPostCode(postCode); + assertThat(studentStrEntityList).isNotEmpty(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-jdbc/README.md b/persistence-modules/spring-jdbc/README.md index 19f8537a4e..de2153088f 100644 --- a/persistence-modules/spring-jdbc/README.md +++ b/persistence-modules/spring-jdbc/README.md @@ -7,4 +7,4 @@ - [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys) - [Spring JDBC Batch Inserts](https://www.baeldung.com/spring-jdbc-batch-inserts) - [Fix EmptyResultDataAccessException When Using JdbcTemplate](https://www.baeldung.com/jdbctemplate-fix-emptyresultdataaccessexception) -- [How to replace deprecated jdbcTemplate.queryForObject and jdbcTemplate.query in spring boot 2.4.X and above](https://www.baeldung.com/spring-boot-replace-deprecated-jdbctemplate-queryforobject-query) +- [How to Replace Deprecated jdbcTemplate.queryForObject and jdbcTemplate.query in Spring Boot 2.4.X and above](https://www.baeldung.com/spring-boot-replace-deprecated-jdbctemplate-queryforobject-query) diff --git a/pom.xml b/pom.xml index a73d508d89..f54e755e69 100644 --- a/pom.xml +++ b/pom.xml @@ -465,10 +465,10 @@ parent-spring-4 parent-spring-5 parent-spring-6 - - apache-spark + apache-spark jhipster-modules + web-modules/restx @@ -615,10 +615,10 @@ parent-spring-4 parent-spring-5 parent-spring-6 - - apache-spark + apache-spark jhipster-modules + web-modules/restx diff --git a/quarkus-modules/quarkus-vs-springboot/pom.xml b/quarkus-modules/quarkus-vs-springboot/pom.xml index 4ec10f385d..2e9d0b8a7f 100644 --- a/quarkus-modules/quarkus-vs-springboot/pom.xml +++ b/quarkus-modules/quarkus-vs-springboot/pom.xml @@ -16,7 +16,7 @@ quarkus-project - + spring-project \ No newline at end of file diff --git a/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml b/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml index c3ee41223f..cbca49a633 100644 --- a/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml +++ b/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml @@ -103,9 +103,10 @@ org.apache.maven.plugins maven-compiler-plugin + 3.12.1 - ${maven.compiler.source.version} - ${maven.compiler.target.version} + ${maven.compiler.release} + ${maven.compiler.release} @@ -117,16 +118,30 @@ Spring release https://repo.spring.io/release + + spring-milestone + Spring Milestone + https://repo.spring.io/milestone + + + spring-snapshot + Spring Snapshot + https://repo.spring.io/snapshot + + - spring-release - Spring release - https://repo.spring.io/release + spring-milestone + Spring milestone + https://repo.spring.io/milestone + + + native @@ -158,6 +173,7 @@ org.springframework.experimental spring-aot-maven-plugin + ${spring-native.version} test-generate @@ -194,6 +210,7 @@ org.springframework.experimental spring-aot-maven-plugin + ${spring-native.version} test-generate @@ -257,6 +274,7 @@ 3.1.0 0.9.11 2.0.8 + 17 \ No newline at end of file diff --git a/spring-6/api-gateway/README.md b/spring-6/api-gateway/README.md new file mode 100644 index 0000000000..d0d8cbb8a2 --- /dev/null +++ b/spring-6/api-gateway/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Global Exception Handling with Spring Cloud Gateway](https://www.baeldung.com/spring-cloud-global-exception-handling) diff --git a/spring-boot-modules/spring-boot-3-grpc/README.md b/spring-boot-modules/spring-boot-3-grpc/README.md new file mode 100644 index 0000000000..2aaf35bf20 --- /dev/null +++ b/spring-boot-modules/spring-boot-3-grpc/README.md @@ -0,0 +1,2 @@ +### Relevant Articles +- [Introduction to gRPC with Spring Boot](https://www.baeldung.com/spring-boot-grpc) diff --git a/spring-boot-modules/spring-boot-3-observation/README.md b/spring-boot-modules/spring-boot-3-observation/README.md index 6d8c02af67..ae812d5f56 100644 --- a/spring-boot-modules/spring-boot-3-observation/README.md +++ b/spring-boot-modules/spring-boot-3-observation/README.md @@ -1,3 +1,3 @@ ## Relevant Articles -- [Observability with Spring Boot 3](https://www.baeldung.com/spring-boot-3-observability) +- [Observability With Spring Boot 3](https://www.baeldung.com/spring-boot-3-observability) - [Intercept SQL Logging with P6Spy](https://www.baeldung.com/java-p6spy-intercept-sql-logging) diff --git a/spring-boot-modules/spring-boot-libraries-3/README.md b/spring-boot-modules/spring-boot-libraries-3/README.md index 1458e3ef39..7d9fd87ad5 100644 --- a/spring-boot-modules/spring-boot-libraries-3/README.md +++ b/spring-boot-modules/spring-boot-libraries-3/README.md @@ -2,4 +2,5 @@ This module contains articles about various Spring Boot libraries -### Relevant Articles: \ No newline at end of file +### Relevant Articles: +- [Event Externalization with Spring Modulith](https://www.baeldung.com/spring-modulith-event-externalization) diff --git a/spring-boot-modules/spring-boot-testing-spock/README.md b/spring-boot-modules/spring-boot-testing-spock/README.md index ab8193ab4e..ac37403a2a 100644 --- a/spring-boot-modules/spring-boot-testing-spock/README.md +++ b/spring-boot-modules/spring-boot-testing-spock/README.md @@ -5,3 +5,4 @@ This module contains articles about Spring Boot testing with Spock framework ### Relevant Articles: - [Testing with Spring and Spock](https://www.baeldung.com/spring-spock-testing) +- [Setting up and Using Spock With Gradle](https://www.baeldung.com/groovy/spock-gradle-setup) diff --git a/spring-cloud-modules/spring-cloud-aws-v3/README.md b/spring-cloud-modules/spring-cloud-aws-v3/README.md index d63b0eaa5d..d42883b1f7 100644 --- a/spring-cloud-modules/spring-cloud-aws-v3/README.md +++ b/spring-cloud-modules/spring-cloud-aws-v3/README.md @@ -1,3 +1,4 @@ # Spring Cloud AWS -TBD \ No newline at end of file +### Relevant Articles: +- [Introduction to Spring Cloud AWS 3.0 – SQS Integration](https://www.baeldung.com/java-spring-cloud-aws-v3-intro) diff --git a/spring-kafka-3/README.md b/spring-kafka-3/README.md index f9c0036ce3..5250070952 100644 --- a/spring-kafka-3/README.md +++ b/spring-kafka-3/README.md @@ -1,2 +1,3 @@ ## Relevant Articles - [Spring Kafka Trusted Packages Feature](https://www.baeldung.com/spring-kafka-trusted-packages-feature) +- [How to Catch Deserialization Errors in Spring-Kafka?](https://www.baeldung.com/spring-kafka-deserialization-errors) diff --git a/spring-reactive-modules/spring-reactive-2/README.md b/spring-reactive-modules/spring-reactive-2/README.md index dbaebc370e..c635d4c9b5 100644 --- a/spring-reactive-modules/spring-reactive-2/README.md +++ b/spring-reactive-modules/spring-reactive-2/README.md @@ -2,7 +2,7 @@ This module contains articles about reactive Spring Boot. -- [Validation for Functional Endpoints in Spring 5](https://www.baeldung.com/spring-functional-endpoints-validation) +- [Validation for Functional Endpoints in Spring 6](https://www.baeldung.com/spring-functional-endpoints-validation) - [Testing Reactive Streams Using StepVerifier and TestPublisher](https://www.baeldung.com/reactive-streams-step-verifier-test-publisher) - [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content) - [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events) diff --git a/spring-security-modules/spring-security-web-thymeleaf/pom.xml b/spring-security-modules/spring-security-web-thymeleaf/pom.xml index dd5f2d7c97..2c8764b88a 100644 --- a/spring-security-modules/spring-security-web-thymeleaf/pom.xml +++ b/spring-security-modules/spring-security-web-thymeleaf/pom.xml @@ -11,7 +11,8 @@ com.baeldung - spring-security-modules + parent-boot-3 + ../../parent-boot-3 0.0.1-SNAPSHOT @@ -40,8 +41,12 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity6 + + com.baeldung.springsecuritythymeleaf.SpringSecurityThymeleafApplication + + \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/CustomUserDetailsService.java b/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/CustomUserDetailsService.java index e84f9eac55..2382630e62 100644 --- a/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/CustomUserDetailsService.java +++ b/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/CustomUserDetailsService.java @@ -7,7 +7,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import java.util.Collections; import java.util.HashMap; diff --git a/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/SecurityConfiguration.java b/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/SecurityConfiguration.java index d438aefcdc..cd8eec18aa 100644 --- a/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/SecurityConfiguration.java +++ b/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/customuserdetails/SecurityConfiguration.java @@ -21,19 +21,14 @@ public class SecurityConfiguration { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.userDetailsService(userDetailsService) - .authorizeRequests() - .anyRequest() - .authenticated() - .and() - .formLogin() - .loginPage("/login") - .permitAll() - .defaultSuccessUrl("/index") - .and() - .logout() - .permitAll() - .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) - .logoutSuccessUrl("/login"); + .authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> authorizationManagerRequestMatcherRegistry + .anyRequest().authenticated()) + .formLogin(httpSecurityFormLoginConfigurer -> httpSecurityFormLoginConfigurer + .loginPage("/login").permitAll() + .defaultSuccessUrl("/index")) + .logout(httpSecurityLogoutConfigurer -> httpSecurityLogoutConfigurer.permitAll() + .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) + .logoutSuccessUrl("/login")); return http.build(); } } diff --git a/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java b/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java index b0478ed01c..c270635363 100644 --- a/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java +++ b/spring-security-modules/spring-security-web-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java @@ -16,19 +16,13 @@ public class SecurityConfiguration { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http.authorizeRequests() - .anyRequest() - .authenticated() - .and() - .formLogin() - .loginPage("/login") - .permitAll() - .successForwardUrl("/index") - .and() - .logout() - .permitAll() - .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) - .logoutSuccessUrl("/login"); + http.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> + authorizationManagerRequestMatcherRegistry.anyRequest().authenticated()) + .formLogin(httpSecurityFormLoginConfigurer -> + httpSecurityFormLoginConfigurer.loginPage("/login").permitAll().successForwardUrl("/index")) + .logout(httpSecurityLogoutConfigurer -> httpSecurityLogoutConfigurer.permitAll() + .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) + .logoutSuccessUrl("/login")); return http.build(); } diff --git a/spring-web-modules/spring-mvc-basics-5/README.md b/spring-web-modules/spring-mvc-basics-5/README.md index ec91449b0f..d503b9e78e 100644 --- a/spring-web-modules/spring-mvc-basics-5/README.md +++ b/spring-web-modules/spring-mvc-basics-5/README.md @@ -14,4 +14,5 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring - [Spring @RequestParam vs @PathVariable Annotations](https://www.baeldung.com/spring-requestparam-vs-pathvariable) - [@RequestMapping Value in Properties File](https://www.baeldung.com/spring-requestmapping-properties-file) - [Map a JSON POST to Multiple Spring MVC Parameters](https://www.baeldung.com/spring-mvc-json-param-mapping) +- [Getting Query String Parameters from HttpServletRequest](https://www.baeldung.com/java-httpservletrequest-get-query-parameters) - More articles: [[<-- prev]](../spring-mvc-basics-4) diff --git a/spring-web-modules/spring-rest-http/README.md b/spring-web-modules/spring-rest-http/README.md index 4c160ee513..04aed3d076 100644 --- a/spring-web-modules/spring-rest-http/README.md +++ b/spring-web-modules/spring-rest-http/README.md @@ -7,7 +7,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header) +- [How to Set a Header on a Response with Spring 6](https://www.baeldung.com/spring-response-header) - [Returning Custom Status Codes from Spring Controllers](https://www.baeldung.com/spring-mvc-controller-custom-http-status-code) - [Spring RequestMapping](https://www.baeldung.com/spring-requestmapping) - [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result) diff --git a/spring-web-modules/spring-thymeleaf-5/README.md b/spring-web-modules/spring-thymeleaf-5/README.md index 7b64a4e423..dcf5dd91b3 100644 --- a/spring-web-modules/spring-thymeleaf-5/README.md +++ b/spring-web-modules/spring-thymeleaf-5/README.md @@ -7,4 +7,5 @@ This module contains articles about Spring with Thymeleaf - [Conditionals in Thymeleaf](https://www.baeldung.com/spring-thymeleaf-conditionals) - [Iteration in Thymeleaf](https://www.baeldung.com/thymeleaf-iteration) - [Spring with Thymeleaf Pagination for a List](https://www.baeldung.com/spring-thymeleaf-pagination) +- [Display Image With Thymeleaf](https://www.baeldung.com/spring-thymeleaf-image) - More articles: [[<-- prev]](../spring-thymeleaf-4) diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/controller/PetController.java b/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/controller/PetController.java new file mode 100644 index 0000000000..c2071ac9c7 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-5/src/main/java/com/baeldung/thymeleaf/controller/PetController.java @@ -0,0 +1,13 @@ +package com.baeldung.thymeleaf.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class PetController { + + @RequestMapping("/") + public String home() { + return "index"; + } +} diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/resources/static/cat.jpg b/spring-web-modules/spring-thymeleaf-5/src/main/resources/static/cat.jpg new file mode 100644 index 0000000000..cd92bb4a16 Binary files /dev/null and b/spring-web-modules/spring-thymeleaf-5/src/main/resources/static/cat.jpg differ diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/resources/static/images/cat.jpg b/spring-web-modules/spring-thymeleaf-5/src/main/resources/static/images/cat.jpg new file mode 100644 index 0000000000..cd92bb4a16 Binary files /dev/null and b/spring-web-modules/spring-thymeleaf-5/src/main/resources/static/images/cat.jpg differ diff --git a/spring-web-modules/spring-thymeleaf-5/src/main/resources/template/index.html b/spring-web-modules/spring-thymeleaf-5/src/main/resources/template/index.html new file mode 100644 index 0000000000..7e045e9769 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-5/src/main/resources/template/index.html @@ -0,0 +1,13 @@ + + + + + Baeldung Pet Store + + +

Welcome Image

+
Pet Store
+ cat + cat + + \ No newline at end of file diff --git a/testing-modules/groovy-spock/README.md b/testing-modules/groovy-spock/README.md index e61c56d470..14c4b145f9 100644 --- a/testing-modules/groovy-spock/README.md +++ b/testing-modules/groovy-spock/README.md @@ -3,3 +3,4 @@ - [Introduction to Testing with Spock and Groovy](http://www.baeldung.com/groovy-spock) - [Difference Between Stub, Mock, and Spy in the Spock Framework](https://www.baeldung.com/spock-stub-mock-spy) - [Guide to Spock Extensions](https://www.baeldung.com/spock-extensions) +- [Improving Test Coverage and Readability With Spock’s Data Pipes and Tables](https://www.baeldung.com/java-spock-improve-test-coverage-data-feeds-tables) diff --git a/testing-modules/jmeter/pom.xml b/testing-modules/jmeter/pom.xml index 67a21f6c86..868023e762 100644 --- a/testing-modules/jmeter/pom.xml +++ b/testing-modules/jmeter/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 @@ -156,14 +156,11 @@
- - - 3.7.0 - + com.baeldung.dashboard.DashboardApplication 3.7.0 diff --git a/testing-modules/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java b/testing-modules/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java index 033281e07f..1893389fae 100644 --- a/testing-modules/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java +++ b/testing-modules/jmeter/src/main/java/com/baeldung/configuration/WebSecurityConfiguration.java @@ -1,5 +1,7 @@ package com.baeldung.configuration; +import static org.springframework.security.config.Customizer.withDefaults; + import java.util.HashSet; import java.util.Set; @@ -12,6 +14,7 @@ import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration public class WebSecurityConfiguration { @@ -30,15 +33,17 @@ public class WebSecurityConfiguration { } @Bean - public SecurityFilterChain securityFilter(HttpSecurity http) throws Exception { - + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http - .authorizeRequests() - .antMatchers("/secured/**").authenticated() - .anyRequest().permitAll() - .and() - .httpBasic(); + .authorizeHttpRequests(authorizeRequests -> + authorizeRequests + .requestMatchers(new AntPathRequestMatcher("/secured/**")) + .authenticated() + .anyRequest().permitAll() + ) + .httpBasic(withDefaults()); return http.build(); + } } diff --git a/testing-modules/jmeter/src/main/java/com/baeldung/domain/Student.java b/testing-modules/jmeter/src/main/java/com/baeldung/domain/Student.java index 0f6150fc48..942a43b215 100644 --- a/testing-modules/jmeter/src/main/java/com/baeldung/domain/Student.java +++ b/testing-modules/jmeter/src/main/java/com/baeldung/domain/Student.java @@ -1,6 +1,6 @@ package com.baeldung.domain; -import javax.validation.constraints.NotNull; +import jakarta.validation.constraints.NotNull; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; diff --git a/web-modules/pom.xml b/web-modules/pom.xml index 6119316a62..a23bc9a7a6 100644 --- a/web-modules/pom.xml +++ b/web-modules/pom.xml @@ -35,7 +35,6 @@ ratpack resteasy - restx rome spark-java struts-2 diff --git a/web-modules/restx/pom.xml b/web-modules/restx/pom.xml index 58877ca72c..f0b4bace48 100644 --- a/web-modules/restx/pom.xml +++ b/web-modules/restx/pom.xml @@ -9,9 +9,10 @@ war + parent-modules com.baeldung - web-modules 1.0.0-SNAPSHOT + ../../