Skip to content

Instantly share code, notes, and snippets.

@AdamBien
Created June 7, 2018 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamBien/bfa3a444b6af3316e772f8eaf133f1cb to your computer and use it in GitHub Desktop.
Save AdamBien/bfa3a444b6af3316e772f8eaf133f1cb to your computer and use it in GitHub Desktop.
52ndAirhacksQ&A.md
@gadton
Copy link

gadton commented Jun 7, 2018

Hello Adam,
we have some CDI components we want to be able to use in several projects by e.g. extracting them to a separate JAR.
The using project should be able to control which components are used and which not. For injection of classes this is easy: referenced classes are used.
@Inject Instance<Foo> and iterating over the found implementations of Foo is an issue as ALL will be taken. Is there a way to control (by the project) which classes are taken?
Would be great if @Inject Instance<Foo> inside the JAR would take implementations of the using project too ;-)

One try was to annotate all components in the extracted JAR with @Alternative and list them in beans.xml of the project but this does not work as it breaks injection inside the extracted JAR.
Another try was to have only abstract classes in the JAR and control the usage in the project by creating (empty) subclasses. Works but looks strange.
Thanks

@1Kamikazzze1
Copy link

Hello Adam,
what is the right choice for the bean-discovery-mode in the beans.xml for CDI? We are using Weld in an SE environment and we are using "all" at the moment but in the attribute description of the bean-discovery-mode it says the following:

Attribute : bean-discovery-mode
It is strongly recommended you use "annotated". If the bean discovery mode is "all", then all types in this archive
will be considered. If the bean discovery mode is "annotated", then only those types with bean defining
annotations will be considered. If the bean discovery mode is "none", then no types will be considered.

Why do they state that you should use annotated vs all? Is it best practice to use annotated? Should we try to change to annotated? What is your opinion on this issue?

Thanks in advance

@dwamara
Copy link

dwamara commented Jun 10, 2018

Hi Adam,
long time no question asked so allow me to ask one today.
I'm actually building a platform for my own startup comprising 14 different microservices. One of them, the "travel" microservice asynchronously calls 4 other services using CompletableFutures to aggregate data from each one of them.
I am using "CompletableFuture allOf(CompletableFuture<?>... cfs)" to wait for all the services to return their data to do the aggregation. But how do you handle still aggregating the results of say 3 of the services if for any reason 1 of the 4 fails as the most important thing for me business speaking will be to present the customer the data that I have been able to aggregate? As far as I've read the documentation, allOf will completely fail if one of the services fails but I would like to be able to keep on going and just forget about the results of the 4th if it fails.

Kind regards,
Daniel

@jpollard-github
Copy link

Hi Adam,

First thank you very much for your blog, books, and web-based courses. I am a recent Java convert after 15 years of Microsoft development, and your perspective on Java EE has been refreshing and enlightening. I switched to Java mainly because of standards and the richer ecosystem and history.

I have three higher level questions for you:

  • Are you planning to be involved with any of the specifications for Jakarta EE? I notice that you've been very involved in the past, and I've seen some of your comments in the new mailing lists. As someone new to the Java/JEE ecosystem, I'm curious what you think?

  • At the end of the green book, you present SOA and Domain Driven Design as two valid approaches in Java EE with ECB. I recently used ECB in a Java project (no Java EE, it's meant as a JAR for clients to consume). It was easy and straightforward, and I definitely used the SOA approach. Do you find yourself using the SOA approach or DDD approach more often with clients, or do you have any new thoughts on these approaches?

  • Do you have any recommendations on being a successful consultant with Java EE (or in general)? You have built up a great reputation over the years, and you continue to do so much for the community (like answering these questions and your courses). It's inspirational.

Thank you!
Jason Pollard
Charlotte, NC, USA

@kullmanp
Copy link

Hi Adam,
I have two questions regarding read-only validation calls in a JEE application with a REST api and JPA as persistence framework.

  • A call in a validation service should not make any persistent changes - it should just report validation messages. How can we make sure that changed entities are not flushed to the database? Use setRollbackOnly() in the method that starts the transaction? (This could also be done using an interceptor.)
  • What's the best REST-style for this kind of call? Say, I want to validate some order data that I normally would persist using PUT /orders/1234. Using a query param like validateOnly=true? Or use a POST to a different uri like /orders/validation?

@gbourant
Copy link

Hello Adam,

Let's say that you are using JAX-RS and you return a Person entity that has a relation with a country.

@Entity
class Person {
    private Long id;
    private String name;
    private Country country;
}

@Entity
class Country {
    private Long id;
    private String name;
}

When i make a GET request on person entity i want to get person's details and only the country ID.
Also on POST requests i want to convert the country ID to the country POJO (country must be received from database).

  1. I would like to hear how you would approach this problem.
  2. Since i'm using Java EE 8 i tried using JSON-B (JSR 367) to achieve the functionality described above.
    2.1) What's the proper way to inject entity manager on a class that implements the JsonbDeserializer ?
    2.2) Is it possible to make a class that implements the JsonbDeserializer using generics so i wouldn't have to implement JsonbDeserializer for each entity type.

Thank you.

@rieckpil
Copy link

rieckpil commented Jun 30, 2018

Hi Adam,

I have three questions for the upcoming airhacks show:

  1. How do migrate your database schema with Flyway? Do you use the Java/Maven or CLI approach?

What do you think about the following solution (JavaEE 8, OpenLiberty 18.0.0.2, Flyway 5.0.7)?

@Startup
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Singleton
public class FlywayMigration {

    private final Logger log = Logger.getLogger(this.getClass().getName());

    @Resource(lookup = "jdbc/sample")
    DataSource dataSource;

    @PostConstruct
    private void onStartup() {

        if (dataSource == null) {
            log.severe("no datasource found to execute the db migrations!");
            throw new RuntimeException(
                    "no datasource found to execute the db migrations!");
        }

        Flyway flyway = new Flyway();
        flyway.setDataSource(dataSource);
        for (MigrationInfo i : flyway.info().all()) {
            log.info("migrate task: " + i.getVersion() + " : "
                    + i.getDescription() + " from file: " + i.getScript());
        }
        flyway.migrate();

    }
}

And what's your Flyway strategy in enterprise projects for the SQL scripts? Do you create a single SQL script for every change during the Sprint or do you collect all changes during one sprint/cycle and squash them into one single SQL script, so that /db/migration won't grow that much?

  1. What are the three most important books about Programming/Software Design/Java every developer should read in your opinion?

  2. If you could give your 20-year-old self three lessons for your Developer career, what would it be?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment