<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Otavio Santana on Medium]]></title>
        <description><![CDATA[Stories by Otavio Santana on Medium]]></description>
        <link>https://medium.com/@otaviojava?source=rss-951be51d886c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*i7FxzKkAnbdZEx2I</url>
            <title>Stories by Otavio Santana on Medium</title>
            <link>https://medium.com/@otaviojava?source=rss-951be51d886c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 16:58:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@otaviojava/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Learn to Access Java Database With Jakarta Data]]></title>
            <link>https://medium.com/xgeeks/learn-to-access-java-database-with-jakarta-data-17fc3e2549b0?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/17fc3e2549b0</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[jakarta]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[rest]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Mon, 21 Feb 2022 20:15:23 GMT</pubDate>
            <atom:updated>2022-02-22T13:06:17.454Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qf1XNXkcceq8kxc1yZJ07A.png" /></figure><p><strong>In this article, we discuss the existing standards for databases in the Java world and the new Jakarta Data proposal, which aims to make life easier for developers.</strong></p><p>Dealing with a database is one of the biggest challenges within a software architecture. In addition to choosing one of several options on the market, it is necessary to consider the persistence integrations. The purpose of this article is to show some of these patterns and learn about a new specification proposal, Jakarta Data, which aims to make life easier for developers with Java.</p><h3>Understanding the Layers That Can Make Up Software</h3><p>Whenever we talk about complexity in a corporate system, we focus on the ancient Roman military strategy: divide and conquer or <em>divide et impera</em>. To simplify the whole, we break it down into small units.</p><p>In the software world, one of the ways to simplify and break down complexity is through layers, whether physical or logical. These layers, mainly the logic ones, can be fragmented, becoming components and functionalities.</p><p>This breaking layer movement is one of the themes in the book “Clean Architecture” when mentioning, for example, the strategy of separating the business code from the infrastructure code.</p><h3>The Three Types of Layers in an Application</h3><p>According to the <a href="https://www.oreilly.com/library/view/learning-domain-driven-design/9781098100124/">“Learning Domain-Driven Design” book</a>, regardless of the architectural style that you are working with, such as monolith or microservices, there is a minimum number of three types of layers in an application. They are the:</p><ol><li>Presentation layer: It is the layer of interaction with the user consuming this resource, whether an end-user or someone who works in software engineering.</li><li>Business logic layer: As its name suggests, this is where the business logic will be, or in the words of Eric Evans, “<a href="https://www.amazon.com/dp/0321125215">it is the layer that finds the heart of the business</a>.”</li><li>Data access layer: This layer holds the entire persistence mechanism. In the context of Stateless architecture, we can think that it is the place with some state guarantee, noting that the storage mechanism is transparent, be it a NoSQL database, SQL, a Rest API, etc.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*v5Fcc2FV6V9R1iIs.png" /></figure><p>These three types of layers tend to be present in various software architecture styles, from simple ones, such as MVC, to more complex ones, such as CQRS, hexagonal model, onion, among others.</p><p>In addition to the three types of layers, the architectural models are very concerned with the communication between these components to ensure high cohesion and low coupling, and they follow the Dependency Inversion Principle, the DIP.</p><p>This isolation of the data access layer mainly ensures that the database paradigm “leaks” into the business model. We know a big difference — also known as impedance — especially between relational databases and object-oriented programming.</p><h3>Persistence Layer</h3><p>After the proper introduction about layers and their importance, we will focus on the persistence layer or database. A point of criticism and admiration within the object-oriented paradigm is a wide range of options and standards for communication.</p><p>For this article, we will talk about some patterns taking into account the single responsibility principle and the coupling with the business and database layer.</p><p>It is worth noting that there is no “silver bullet” solution, so it is essential to pay attention to which context this pattern will be used.</p><h3>Pattern Types When It Comes to Database</h3><p>Of course, we have several integration models and patterns between the database and OOP. This article focuses on the following:</p><ul><li>Pattern 1: Data-oriented programming</li><li>Pattern 2: Active record</li><li>Pattern 3: Mapper</li></ul><p>Next, let’s look at these patterns in detail.</p><h3>Pattern 1: Data-Oriented Programming</h3><p>In his book <a href="https://www.manning.com/books/data-oriented-programming">“Data-Oriented Programming”</a>, author Yehonathan Sharvit proposes reducing complexity by promoting and treating data as a “first-class citizen.”</p><p>This pattern summarizes three principles:</p><ol><li>The code is data separated.</li><li>Data is immutable.</li><li>Data has flexible access.</li></ol><p>This proposal eliminates the entity layer, focusing explicitly on data dictionaries through, for example, an implementation of Map.</p><h3>Pattern 2: Active Record</h3><p>After Martin Follower’s book <a href="https://www.amazon.com/dp/0321127420">“Patterns of Enterprise Application Architecture,”</a> this pattern became quite popular.</p><p>In short, the pattern has a single object, which is responsible for both the data and the behavior. It allows simplifying business rules since the idea is that there is direct access to data.</p><p>However, in the case of more complex architectures, active record tends to become quite challenging to deal with. We add a high coupling between the database solution, not to mention the break of single responsibility. In addition to being responsible for business rules, the same class is also responsible for database operations.</p><p>The most recent and widely used solution is <a href="https://quarkus.io/">Quarkus’s</a> <a href="https://quarkus.io/guides/hibernate-orm-panache#solution-1-using-the-active-record-pattern">Panache</a> within the Java world. This way, it is possible to make an application with microservices with only two classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3909642dd8040e801415d750ef0003a6/href">https://medium.com/media/3909642dd8040e801415d750ef0003a6/href</a></iframe><h3>Pattern 3: Mapper</h3><p>Another database communication solution that meets the previous premise is mapper. Generally speaking, it leaves entity and database operations separate. What, at most, tends to appear within classes is the metadata or annotations of the Java world.</p><p>This standard ensures greater separation between the business layer and the database, and it guarantees the single-responsibility principle. We simplify maintenance and reading in applications, as we have a class for the entity and another for database operations.</p><p>However, for simple projects, Mapper tends to be unfeasible. It is the case, for example, of straightforward applications with CRUD that, depending on the style, will need three or four classes to achieve the same objective, unlike standards such as active record, which would perform this function with half the number of objects.</p><p>The most common example, of course, is the ORM <a href="https://hibernate.org/">Hibernate</a>. However, this type of solution is not exclusive to relational databases, as there are solutions for NoSQL such as Spring Data and Jakarta NoSQL.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c70138cef37ddcdebef7c18352af77bc/href">https://medium.com/media/c70138cef37ddcdebef7c18352af77bc/href</a></iframe><h3>DAO vs. Repository</h3><p>From a mapper, it is possible to think of two more patterns. They are:</p><ol><li>DAO (Data Access Object)</li><li>Repository</li></ol><p>These patterns consider the decoupling between the model and the persistence layer, but the similarity ends there.</p><p>The differences are in the coupling as it is linked to the data access layer, and not to the model, in addition to the focus on the service layers, semantics, and nomenclature. Let’s better understand these models separately.</p><h4>Data Access Object (DAO)</h4><p>The data access object (DAO) standard isolates the application and business layers from persistence through an abstraction API. This API, in turn, bears a close resemblance to the database engine.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7420e29cf9c48b0679fde31353a62fa3/href">https://medium.com/media/7420e29cf9c48b0679fde31353a62fa3/href</a></iframe><h4>Repository</h4><p>The repository pattern is a mechanism that allows you to encapsulate storage, retrieval, and search behavior by emulating a collection of objects. In this way, the design further hides the relationship of the persistence mechanism.</p><p>This pattern focuses on the closest proximity of entities and hides where the data comes from, making it possible for a Repository to use a DAO pattern itself.</p><h4>Summarizing DAO x Repository</h4><p>The important point is the semantics. Let’s take an example: consider that a Car entity would have Garage as a class, representing the collection of entities. The result would be the following code snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5377770a7beebe20174945fb552f8df5/href">https://medium.com/media/5377770a7beebe20174945fb552f8df5/href</a></iframe><p>In short, if we compare the two types of pattern inside mapper:</p><ul><li>DAO focuses on an abstraction for accessing some kind of data.</li><li>The repository focuses on a collection, regardless of the object’s origin. For this reason, a repository can use a DAO to achieve its goal.</li></ul><h3>A New API Proposal for Data Access Is Born: Jakarta Data</h3><p>After knowing all the patterns, and their respective importance and trade-offs, it is essential to take one more step: to see an API that better explores these patterns and, thus, facilitates the adoption of good practices with Java and data resources.</p><p>The proposal for a new specification called Jakarta Data is born. Jakarta Data is premised on three principles:</p><ol><li>An easy and declarative API</li><li>A cohesion in this layer</li><li>A decoupling of the other layers</li></ol><p>Still, in its first version, the focus of this new proposal is on delivering the repository pattern so that, with just one interface and a few annotations, it is possible to implement Jakarta Data, initially, in three projects:</p><p>Relational with JPA, NoSQL with Jakarta NoSQL, and REST with REST Client for MicroProfile.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/721b10c4622a585ba929a4c6408095ef/href">https://medium.com/media/721b10c4622a585ba929a4c6408095ef/href</a></iframe><p>In summary, from Jakarta Data, it is easier to deal with the business layer both in terms of polyglot persistence and its decoupling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cRd36pEZsKx1jK3y.png" /></figure><h3>Jakarta Data: More Ease and Integration</h3><p>Overall, we always take into account the degree of insulation of the other layers and their ease of use and maintenance. From this scenario, Jakarta Data was born, whose objective is to help use these patterns in a simple and integrated way to the world of Java specification. And, by default, the expectation is full support from the community and providing help and feedback.</p><p><strong>If you enjoy working at a large scale in projects with global impact and if you like a real challenge, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team, and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at xgeeks! See you soon!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17fc3e2549b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/learn-to-access-java-database-with-jakarta-data-17fc3e2549b0">Learn to Access Java Database With Jakarta Data</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Readable Code With Dependency Injection and Jakarta CDI]]></title>
            <link>https://medium.com/xgeeks/making-readable-code-with-dependency-injection-and-jakarta-cdi-ae82d0565a0?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae82d0565a0</guid>
            <category><![CDATA[xgeeks]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[jakarta-ee]]></category>
            <category><![CDATA[jakarta]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Mon, 24 Jan 2022 11:27:57 GMT</pubDate>
            <atom:updated>2022-01-24T11:27:57.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*vkINH-8z_oof2F7rJvuSaQ.jpeg" /></figure><h4>Learn more about dependency injection with Jakarta CDI and enhance the effectiveness and readability of your code.</h4><p>Within programming, object orientation (also known as OOP) is one of the wealthiest paradigms in documentation and standards, as with dependency injection. However, the most common is that these standards are misinterpreted and implemented and what would allow a clear vision and a good design for a cooperative application, in practice, harms the quality and efficiency of your code.</p><p>In this article, I will bring the advantages of exploring object orientation, more specifically dependency injection, together with the specification of the Java world that covers this API: the Jakarta CDI.</p><h3>What Is Dependency Injection?</h3><p>The first step is to contextualize what dependency injection is and why it differs from inversion of controls, although the two concepts are very confused.</p><p>In the context of OOP (Object Orientation), dependency is related to any direct subordination of a class, and that can be done in several ways. For example, through constructors, accessor methods, such as setters, or creation methods, such as the <a href="https://refactoring.guru/design-patterns/factory-method">Factory Method</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26d0211bd741feff83dae4dfaa61d566/href">https://medium.com/media/26d0211bd741feff83dae4dfaa61d566/href</a></iframe><p>This example injection also can measure how much one class is linked to another, which we call coupling. It is vital because it is part of the job of good code design to be concerned with <a href="https://www.baeldung.com/cs/cohesion-vs-coupling">high cohesion and low coupling</a>.</p><h3>The Difference Between Dependency Injection and Inversion</h3><p>Once the basic concepts of OOP are explained, the next step is to understand what differs between injection and dependency inversion.</p><p>This distinction happens because of what we call the <a href="https://en.wikipedia.org/wiki/Dependency_inversion_principle">DIP</a>, or Dependency Inversion Principle, which works as a guide to good practices focused on decoupling a class from concrete dependencies through two recommendations:</p><ol><li>High-level modules must not depend on low-level modules, but both must depend on abstractions (Example: interfaces).</li><li>Abstractions, in turn, should not depend on details. However, parties or concrete implementations must depend on abstractions.</li></ol><p>While inversion assumes all these requirements, <a href="https://www.martinfowler.com/articles/injection.html">dependency injection</a> is a DIP technique to supply a class’s dependencies, usually through a constructor, attribute, or a method such as a setter.</p><p>In short: dependency injection is part of the best practices advocated by inversion of control (IoC).</p><p>As tricky as these concepts are, at first, they are fundamental because they can be correlated to the <a href="https://en.wikipedia.org/wiki/Barbara_Liskov">Barbara Liskov</a> principle. After all, both the <a href="https://en.wikipedia.org/wiki/Liskov_substitution_principle">Liskov principle</a> and dependency injection are part of <a href="https://sites.google.com/site/unclebobconsultingllc/getting-a-solid-start">SOLID</a>.</p><h3>Where Does CDI Come in, and How Do We Get to Jakarta CDI?</h3><p>As with injection and inversion, it is crucial to take a step back and contextualize what CDI is.</p><p>The CDI (Dependency and Contexts Injection) arose from the need to create a specification within the <a href="https://jcp.org/en/jsr/detail?id=365">JCP, JSR 365</a>, mainly because, in the Java world and projects like Spring and Google Guice, there are several solutions and implementations of these frameworks.</p><p>Briefly, the purpose of Jakarta CDI is to allow the management of stateful or stateless component life control via context and <a href="https://www.baeldung.com/java-ee-cdi">component injection</a>.</p><p>It is a project in constant evolution. If you want to keep up with the latest updates, it’s worth knowing <a href="https://projects.eclipse.org/projects/ee4j.odi">Eclipse Open-DI</a>. It is currently being optimized to improve booting through <a href="https://github.com/eclipse-ee4j/cdi/issues/425">CDI Lite</a>.</p><h3>CDI in Practice</h3><p>To exemplify the features of CDI, we will create a simple Java SE application with CDI to show six essential elements within CDI, which are:</p><ol><li>Perform a single injection.</li><li>Differentiate implementations through qualifications.</li><li>Teach CDI to create and distribute objects.</li><li>Apply Observer.</li><li>Apply Decorator.</li><li>Use the interceptor.</li></ol><p>In this article, even to avoid making the text too big, we will highlight the codes. If you want, you can later <a href="https://github.com/otaviojava/payara-fastlane-demos/tree/main/cdi">access the code in full</a>.</p><p>It is nice to mention that this content was created with <a href="https://twitter.com/kvarel4">Karina Varela</a> and is part of the classes we took throughout 2021, mainly in American and European countries, in partnership with <a href="https://microstream.one/">Microstream</a> and <a href="https://www.payara.fish/">Payara</a>.</p><h3>Perform a Single Injection</h3><p>In our first implementation, we will create a “Vehicle” interface and an implementation using the Java SE container.</p><p>An important point: we have the context in addition to the injection of dependencies. We can <a href="https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0#contexts">define the life cycle of a class or bean</a>, and, in this case, the implementation will have the <a href="https://jakarta.ee/specifications/cdi/3.0/jakarta-cdi-spec-3.0#bean_defining_annotations">application scope</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6801752223752bea232ea44d8dcf5f3d/href">https://medium.com/media/6801752223752bea232ea44d8dcf5f3d/href</a></iframe><p>In this piece of code, we have the interface Vehicle and its respective implementation, Car, in which the CDI will be able to inject an instance both through the interface and through the implementation.</p><p>Since we are talking about best practices, please understand that we are using the case of a single interface for a single implementation for teaching purposes. In practice, ideally, you don’t do this so as not to break the <a href="https://en.wikipedia.org/wiki/KISS_principle">KISS principle</a>.</p><p>A good indicator for this is interfaces that start with “I” or implementations that end with “Impl”. In addition to being an indicator of unnecessary complexity, it is a <a href="https://refactoring.guru/refactoring/smells">code smell</a>. After all, it is not a meaningful name, breaking the principle of the <a href="https://www.amazon.com/dp/B001GSTOAM/">Clean Code</a>.</p><h3>Differentiate Implementations Through Qualifications</h3><p>In the previous example, we had the case of a one-to-one relationship, that is, an interface for a single implementation. But what happens when we have multiple implementations for the same interface?</p><p>If we don’t have this set, CDI won’t know the default implementation and will throw the <a href="https://jakarta.ee/specifications/platform/9/apidocs/jakarta/enterprise/inject/ambiguousresolutionexception">AmbiguousResolutionException</a>. You can solve this problem using the Named annotation or a Qualifier. In our case, we will use the Qualifiers.</p><p>Imagine the following scenario in which we have an orchestra with several musical instruments. This orchestra will need to play all the instruments together and be able to discriminate between them. In our example, this scenario would look something like the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecf32952275fe9ebb3ef3cb7f5daabbf/href">https://medium.com/media/ecf32952275fe9ebb3ef3cb7f5daabbf/href</a></iframe><p>We have the instrument interface, an enumerator to define its type, and the CDI Qualifier through a new annotation in this code example.</p><p>After the implementations and qualifiers, it will be pretty simple for the orchestra to play all the instruments together and special tools considering their different types, for example, string, percussion, or wood.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcb5d2e0eff4728c60265e3a0453a807/href">https://medium.com/media/dcb5d2e0eff4728c60265e3a0453a807/href</a></iframe><p>The CDI container injects an Orchestra instance and demonstrates the use of each instrument.</p><h3>Teach CDI to Create and Distribute Objects</h3><p>In addition to defining its scope, it is often impossible to perform activities such as determining or creating a class within the CDI container. This type of resource is essential for cases such as, for example, when we want to inject a connection to some service.</p><p>It is possible to teach the container to create instances and destroy them within CDI through the Produces and Disposes annotations, respectively. For this example, we will create a connection that will be created and closed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d39d5d8df2dbeec37f05b6b7dee492a/href">https://medium.com/media/2d39d5d8df2dbeec37f05b6b7dee492a/href</a></iframe><p>Right now, we have a connection from which we teach how the CDI should create and close the connection.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b98976bec040c1422b542b5389767509/href">https://medium.com/media/b98976bec040c1422b542b5389767509/href</a></iframe><h3>Apply Observer</h3><p>We cannot forget the <a href="https://refactoring.guru/design-patterns/observer">Observer</a> among the patterns very present in corporate architectures and present in the <a href="https://springframework.guru/gang-of-four-design-patterns/">GoF</a>.</p><p>One of the assessments I make of this pattern is that, given its importance, we can see it similarly in architectural practices, such as <a href="https://microservices.io/patterns/data/event-driven-architecture.html">Event-Driven</a>, and even in a paradigm with <a href="https://developers.redhat.com/blog/2017/06/30/5-things-to-know-about-reactive-programming">reactive programming</a>.</p><p>In CDI, we can handle events synchronously and asynchronously. Imagine, for example, that we have a journalist, and he will need to notify all the necessary media. If we do the coupling of these media directly in the “Journalist” class, every time a media is added or removed, it will be necessary to modify it. It breaks the <a href="https://www.baeldung.com/java-open-closed-principle">open-closed principle</a> to solve; we will use Observer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/505867ff158b94b858236b2ee7e349a1/href">https://medium.com/media/505867ff158b94b858236b2ee7e349a1/href</a></iframe><p>So we created a Journalist class that notifies the media, a novelty thanks to the Observer pattern with the CDI. The event is triggered by the Event instance, and to listen for it; it is necessary to use the @Observers annotation with the specific parameter to be listened to.</p><h3>Apply Decorator</h3><p>The <a href="https://refactoring.guru/design-patterns/decorator">Decorator</a> pattern allows us to add behavior inside the object, obeying the principle of <a href="https://en.wikipedia.org/wiki/Composition_over_inheritance">composition over inheritance</a>. We see this within the Java world with wrappers of primitive types like Integer, Double, Long, etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/793752fcd6f97717914764cae3cc9b9f/href">https://medium.com/media/793752fcd6f97717914764cae3cc9b9f/href</a></iframe><p>We created a worker abstraction, the Programmer, and the Manager responsible for delegating the worker. In this way, we could add a behavior, such as sending an email, without modifying the programmer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc4fbb577a48e49622310048fccdf510/href">https://medium.com/media/fc4fbb577a48e49622310048fccdf510/href</a></iframe><h3>The Interceptor</h3><p>The CDI can also perform and control some operations in the code in a transversal way, similar to what we do with <a href="https://www.baeldung.com/spring-aop">aspect-oriented programming and cutpoints with Spring</a>.</p><p>The CDI interceptor tends to be quite helpful when we want, for example, a logging mechanism, transaction control, or a timer for a method that will be executed, among others. In this case, the sample used will be a timer with an interceptor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d001d58133ab7fd98ccfef2510ef436f/href">https://medium.com/media/d001d58133ab7fd98ccfef2510ef436f/href</a></iframe><p>The interceptor implementation will allow the creation of the annotation that will be used to indicate the intercept, and the class, in turn, will define how this intercept will be implemented, which, in our case, will be a counter.</p><p>The following and last example is to create two methods that we will count, with two implementations, one of which will have a delay of two seconds.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c17178db266939296ed3e7bfaef0e4f7/href">https://medium.com/media/c17178db266939296ed3e7bfaef0e4f7/href</a></iframe><h3>Dependency Injection With Jakarta CDI: More Options for Your Development</h3><p>Given these practical examples, we can see the various possibilities and challenges possible when working with Object Orientation and better understand some of its principles around dependency injection and CDI.</p><p>It’s important to remember that, as Uncle Ben once said, “with great power comes great responsibility.” As such, common sense remains the best compass for exploring these and other CDI features, resulting in a high-quality design and clarity.</p><h3>References</h3><ul><li><a href="https://daedtech.com/dependency-injection-or-inversion/">Dependency Injection or Inversion?</a></li><li><a href="https://stackoverflow.com/questions/46709170/difference-between-dependency-injection-and-dependency-inversion">Difference between dependency injection and dependency inversion</a></li><li><a href="https://lostechies.com/derickbailey/2011/09/22/dependency-injection-is-not-the-same-as-the-dependency-inversion-principle/">Dependency Injection Is NOT The Same As The Dependency Inversion Principle</a></li></ul><p><strong>If you enjoy working on large-scale projects with global impact and if you like a real challenge, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! See you soon!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae82d0565a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/making-readable-code-with-dependency-injection-and-jakarta-cdi-ae82d0565a0">Making Readable Code With Dependency Injection and Jakarta CDI</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting with information security: how to avoid headaches with vulnerabilities in your code]]></title>
            <link>https://medium.com/xgeeks/starting-with-information-security-how-to-avoid-headaches-with-vulnerabilities-in-your-code-a771156ebe6e?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a771156ebe6e</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[xgeeks]]></category>
            <category><![CDATA[horusec]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Fri, 10 Dec 2021 12:39:23 GMT</pubDate>
            <atom:updated>2021-12-10T12:39:49.344Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*H7XaHl9bG0p8-c7N6VFwIQ.jpeg" /></figure><p>Understand the impacts of a security issue on your application and how to avoid being responsible for your company’s next security issue.</p><p>In recent times, we have witnessed several information security breaches worldwide: vulnerabilities, ransomware, Man-in-the-middle, among other problems that become headaches not only for the engineering team but for the whole company and even for customers of your product.</p><p>What if we say that most security problems could be avoided? This article will cover the importance of information security and how to include it throughout the development process: the so-called <strong>DevSecOps</strong>.</p><h3>The 3 Myths Around Security Information</h3><p>There are three taboos in the area of software development that we need to talk about to start addressing information security more consistently:</p><ol><li><strong>Security breaches are often seen as an issue only for large companies.</strong></li></ol><p>The first of them is the simplest to say: most security flaws and their respective impacts and damages are commonly related to large companies, such as <a href="https://www.csoonline.com/article/2130877/the-biggest-data-breaches-of-the-21st-century.html">Facebook, LinkedIn, among others</a>.</p><p>However, this is not a problem unique to large companies, so much so that a study by <strong>codegrip reports</strong> that <a href="https://www.codegrip.tech/productivity/what-is-code-vulnerability/">three out of four applications currently in use have some vulnerability</a>.</p><p><strong>2. Vulnerability does not harm businesses.</strong></p><p>According to <a href="https://www.ibm.com/security/data-breach">IBM’s latest vulnerability research report</a>, this idea is far from true. To give you an idea, about <strong>38% of business was lost by companies that had a security breach</strong>. In addition, there are some average loss estimates:</p><ul><li>Average of <strong>180 USD</strong> for each record of personal information.</li><li>4.62 million dollars was the average ransomware breach.</li><li>$3.61 million for every breach of hybrid cloud environments.</li></ul><p>In practice, vulnerability also impacts brand trust and credibility. A recent example <a href="https://www.nytimes.com/2017/05/23/business/target-security-breach-settlement.html">was Target, which had to shell out nearly $200 million to repair its credibility</a>.</p><p><strong>3. Security problems come from big mistakes.</strong></p><p>Of all the myths, this is the biggest fallacy of all! In general, the “minor problems” are precisely those that result in the most extensive security disasters, and we can say that failures usually present <strong>two gaps</strong>:</p><ol><li>We encountered flaws such as insecure code design, injection, and configuration issues through a <strong>code vulnerability</strong> intentionally or unintentionally: within the <a href="https://owasp.org/Top10/">TOP 10 demonstrated by OWASP</a>.</li><li><strong>Through the vulnerability of operations</strong>: among the most common problems, we can mention the choice for “weak passwords”, default or even the lack of password. A second common failure is the mismanagement of people’s permission to a document or system. These types of problems, unfortunately, are pretty standard. Not by chance, <a href="https://owasp.org/Top10/">75% of Redis servers have issues of this type</a>.</li></ol><p>In an analogy, we can say that security flaws are like the case of the Titanic. Considered one of the biggest wrecks, most people are unaware that the ship had a “small problem”: the lack of a <a href="https://www.theguardian.com/uk/2007/aug/29/artnews.art">simple key</a> that could have opened the compartment with binoculars and other devices to help the crew visualize the iceberg in time and prevent a collision.</p><h3>Knowing the security triad</h3><p>We understand the importance of information security and the tremendous impact of its absence. With that, the question remains: how to define if an application is safe?</p><p>In short, there is an acronym for a secure application based on <a href="https://www.iso27001security.com/html/27002.html">ISO 27002</a>, which is CIA, focused on three properties:</p><ul><li><strong>Confidentiality</strong>: The guarantee that a message will be delivered to the person who needs to receive that information.</li><li><strong>Integrity</strong>: Ensuring that information is delivered unchanged along the way.</li><li><strong>Availability</strong>: The guarantee that data must always be available to the legitimate user.</li></ul><p>To illustrate, an analogy. If the Titanic was a “failed application”, what happened was a problem in property A (Availability), since the key that guaranteed access to the binoculars was not available to the team ahead of the vessel.</p><h3>Understanding information security as a methodology: DevSecOps</h3><p>Once we understand the security principles, we need to understand the “how” to incorporate them into the routine of our applications. After all, how are we going to ensure that each delivery/deployment has no vulnerability issues?</p><p>One of the solutions is to <strong>increase the integration between teams</strong>, avoiding feedback delays and, mainly, making information security happen in a proactive and non-reactive way, as it usually happens.</p><p>The answer to this is <strong>DevSecOps</strong>, which focuses on adding a layer of security to the development operation. Thinking about this methodology is another step in the history of integration between teams.</p><ul><li><strong>Agile</strong>: The cone that comes from the <a href="https://agilemanifesto.org/">agile manifesto of 2001</a>, this methodology focuses on integrating the development team and the product team.</li><li><a href="https://aws.amazon.com/devops/what-is-devops/"><strong>DevOps</strong></a>: in the next integration step, the operations team is added within the already integrated development and user team.</li><li><strong>DevSecOps</strong>: finally, the security team is added to the groups that already exist in DevOps.</li></ul><p>As another methodology terminology, it is natural that there are several definitions for the same term. Some of them:</p><ul><li><a href="https://www.amazon.com.br/dp/B08QRRNX6K/">DevSecOps: A leader’s guide to producing secure software</a>: DevSecOps is DevOps made securely.</li><li><a href="https://www.amazon.com.br/dp/B07FNXVKCH/">Hands-On Security in DevOps</a>: DevOps offers speed and quality benefits with ongoing development and deployment methods, but it does not guarantee the security of an entire organization.</li><li><a href="https://www.redhat.com/en/topics/devops/what-is-devsecops">DevSecOps by RedHat</a>: Whether you call it “DevOps” or “DevSecOps”, it’s always been ideal for including security as an integral part of the entire application lifecycle.</li></ul><p>But regardless of which term is preferred, the significant point is that with <strong>DevSecOps</strong>, we need to incorporate information security as part of the process. In other words: <a href="https://www.ericom.com/whatis/layered-security/">layered security</a>, thinking from the end-user, through the engineering team, to database and operating-system configurations.</p><p>In addition to layered security, another core of the methodology is <strong>security automation</strong>. When we’re in the middle of a development treadmill, we tend to forget what we inevitably had to remember.</p><p>Information security tools can be integrated from CI/CD. That is, if there is any flaw, it can break the build. Within the categories of security tools, we can list some:</p><ul><li><a href="https://www.synopsys.com/glossary/what-is-sast.html"><strong>SAST</strong></a> (Static application security testing) is a tool that scans the code statically and analyzes the code before compilation.</li><li><a href="https://www.whitesourcesoftware.com/resources/blog/dast-dynamic-application-security-testing/"><strong>DAST</strong></a> (Dynamic Application Security Testing): a tool that performs code validations at runtime.</li><li><strong>IAST</strong> (Interactive Application Security Testing): Runs application tests from a running application. The most significant difference between IAST and DAST is that the tests are <a href="https://www.veracode.com/security/interactive-application-security-testing-iast">performed within the application</a>.</li></ul><h3>How Horusec can help you adopt the DevSecOps methodology in your project</h3><p>In general, these tools help detect vulnerabilities, monitor bugs, and, above all, prevent security problems.</p><p>And among the tools that exist on the market, we have <a href="https://horusec.io/site/">Horusec</a>, one of the <a href="https://opensource.zup.com.br/">Open Source projects maintained by Zup</a> and which focuses on making your application safer and preventing code vulnerabilities.</p><p>One of its differentials is its <strong>orchestration security feature tools</strong>. That is, it allows the integration of more tools. The main philosophy of the product is As much possible security: better!</p><p>Horusec also has a dashboard, which helps teams understand security issues within their application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/0*kL4uzT1XOeyFR98Y" /></figure><p>It is possible to integrate with Horusec in several ways, for example, with a CI like Github Action, and its might exports to the dashboard.</p><p>Prevention is the key, which means that if a PR has a vulnerability, the build “breaks”, preventing a future headache or vulnerability disaster from being merged into the production environment.</p><p>Currently, Horusec has three components:</p><ul><li><strong>CLI</strong>, or the classic terminal, allows the analysis and visualization of vulnerabilities directly through the terminal.</li><li>The <strong>Dashboard, or Horus-Manager</strong>, is an optional feature that allows you to view these vulnerabilities more intuitively than the terminal.</li><li><strong>An extension to IDE</strong> is also optional, making it easier to analyze vulnerabilities from the IDE itself. Today, we have the extension to use Horusec in Visual Studio Code.</li></ul><p>An excellent first experience installing both the CLI and the dashboard, but don’t worry; you can find all the information in the <a href="https://horusec.io/docs/">official project documentation</a>. Then you can analyze this repository <a href="https://github.com/ZupIT/horusec-examples-vulnerabilities">which contains several vulnerabilities and in several programming languages</a>.</p><p>It’s good to rely on tools like Horusec because they allow us, as development professionals, to have greater confidence in creating more secure code without vulnerabilities, thus preventing us from being the next responsible for the security of our project/product.</p><p><strong>If you enjoy working on large-scale projects with global impact and if you like a real challenge, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! See you soon!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a771156ebe6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/starting-with-information-security-how-to-avoid-headaches-with-vulnerabilities-in-your-code-a771156ebe6e">Starting with information security: how to avoid headaches with vulnerabilities in your code</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Apache Kafka With Spring]]></title>
            <link>https://medium.com/xgeeks/introduction-to-apache-kafka-with-spring-38367e53822f?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/38367e53822f</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Wed, 27 Oct 2021 08:37:03 GMT</pubDate>
            <atom:updated>2021-10-27T08:37:03.221Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AonjY0x_UVo9TPbYXkEb8Q.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@helloimnik">Hello I’m Nik</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Apache Kafka is a community-distributed streaming platform that has three key capabilities: publish and subscribe to streams of records, store streams of records in a fault-tolerant durable way, and then process streams as they occur. Apache Kafka has several successful cases in the Java world. This post will cover how to benefit from this powerful tool in the Spring universe.</h3><h3>Apache Kafka Core Concepts</h3><p>Kafka is run as a cluster on one or more servers that can span multiple data centers; Kafka cluster stores a stream of records in categories called topics, and each record consists of a key, a value, and a timestamp.</p><p><a href="https://kafka.apache.org/intro">From the documentation</a>, Kafka has four core APIs:</p><ul><li>The Producer API allows an application to publish a stream of records to one or more Kafka topics.</li><li>The Consumer API allows an application to subscribe to one or more topics and process the stream of records produced to them.</li><li>The Streams API allows an application to act as a stream processor, consuming an input stream from one or more topics and producing an output stream to one or more output topics, effectively transforming the input streams to output streams.</li><li>The Connector API allows building and running reusable producers or consumers that connect Kafka topics to existing applications or data systems.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NY8TfUX_xMxk7hNq.png" /></figure><h3>Using Docker</h3><p>There is also the possibility of using Docker. As it requires two images, one to Zookeeper and one to Apache Kafka, this tutorial will use docker-compose. Follow these instructions:</p><ul><li><a href="https://docs.docker.com/install/">Install Docker</a></li><li><a href="https://docs.docker.com/compose/install/">Install Docker-compose</a></li><li>Create a docker-compose.yml and set it with the configuration below:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d05cd7d6783a26e3172762c227447845/href">https://medium.com/media/d05cd7d6783a26e3172762c227447845/href</a></iframe><p>Then, run the command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1af67098e5be593511c772a0780a08ef/href">https://medium.com/media/1af67098e5be593511c772a0780a08ef/href</a></iframe><p>To connect as localhost, also define Kafka as the localhost within Linux, append the value below at the /etc/hosts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/126d148a6d9572203f07869b510b9eca/href">https://medium.com/media/126d148a6d9572203f07869b510b9eca/href</a></iframe><h3>Application With Spring</h3><p>To explore Kafka, we’ll use the <a href="https://spring.io/projects/spring-kafka">Spring-kafka</a> project. In the project, we’ll simple a name counter, which is based on a request it will fire an event to a simple counter in memory.</p><p>The Spring for Apache Kafka (spring-kafka) project applies core Spring concepts to the development of Kafka-based messaging solutions. It provides a “template” as a high-level abstraction for sending messages. It also provides support for Message-driven POJOs with @KafkaListener annotations and a “listener container”. These libraries promote the use of dependency injection and declarative. In all these cases, you will see similarities to the JMS support.</p><p>The first step in a Spring project maven based, where we’ll add Spring-Kafka, spring-boot-starter-web.</p><p>Spring-kafka by default uses the String to both serializer and deserializer. We’ll overwrite this configuration to use JSON where we’ll send Java objects through JSON.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e805c069fdb6fd7d407d31ead200bdc3/href">https://medium.com/media/e805c069fdb6fd7d407d31ead200bdc3/href</a></iframe><p>The first class is a configuration to either create a topic if it does not exist. Spring has a TopicBuilder to define the name, <a href="https://www.instaclustr.com/the-power-of-kafka-partitions-how-to-get-the-most-out-of-your-kafka-cluster/">partition</a>, and <a href="https://blog.knoldus.com/apache-kafka-topic-partitions-replicas-isr/">replica</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ff1660cb1482f63771c872325f7b4c9/href">https://medium.com/media/6ff1660cb1482f63771c872325f7b4c9/href</a></iframe><p>KafkaTemplate is a template for executing high-level operations in Apache Kafka. We’ll use this class in the name service to fire two events, one to increment and another one to decrement, in the Kafka.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46c6d1e5f238a67ad8737f9a2425de21/href">https://medium.com/media/46c6d1e5f238a67ad8737f9a2425de21/href</a></iframe><p>Once we talked about the producer the KafkaTemplatethe next step is to define a consumer class. A Consumer class will listen to a Kafka event to execute an operation. In this sample, the NameConsumer will listen to events easily with the KafkaListener annotation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8811d815efb34c83de6da18f231ae4d/href">https://medium.com/media/c8811d815efb34c83de6da18f231ae4d/href</a></iframe><p>To conclude, we see the potential of Apache Kafka and why this project became so accessible to Big-Data players. This is a simple example of how secure it is to integrate with Spring.</p><p><strong>If you enjoy working on large-scale projects with global impact and if you like a real challenge, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! See you soon!</strong></p><h3>References:</h3><ul><li><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-kafka">https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-kafka</a></li><li><a href="https://spring.io/projects/spring-kafka">https://spring.io/projects/spring-kafka</a></li><li><a href="https://docs.spring.io/spring-kafka/reference/html/">https://docs.spring.io/spring-kafka/reference/html/</a></li><li><a href="https://github.com/xgeekshq/spring-kafka">Source</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38367e53822f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/introduction-to-apache-kafka-with-spring-38367e53822f">Introduction to Apache Kafka With Spring</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fluent-API: Creating Easier, More Intuitive Code with a Fluent API]]></title>
            <link>https://medium.com/xgeeks/fluent-api-creating-easier-more-intuitive-code-with-a-fluent-api-fced26dc8a02?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fced26dc8a02</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[xgeeks]]></category>
            <category><![CDATA[fluent]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Fri, 10 Sep 2021 11:49:27 GMT</pubDate>
            <atom:updated>2021-09-10T11:49:27.431Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0fJggQSkSZ0c5urJDtIJHA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@ksubedi">Kaushal Subedi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We know that, in a software project, nothing replaces good documentation. However, it is also necessary to pay attention to how intuitive the written code is. After all, the simpler and more natural the code is, the better its experience for users.</p><p>In the simple “programming rule”, in which we will forget everything we have to remember, an API that “forces” you to remember is crucial proof of failure.</p><p>That’s why, in this article, we’ll introduce the topic and show you how to create a fluid API from the Fluent-API concept.</p><h3>What is a Fluent-API?</h3><p>When we speak in the context of software engineering, a fluent-API is an object-oriented API whose design is largely based on method chaining.</p><p>This concept, created in 2005 by <a href="https://twitter.com/ericevans">Eric Evans</a> and <a href="https://twitter.com/martinfowler">Martin Fowler</a>, aims to increase code readability by creating a domain-specific language (<a href="https://en.wikipedia.org/wiki/Domain-specific_language">DSL</a>).</p><p>In practice, creating a fluent API means developing an API in which it is unnecessary to memorize the next steps or methods, allowing for a natural and continuous sequence as if it were a menu of options.</p><p>This natural cadence works in a similar way to a restaurant or even a fast-food chain in that as you are putting together a dish, the options vary according to the choices you make. If, for example, you choose a chicken sandwich, the sides will be suggested considering the chosen dish and so on.</p><h3>Fluent API in Java context</h3><p>In the Java world, we can think of two famous examples of this type of implementation.</p><p>The first one is the <a href="https://www.jooq.org/">JOOQ</a> framework, a project led by <a href="https://twitter.com/lukaseder">Lukas Eder</a>, which facilitates communication between Java and relational databases. JOOQ’s most significant difference is that it is data-oriented, which helps avoid and/or reduce the impedance problem, or loss, associated with <a href="https://en.wikipedia.org/wiki/Object%E2%80%93relational_impedance_mismatch">relational and object-oriented</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b493a0d252adc6d64c49a0bede8c0e0/href">https://medium.com/media/0b493a0d252adc6d64c49a0bede8c0e0/href</a></iframe><p>Another example is in non-relational databases, i.e., NoSQL, within the specifications of the enterprise Java world. Among them is <a href="https://jakarta.ee/">Jakarta EE</a>, which is the first specification of its kind and which became <a href="https://jakarta.ee/specifications/nosql/">Jakarta NoSQL</a> under the umbrella of the <a href="https://www.eclipse.org/org/foundation/">Eclipse Foundation</a>.</p><p>The purpose of this specification is to ensure smooth communication between Java and NoSQL databases.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cf68cd3408f99b539f3617c0d16683b/href">https://medium.com/media/8cf68cd3408f99b539f3617c0d16683b/href</a></iframe><p>Generally speaking, a fluent API is divided into three parts:</p><ol><li><strong>The final object or result:</strong> Overall, the fluent-API resembles the builder pattern, but the most powerful dynamic is coupled with DSL. In both, the result tends to be an instance representing the result of a process or a new entity.</li><li><strong>The options</strong>: in this case, are the collections of interfaces or classes that will serve as “our interactive menu”. From an action, the idea is that show only the options available for the next step, following an intuitive sequence.</li><li><strong>The result</strong>: after all this process, the answer may or may not result in an instance either for an entity, strategy, etc. The critical point is that the result must be valid.</li></ol><h3>Fluid API in practice</h3><p>To demonstrate some of this concept, we’ll create a sandwich order with the expected result of an order with the corresponding purchase price. The flow will be as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*TtBztm8JUZ5zVREGy4RLNQ.png" /></figure><p>Of course, there are several ways to implement this fluent API functionality, but we opted for a short version.</p><p>As we already mentioned the three parts of an API — object, options, and result -, we will start with the order that the “Order” interface will represent. A highlight is that this interface has some interfaces, which will be responsible for demonstrating our options.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8efdd9de755f87ef83e06ed1f28ba687/href">https://medium.com/media/8efdd9de755f87ef83e06ed1f28ba687/href</a></iframe><p>The result of this API will be our order class. It will contain the sandwich, the drink, and their respective quantities.</p><h3>A quick add-on before we go back to the tutorial</h3><p>One point that we won’t focus on in this article, but that is worth mentioning, is related to the representation of money.</p><p>When it comes to numerical operations, it is ideal to use BigDecimal. That’s because, following references like the <a href="https://www.amazon.com/Effective-Java-Joshua-Bloch/dp/0134685997">Java Effective</a> book and the blog <a href="https://martinfowler.com/ieeeSoftware/whenType.pdf">When Make a Type</a>, we understand that complex types need a unique type. This reasoning, coupled with the pragmatism of “don’t repeat yourself” (DRY, or don’t repeat yourself), the result is the use of the Java specification for money: <a href="https://javamoney.github.io/">The Money API</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d70a098b3ccb3d3f89f09b78732789d9/href">https://medium.com/media/d70a098b3ccb3d3f89f09b78732789d9/href</a></iframe><p>The last step in the journey is API implementation. It will be responsible for the “ugly” part of the code, making the API look beautiful.</p><p>The price list will be placed directly in the code since we don’t use a database or another data reference, and we intend to make the example as simple as possible. But it is worth stressing that, in a natural environment, this information would be in a database or a service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2dfeed7fc490fbc6210e71ea72db08a/href">https://medium.com/media/a2dfeed7fc490fbc6210e71ea72db08a/href</a></iframe><p>The result is an API that will return the request to us straightforwardly and intuitively.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd146ac09358a108903e4f6d24aa660f/href">https://medium.com/media/bd146ac09358a108903e4f6d24aa660f/href</a></iframe><h3>How is Fluent API different from others patterns?</h3><p>It is widespread to have a comparison between two API standards, which are Builder and Fluent-API. The reason is that they both use methods in sequence for the process of creating an instance.</p><p>However, Fluent-API is “tied with a DSL”, and it forces an easy path to do so. But to make these differences even more evident, we’ve separated highlights for each of these patterns:</p><h3>The Builder pattern:</h3><ul><li>It tends to be much easier to implement;</li><li>It is not clear which construction methods are needed;</li><li>The vast majority of problems will happen at runtime;</li><li>Some tools and frameworks create it automatically;</li><li>It needs more robust validation in the build method to check which mandatory methods were not invoked.</li></ul><h3>The Fluent-API:</h3><ul><li>It is important that, for each method, there is validation and throws the error if the parameter is invalid, remembers the fast fail premise;</li><li>It must return a valid object at the end of the process.</li></ul><p>And now, is it easier to understand the similarities and differences between patterns?</p><p><a href="https://blog.jooq.org/the-java-fluent-api-designer-crash-course/">That is our introduction to the concept of fluent-API</a>. As with all solutions, there is no “silver bullet”, as great complexity is often not justified for the entire process.</p><p>Our colleague <a href="https://twitter.com/rponte">Rafael Ponte</a> often says that “the easier it is to use the API for the client, the more difficult it will be to design and implement it for the developer”.</p><p>It is an excellent tool that helps in creating a failsafe for you and other users. You can see more about it on <a href="https://github.com/soujava/sample-fluent-api">Sou Java’s Github</a>.</p><p><strong>If you enjoy working on large-scale projects with global impact and if you like a real challenge, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! See you soon!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fced26dc8a02" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/fluent-api-creating-easier-more-intuitive-code-with-a-fluent-api-fced26dc8a02">Fluent-API: Creating Easier, More Intuitive Code with a Fluent API</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[It is time to designing your code as Bulletproof Code!]]></title>
            <link>https://medium.com/xgeeks/it-is-time-to-designing-your-code-as-bulletproof-code-b8e373e76ba7?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8e373e76ba7</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[xgeeks]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Tue, 31 Aug 2021 17:08:31 GMT</pubDate>
            <atom:updated>2021-08-31T17:08:31.225Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*5I0y95JzarDKTTFFm6k5Kw.jpeg" /></figure><p>There is no doubt about the benefits good coding practices bring, such as clean code, easy maintenance, and a fluent API. However, do best practices help with data integrity? This discussion came up, mainly, with new storage technologies, such as the NoSQL database, that do not have native validation that the developer usually faces when working on SQL schema. A good topic that covers <a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship-ebook/dp/B001GSTOAM/ref=sr_1_1?keywords=clean+code&amp;qid=1555618511&amp;s=digital-text&amp;sr=1-1">clean code</a> is whose objects expose behavior and hide data, which differs from structured programming. The goal of this post is to explain the benefits of using a rich model against the anemic model to get data integrity and bulletproof code.</p><p>As mentioned above, an ethical code design also has an advantage in performance, once it saves requests to a database that has schema to check the validation. Thus, the code is agnostic of a database so that it will work in any database. However, to follow these principles, it requires both good OOP concepts and the business rules to make also a <a href="https://martinfowler.com/bliki/UbiquitousLanguage.html">ubiquitous language</a>. To make it smoother, this post will create a system that sorts a soccer player into a team; the rules of this system are:</p><ul><li>Player’s name is required</li><li>All players must have a position (goalkeeper, forward, defender, and midfielder).</li><li>Goals counter whose the player does on the team</li><li>Contact’s email</li><li>A team has players and names both as required</li><li>A team cannot handle more than twenty players</li></ul><p>With the information that was collected, there is the first draft code version:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c40ed5cc7d353dd312fe1a23036dd453/href">https://medium.com/media/c40ed5cc7d353dd312fe1a23036dd453/href</a></iframe><p>As the first refactoring, once there are fixed positions, it does not fit in very well on String. To fix it, we will use <a href="https://www.baeldung.com/a-guide-to-java-enums">enumeration</a> instead of String.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6aebcccd2c7996db057b58f1ac6aa506/href">https://medium.com/media/6aebcccd2c7996db057b58f1ac6aa506/href</a></iframe><p>Formerly introduced to the module fields, the next step is about security and encapsulation. Using <em>Effective Java</em> as a reference, the goal is to minimize the accessibility, thus just define all fields as private. Next, let’s put public getter and setter methods, right? Wrong! When a Java developer uses getters and setters unrestrained, it has the same effect on a public&#39;s field, causing loose coupling.</p><p>An accessor method must be used as the last resource that includes don’t create it as public visibility, in other words, as either default or protected, based on the encapsulation concern, it is possible to make the following conclusions:</p><ul><li>In the system sample, players do not change email, name, and position. Therefore, it does not need to create a setter method in these fields.</li><li>The last year&#39;s field indicates when the player will leave the team by contract. When it is optional, it means that there is no expectation to the player leave the club. The setter method is required, but the last year must be equals to or higher than a year of start. Also, a player cannot start to play before when <a href="https://en.wikipedia.org/wiki/History_of_association_football">soccer was born</a> in 1863.</li><li>Just the team can handle a player; it must be a tight coupling.</li></ul><p>In the Team class, there is a method used to add a player and a getter method returns all players from the team. The player must have a validation such as it cannot add a null player or cannot be higher than twenty players. A critical point on the getter to a collection is when directly returning an instance, the client might use the method to write directly such as clean, add, and so on. To solve the encapsulation, a good practice is to return a read-only instance such as <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#unmodifiableList-java.util.List-">unmodifiableList</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab0498208703c5ab3be9aeb8791cc089/href">https://medium.com/media/ab0498208703c5ab3be9aeb8791cc089/href</a></iframe><p>About the Player&#39;s class, all fields will have a getter method. The end field is an exception; once it may not exist at some point, a developer can return this attribute using an <a href="https://dzone.com/articles/java-8-optional-handling-nulls-properly">Optional to handle it instead of a null element</a>. Still, on the end field, thesetter method is required once it either sets an end value or updates the end because the player renewed the contract and the validation is vital to guarantee the object integrity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ef536383948d25720472ad1f0c8cd6f/href">https://medium.com/media/8ef536383948d25720472ad1f0c8cd6f/href</a></iframe><p>With the access method defined, the next step is the strategy of instance creation. Almost always, attributes are required for a new instance; the first move might create a constructor that receives all parameters. That fits on the Team class because it has a name parameter; however, in the player, there are several issues:</p><ol><li>The first is on the parameters quantity; a polyadic is not a good practice for several reasons. For example, with too many arguments of the same type, it is possible to make a mistake when changing the order.</li><li>The second one is on the complexity of these validations.</li></ol><p>An excellent way to solve it has two steps:</p><p>The first step is the type definition. This makes sense when an object has a colossal intricacy such as money, date. There is a nice post on <a href="https://www.martinfowler.com/ieeeSoftware/whenType.pdf">When to Make a Type</a>, which explains more on how to enhance code with this resource. A programmatic developer knows that reinventing the wheel is also a code smell. Therefore, the code will use the <a href="https://www.baeldung.com/java-8-date-time-intro">Date and Time API </a>from Java 8 and <a href="https://www.baeldung.com/java-money-and-currency">JSR 354: Money-API</a>. I just left the email type, as show the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f5a54556a80d952947b3a5a0a79b3fd/href">https://medium.com/media/8f5a54556a80d952947b3a5a0a79b3fd/href</a></iframe><p>With the email type created, we have a new version of the Player&#39;s class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb082639dd919c2f6f3a6dd5d6b37045/href">https://medium.com/media/cb082639dd919c2f6f3a6dd5d6b37045/href</a></iframe><p>The next step is a <a href="https://dzone.com/articles/creational-design-patterns-builder-pattern">Builder design pattern</a>, which follows the single responsibility to hold the duty to create a player instance. Furthermore, it avoids a mistake that changes the parameter order. Usually, mapper frameworks require a default constructor because it goes through reflection. Put the Deprecated annotation on this constructor to show that it is not a recommended method. An inner class fits in a builder because it can create a private constructor that only accesses the player builder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52b4334add724964adf7745e71569504/href">https://medium.com/media/52b4334add724964adf7745e71569504/href</a></iframe><p>Using a builder pattern on this principle, a Java developer knows when the instance exists and has valid information.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e51b26c5dc80b334cab228b30a476876/href">https://medium.com/media/e51b26c5dc80b334cab228b30a476876/href</a></iframe><p>As mentioned before Team&#39;s class does not need once it is a smooth one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/318bbedc471f80ea97ddf33e2309759f/href">https://medium.com/media/318bbedc471f80ea97ddf33e2309759f/href</a></iframe><p>When Java developers talk about validation, it is essential to speak of the Java specification that does it, the <a href="https://beanvalidation.org/">Bean Validation</a>, BV, that makes it more accessible to a Java developer to <a href="https://www.baeldung.com/javax-validation">create validation using annotation</a>. It is critical to point out that BV does not invalidate POO concepts. In other words, avoid loose coupling, the <a href="https://www.baeldung.com/solid-principles">SOLID</a> principle is still valid instead of putting those concepts away. Therefore, BV can either double-check validation or execute the validation on the Builder to return an instance, only if it passes on the validation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e7c49bc386e9f749e087a33c28dfee5/href">https://medium.com/media/6e7c49bc386e9f749e087a33c28dfee5/href</a></iframe><p>The next step is to do it safely and fluently. Yeap, we’ll cover a fluent API. The main point of a fluent API is to save time to check the documentation and make the communication with the API natural and smooth.</p><p>As an initial step, we’ll create an interface that will work as menu options, where the user can follow as a Windows Wizard:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df7735657b3f1c6ecdadc30a35f128e3/href">https://medium.com/media/df7735657b3f1c6ecdadc30a35f128e3/href</a></iframe><p>The PlayerDSL class implements all the “menu options” as you can see in the class below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1d4e22735582c7c01c90d416ef784bc/href">https://medium.com/media/c1d4e22735582c7c01c90d416ef784bc/href</a></iframe><p>As you can see, I don’t need to memorize the following API; the API will do it to me.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc81f111b738b4837dcaa8bb873ad815/href">https://medium.com/media/fc81f111b738b4837dcaa8bb873ad815/href</a></iframe><p>To conclude, this article demonstrates how to make code bulletproof using best design practices. Furthermore, we gain both object and data integrity at the same time. These techniques are agnostic from storage technology — the developer can use these principles in any enterprise software. That is important to say the tests are essential, but that is out of the article’s scope. <strong><em>In the next part of this topic, we will cover integration between this coding design with the database.</em></strong></p><p>You can find the source code on <a href="https://github.com/soujava/bulletproof">GitHub</a>.</p><p><strong>If you enjoy working on large-scale projects with global impact and if you like a real challenge, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! See you soon!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8e373e76ba7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/it-is-time-to-designing-your-code-as-bulletproof-code-b8e373e76ba7">It is time to designing your code as Bulletproof Code!</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Spring Data JPA With Inheritance in a REST Application]]></title>
            <link>https://medium.com/xgeeks/introduction-to-spring-data-jpa-with-inheritance-in-a-rest-application-2243e7378e67?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2243e7378e67</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[xgeeks]]></category>
            <category><![CDATA[spring-data]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Thu, 24 Jun 2021 10:22:15 GMT</pubDate>
            <atom:updated>2021-06-24T10:22:15.971Z</atom:updated>
            <content:encoded><![CDATA[<h3>Indeed, Spring is a platform to make the Java developer life more manageable. This tutorial will explore a primary feature on Spring Data JPA, such as the inheritance.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37ytRJbR6CB01nkTcFuKBg.jpeg" /></figure><p>Spring Data JPA makes it easy to implement JPA-based repositories quickly. This module deals with enhanced support for JPA-based data access layers, and it is a proud member of the Spring family. <strong>This tutorial will be a short intro about Spring Data JPA and its functionality.</strong></p><p>In the second part, <a href="https://dzone.com/articles/introduction-to-spring-core-annotations-api">we could cover the basic annotations on both Spring Core and the Spring Web</a>, focusing on Rest Controller; however, we did not create an application with a database connection.</p><p>Fortunately, it is the goal of this part to make a connection easier and clean. We’ll use Spring Data because it reduces a lot of code, and it uses the JPA annotations.</p><p>To explore the JPA annotations with a repository, we’ll create simple rest to handle a person and its tickets through plan, train, and bus. The foremost goal here is to explore the heritage of both the JPA and JSON serialisation.</p><p>It is essential to highlight that there is an <a href="https://en.wikipedia.org/wiki/Object%E2%80%93relational_impedance_mismatch">impedance mismatch</a>. Thus objects are not RDBMS, and if we don’t think about it will apply to performance and a bad design.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5b9bfc5460a53c57fbfbe461f7743a7/href">https://medium.com/media/f5b9bfc5460a53c57fbfbe461f7743a7/href</a></iframe><p>Only to show the heritage, there is a Ticket as an abstract class with some specialisation. We used the Ticket class as an entity with a single table strategy, and in the Jackson, the values of the subtype both are using the field type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1a2caf2eb9d87ad24d2de379397690e/href">https://medium.com/media/c1a2caf2eb9d87ad24d2de379397690e/href</a></iframe><p>The repository class integrates the database smoothly because the developer does not need to handle the implementation but with an interface. This repository has several features such as <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods">query by method</a> and uses the <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query">Query annotation</a> to execute queries without handle the undertaking.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b28cb9623ba04ce1abef9955a8891f4a/href">https://medium.com/media/b28cb9623ba04ce1abef9955a8891f4a/href</a></iframe><p>The last layer is the controller, where we’ll do a tight integration with the repository once it is a light application. The PersonController has the pagination features beyond the CRUD operation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/698debb1b55a5038fe6e2d4b145452d1/href">https://medium.com/media/698debb1b55a5038fe6e2d4b145452d1/href</a></iframe><p>In this tutorial, we could explore the Spring Data JPA API basics using the inheritance feature on both JPA and JSON. Spring has several resources that allow us to create a Rest application with a database integration with a couple of classes. It is essential to say that it is a first step in the JPA and Spring world where there are references to go deep below.</p><p><strong>If you enjoy working at a large scale in projects with global impact and if you like a real challenge with Java, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team, especially in </strong><a href="https://boards.greenhouse.io/xgeeks/jobs/5045629002"><strong>Java</strong></a><strong> and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at xgeeks! See you soon!</strong></p><h3>References:</h3><ul><li><a href="https://spring.io/guides/gs/rest-service/">Building a RESTful Web Service</a></li><li><a href="https://spring.io/guides/gs/serving-web-content/">Serving Web Content with Spring MVC</a></li><li><a href="https://spring.io/guides/tutorials/bookmarks/">Building REST services with Spring</a></li><li><a href="https://spring.io/guides/gs/accessing-data-jpa/">Accessing Data with JPA</a></li><li><a href="https://github.com/LeaseWeb/api-standards">LeaseWeb API Design Standards</a></li><li><a href="https://www.baeldung.com/hibernate-inheritance">Hibernate Inheritance Mapping</a></li><li><a href="https://martinfowler.com/articles/richardsonMaturityModel.html">Glory of REST</a></li><li><a href="https://github.com/xgeekshq/workshop-intro-java-11-spring">Source Code</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2243e7378e67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/introduction-to-spring-data-jpa-with-inheritance-in-a-rest-application-2243e7378e67">Introduction to Spring Data JPA With Inheritance in a REST Application</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Spring Core Annotations API]]></title>
            <link>https://medium.com/xgeeks/introduction-to-spring-core-annotations-api-89eb31115efc?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/89eb31115efc</guid>
            <category><![CDATA[xgeeks]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Thu, 20 May 2021 13:25:48 GMT</pubDate>
            <atom:updated>2021-05-20T13:25:48.532Z</atom:updated>
            <content:encoded><![CDATA[<h3>Spring is a popular Java framework with several features and resources to make a Java developer’s life easier. This tutorial will help you get started on its annotations.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*qP57UPLajnNc1E1u4nA-ew.jpeg" /></figure><p>The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications — on any deployment platform. It was born as a container of IoC. Still, nowadays, Spring is a platform that provides several tools to make the Java developer easier, such as Security, Data, etc. Those features have in common the Spring core. This tutorial will talk about the basic annotations to start to use Spring.</p><p>Spring is an annotation driver framework. Thus, it uses annotations to identify the components to inject and to use. The first step in this tutorial is a list of the most trivial annotations in Spring.</p><ul><li>Component: Indicates that an annotated class is a &#39;component.&#39; Such classes are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning.</li><li>Repository: Indicates that an annotated class is a &#39;Repository,&#39; originally defined by Domain-Driven Design (Evans, 2003) as &#39;a mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects.&#39;</li><li>Service: Indicates that an annotated class is a &#39;Service,&#39; originally defined by Domain-Driven Design (Evans, 2003) as &#39;an operation offered as an interface that stands alone in the model, with no encapsulated state.&#39;</li><li>Qualifier: This annotation may be used on a field or parameter as a qualifier for candidate beans when autowiring. It may also be used to annotate other custom annotations that can then in turn be used as qualifiers.</li><li>ComponentScan: Configures component scanning directives for use with @Configuration classes. Provides support parallel with Spring XML&#39;s &lt;context:component-scan&gt; element.</li><li>SpringBootApplication: Indicates a configuration class that declares one or more @Bean methods and also triggers auto-configuration and component scanning.</li><li>Configuration: Indicates that a class declares one or more @Bean methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime.</li><li>Bean: Indicates that a method produces a bean to be managed by the Spring container.</li><li>Primary: Indicates that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency. If exactly one &#39;primary&#39; bean exists among the candidates, it will be the autowired value.</li><li>Lazy: Indicates whether a bean is to be lazily initialized.</li></ul><p>To create a class observable in Spring, we need to use annotation. The basic ones are Component annotations and their specialization, such as Repository and Service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fabb3648bb4b3ffd091a6e66492486ee/href">https://medium.com/media/fabb3648bb4b3ffd091a6e66492486ee/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1b8010ff3f150831bc67c1d17871cb9/href">https://medium.com/media/b1b8010ff3f150831bc67c1d17871cb9/href</a></iframe><p>Spring has support to polymorphism as well, where you can handle with several implementations, such as given a payment we have several options. There is the primary annotation to define a ‘default’ option, and there is a Qualifier where you can choose the implementation to select.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ceed71fdf88255c36b84775fce5a45a1/href">https://medium.com/media/ceed71fdf88255c36b84775fce5a45a1/href</a></iframe><p>Spring has the option to us, as a developer, teach him how to create an instance. The idea is like the Produces annotation in CDI. So, you can use this class through Spring.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9177f8958a8261a063aa1b15aa4e697d/href">https://medium.com/media/9177f8958a8261a063aa1b15aa4e697d/href</a></iframe><p>Usually, especially in Java, we create an application to communicate to another application through the HTTP request. Indeed, Spring supports it, and we did with the core annotations, below the basic’s annotations with Spring.</p><ul><li>SpringBootApplication: Indicates a configuration class that declares one or more @Bean methods and also triggers auto-configuration and component scanning.</li><li>ResponseStatus: Marks a method or exception class with the status code and reason that should be returned.</li><li>RequestMapping: Annotation for mapping web requests onto methods in request-handling classes with flexible method signatures.</li><li>GetMapping: Annotation for mapping HTTP GET requests onto specific handler methods.</li><li>RequestParam: Annotation which indicates that a method parameter should be bound to a web request parameter.</li><li>PathVariable: Annotation which indicates that a method parameter should be bound to a URI template variable.</li><li>PostMapping: Annotation for mapping HTTP POST requests onto specific handler methods.</li><li>RequestBody: Annotation indicating a method parameter should be bound to the body of the web request.</li><li>PutMapping: Annotation for mapping HTTP PUT requests onto specific handler methods.</li><li>DeleteMapping: Annotation for mapping HTTP DELETE requests onto specific handler methods.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/422b8e9875ff7b54318ebfdb955411c2/href">https://medium.com/media/422b8e9875ff7b54318ebfdb955411c2/href</a></iframe><p>That is it; in this tutorial, we could cover a brief introduction about Spring and its annotations in both core and the rest controller. The goal is to help you start your project with Spring frameworks because this project has a bright future and will make your life easier as a Java developer.</p><h3>References:</h3><ul><li><a href="https://spring.io/guides/gs/rest-service/">Building a RESTful Web Service</a></li><li><a href="https://spring.io/guides/gs/serving-web-content/">Serving Web Content with Spring MVC</a></li><li><a href="https://spring.io/guides/tutorials/bookmarks/">Building REST services with Spring</a></li><li><a href="https://medium.com/javarevisited/core-spring-framework-annotations-300493ba85da">Core Spring Framework Annotations</a></li></ul><p><strong>If you enjoy working at a large scale in projects with global impact and if you like a real challenge with Java, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team, especially in Java and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at xgeeks! See you soon!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89eb31115efc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/introduction-to-spring-core-annotations-api-89eb31115efc">Introduction to Spring Core Annotations API</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Overview Between Java 8 and Java 11]]></title>
            <link>https://medium.com/xgeeks/an-overview-between-java-8-and-java-11-b445e48f16ed?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b445e48f16ed</guid>
            <category><![CDATA[xgeeks]]></category>
            <category><![CDATA[java11]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Fri, 14 May 2021 11:51:39 GMT</pubDate>
            <atom:updated>2021-05-14T11:51:39.182Z</atom:updated>
            <content:encoded><![CDATA[<h3>This tutorial covers the basics of Java 8 and Java 11; it is a start to prepare you for the next LTS: Java 17.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*MXkcoAvTanpxJbX2ThbLeg.jpeg" /></figure><p>One of the great news introduced in the Java world is related to the version cycle, of which we have a release every six months and a version of Long Term Support every three years. Currently, the LTS version is Java 11, from which many companies are moving towards its use. First, this movement is significant because new frameworks will not support Java 8 and will consider Java 11 as a minimum beyond the point that the next LTS will be in September 2021 with Java 11. The purpose of this article is to talk a little about the basic APIs that happens between Java 8 and Java 11.</p><h3>The Functions Classes</h3><p>An important point that will serve as a basis, starting with Java 8, is the new interfaces within the java.util.function package, in this overview, we&#39;ll see covert four interfaces:</p><p><strong>Function</strong>: Represents a function that accepts one argument and produces a result:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0243a05f90d1357877817196341faaf/href">https://medium.com/media/a0243a05f90d1357877817196341faaf/href</a></iframe><p><strong>Predicate</strong>: Represents a predicate (boolean-valued function) of one argument.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e722751d74df49161109b35304a14024/href">https://medium.com/media/e722751d74df49161109b35304a14024/href</a></iframe><p><strong>Supplier</strong>: Represents a supplier of results.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a8bf050b98484200fc1cef9cc99cdff/href">https://medium.com/media/4a8bf050b98484200fc1cef9cc99cdff/href</a></iframe><p><strong>Consumer</strong>: Represents an operation that accepts a single input argument and returns no result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83410e3e24e0e802a23ed78c04218cb9/href">https://medium.com/media/83410e3e24e0e802a23ed78c04218cb9/href</a></iframe><p>On those interfaces, we’ll see several improvements, such as in the Collections implementations:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebbc69bc5a740f8f8fb602ec168ea377/href">https://medium.com/media/ebbc69bc5a740f8f8fb602ec168ea377/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2541050b507071c56b1f9609c94f88d9/href">https://medium.com/media/2541050b507071c56b1f9609c94f88d9/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16e271ec68cea24117276e7ed2a5cc33/href">https://medium.com/media/16e271ec68cea24117276e7ed2a5cc33/href</a></iframe><p>Also, there are new methods factories to make it easier to create the collections interfaces:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5a7ab5ef0b4c875d867c14e2b052db0/href">https://medium.com/media/d5a7ab5ef0b4c875d867c14e2b052db0/href</a></iframe><p><strong>Stream</strong> is a sequence of elements supporting sequential and parallel aggregate operations. We can think about a waterfall or a river flow. This API is robust and clean to manipulate a collection such as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34f054c26de60338dcc740ddcb654e74/href">https://medium.com/media/34f054c26de60338dcc740ddcb654e74/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02d881039cd94a641a7868dcedf4d145/href">https://medium.com/media/02d881039cd94a641a7868dcedf4d145/href</a></iframe><p>When Java 8 was released, a new Date and Time API with new types, immutable classes, practical news methods, and finally Enums to the day of weeks and months instead of numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29606ad1cb6b6b24c5332aa10665132f/href">https://medium.com/media/29606ad1cb6b6b24c5332aa10665132f/href</a></iframe><p>As the current LTS, Java 11 has several features that make the developer live easier in their day job. This post was only an overview and quickly started with Java 11 and missed some Java 8. There are many references about the feature to each new version.</p><h3>References:</h3><ul><li><a href="https://www.baeldung.com/java-8-streams">Intro to Stream</a></li><li><a href="http://tutorials.jenkov.com/java-functional-programming/streams.html">Stream API</a></li><li><a href="https://www.baeldung.com/java-8-date-time-intro">Introduction to the Java Date/Time API</a></li><li><a href="https://www.baeldung.com/java-11-new-features">Java 11 New Features</a></li><li><a href="https://www.baeldung.com/new-java-9">New Features in Java 9</a></li><li><a href="https://www.baeldung.com/java-10-overview">New Features in Java 10</a></li><li><a href="https://github.com/xgeekshq/workshop-intro-java-11-spring">Sample Source</a></li></ul><p><strong>If you enjoy working at a large scale in projects with global impact and if you like a real challenge with Java, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team, especially in Java and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at xgeeks! See you soon!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b445e48f16ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/an-overview-between-java-8-and-java-11-b445e48f16ed">An Overview Between Java 8 and Java 11</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Spring Boot and JDBCTemplate: Introduction to Docker]]></title>
            <link>https://medium.com/xgeeks/introduction-to-spring-boot-and-jdbctemplate-introduction-to-docker-b171fdd69263?source=rss-951be51d886c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b171fdd69263</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Otavio Santana]]></dc:creator>
            <pubDate>Tue, 27 Apr 2021 18:00:23 GMT</pubDate>
            <atom:updated>2021-05-05T18:48:35.088Z</atom:updated>
            <content:encoded><![CDATA[<p>With the set application connected to the database, the next step is to deploy the application. In the third part of this series, our primary goal is to deploy our application using both Docker and Docker-compose resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*bImfs6dh0acpkJu0hLHnEQ.jpeg" /></figure><p>Indeed, the use of containers has made the use and adoption of cloud computing a lot easier, and with its most significant differential, the application isolation refuse. Making an analogy with the Java world of which we have the <a href="https://en.wikipedia.org/wiki/Write_once,_run_anywhere">WORA</a> Write Once Read Anywhere with containers, we have the P<a href="https://www.nginx.com/resources/library/docker-for-java-developers/">ORA Package Once Run Anytime</a>. Since the container, on a general basis, focuses on being an isolated package within an application. The purpose of this article is not to talk about the inner workings of a container. However, <a href="https://platform.sh/blog/2020/the-container-is-a-lie/">we have this excellent article from</a> <a href="https://twitter.com/Crell">Larry</a> that manages to address more about the subject.</p><p>Within the microservices world, <a href="https://twitter.com/leonardr">Leonard Richardson</a> breaks down t<a href="https://martinfowler.com/articles/richardsonMaturityModel.html">he principal elements of a REST approach into three steps</a>. These introduce resources, HTTP verbs, and hypermedia controls. In the cloud computing environment, there is still no similar thing for the glory of the cloud. However, there is an excellent debate about some elements of migrating an application until the cloud computing environment arrives:</p><ol><li><a href="https://blog.newrelic.com/engineering/container-orchestration-explained/">Orchestrator</a>: Once you work with containers and isolate applications, the next step would be to create mechanisms to manage such containers.</li><li><a href="https://www.jetbrains.com/teamcity/ci-cd-guide/continuous-integration-vs-delivery-vs-deployment/">CI/CD</a>: A good code is a code in production, however, with the most outstanding possible security. The use of CI / CD tools helps in this regard.</li><li><a href="https://www.amazon.com/Infrastructure-Code-Dynamic-Systems-Cloud-ebook-dp-B08Q35FM4B/dp/B08Q35FM4B/ref=mt_other">Infrastructure as code</a>: Creates a declarative API for operations; this allows for greater integration and the implementation of the DevOps culture, in addition to the significant first step towards greater automation of processes.</li><li><a href="https://dzone.com/articles/java-gitops">GitOps</a>: Git becomes a source of truth for both code and operations.</li></ol><p>The first step is to run the terminal application and then run the same application, however, with docker-compose. For the installation of the database, Docker will help straightforwardly. Thus, to start a PostgreSQL instance, it is necessary to execute with the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be9428d970c36f98d8ef912b484e8c4b/href">https://medium.com/media/be9428d970c36f98d8ef912b484e8c4b/href</a></iframe><p>The next step is to run the application; once we use maven, there is a command to prepare the application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6be1a60c372ae31d2b8694a5488e19f8/href">https://medium.com/media/6be1a60c372ae31d2b8694a5488e19f8/href</a></iframe><p>The application is running; feel free to perform tests within the application. It is missing API documentation such as Swagger and Open API, which we won’t cover.</p><p>The next step is to run this same application within the docker-compose; Spring has a maven plugin to create a Docker image integrated with <a href="https://paketo.io/">Paketo</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da0dbf9fab8e58857d409a835759e91f/href">https://medium.com/media/da0dbf9fab8e58857d409a835759e91f/href</a></iframe><p>After the build, there may be a new image with the version’s name according to the project in maven.</p><p>The next and last step is to create the docker-compose.yml file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f96c02a5bb3e2dc555973b200402cb32/href">https://medium.com/media/f96c02a5bb3e2dc555973b200402cb32/href</a></iframe><p>We present all the initial concepts to create an application locally or through the docker, through a plugin from Spring itself. With Spring JDBC, there was a significant reduction in code compared to JDBC of the core java. However, there are still tools that managed to reduce this complexity even more. In the third and last part of the series, there will be a refactoring to use the same problem using Spring Data JPA.</p><p><strong>If you enjoy working at a large scale in projects with global impact and if you like a real challenge with Java, feel free to reach out to us at </strong><a href="https://xgeeks.io/"><strong>xgeeks</strong></a><strong>! We are growing our team, especially in Java and you might be the next one to join this group of talented people 😉</strong></p><p><strong>Check out our social media channels if you want to get a sneak peek of life at xgeeks! See you soon!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b171fdd69263" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xgeeks/introduction-to-spring-boot-and-jdbctemplate-introduction-to-docker-b171fdd69263">Introduction to Spring Boot and JDBCTemplate: Introduction to Docker</a> was originally published in <a href="https://medium.com/xgeeks">xgeeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>