Skip to content

Instantly share code, notes, and snippets.

View struberg's full-sized avatar

Mark Struberg struberg

  • Vienna
View GitHub Profile
import org.apache.deltaspike.core.api.config.ConfigResolver;
import java.util.concurrent.TimeUnit;
/**
* A value taken from DeltaSpike configuration.
* But with configurable expiry time
*
* Use the {@link #get()} method to resolve the cached or re-loaded value
*
* @author Mark Struberg
Hi Vlad!
The 140 char limit on Twitter isn't really helpful to make to the point statements. At least it seems you totally missed my 2nd tweet. But since the context between 2 tweets often gets lost I thus added a longer explanation as blog post https://struberg.wordpress.com/2016/10/15/tostring-equals-and-hashcode-in-jpa-entities/
I you have read my blog post carefully then you might notice that your first sentence is quite off from what I expressed. You missed that I am focusing on PORTABLE behaviour (which you as a Hibernate maintainer obviously don't care about) and on DEFAULT IDE generated behaviour (which will hit Hibernate as well).
To get things straight: most IDEs do a bad job in GENERATING a good toString(), equals() and hashCode() method. They usually just pick all the attributes. Those generated methods usually also include attributes which are @ElementCollections or @OneToMany fields. I guess you agree with me that touching those fields in e.g. toString() will also trigger lazyLoading even in
The following small changes allows to use < and > in asciidoctor code parts in reveal.js
-------
(function () {
var optionKeys = ['attributes'];
var defaultOptions = ['showtitle'];
var sections = document.querySelectorAll('[data-asciidoctor]');
var attributes, options;
for (var i = 0, len = sections.length; i < len; i++) {
var currentAttr = sections[i].getAttribute('data-attributes');
@ApplicationScoped
public class DynamicConfigUsageSample {
private @Inject Config config;
private ConfigValue<String> serverUrlCfg;
private ConfigValue<Integer> serverPortCfg
@PostConstruct
private void init() {
public class ConfigLocator implements Extension {
private Config config;
public void initConfig(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
List<ConfigSource> collectedConfigSources = new ArrayList<>();
bm.fireEvent(new CollectConfig(collectedConfigSources));
this.config = ConfigProvider.newConfig()......;
bm.fireEvent(config);
public Optional<String> getDings() {
String dings = ...;
return Optional.ofNullable(dings);
}
public void usageWithOptional(Optional<String> val) {
String x = val.orElse("defaultValue");
or
String x = val.get() // and boom if missing instead of Validate.notNull
ConfigValue<Integer> port = config.resolve("myUrl)
.as(Integer.class)
.cacheFor(5,TimeUnit.Seconds)
.notifyOnChange(::somemethod);
...
port.get();
Consider the following annotation
@Qualifier
public @interface ConfigProperty {
@Nonbinding
String value() default "";
}
If I like to programmatically create an annotation instance then I can write
@struberg
struberg / JaxWsRegistrationExtension.java
Created June 9, 2017 09:59
Register JAX-WS in Meecrowave. Just playing around with it for now
public class JaxWsRegistrationExtension implements Extension {
private List<AnnotatedType> webServices = new ArrayList<>();
public void collectWebServices(@Observes @WithAnnotations(WebService.class) ProcessAnnotatedType<?> pat) {
if (pat.getAnnotatedType().isAnnotationPresent(Path.class) && !pat.getAnnotatedType().getJavaClass().isInterface()) {
webServices.add(pat.getAnnotatedType());
}
}
INFORMATION: OpenWebBeans Container has started, it took [106] ms.
took ms: 1521
Observer_000
Observer_002
Observer_004
Observer_006
Observer_007
Observer_008
Observer_009
Observer_010