Java
- Storing LocalDateTime as DATETIME
In MYSQL the TIMESTAMP column type only supports dates until 2038 and so it makes sense to use the DATETIME type as this supports a much wider range of dates. By default it only stores seconds and no millis or micros.
The result is that times are rounded. 500 millis is rounded up to the next second. And this can give issues during the transition from wintertime to summertime. Imagine a …
- MS-SQL fast count
SELECT COUNT(*) FROM dbo.<database> can take a long time. If accuracy is not 100% needed this might help:
SELECT SUM(p.rows) FROM sys.partitions AS p
INNER JOIN sys.tables AS t
ON p.[object_id] = t.[object_id]
INNER JOIN sys.schemas AS s
<… - Kotlin typealias
The typealias can be handy to define very simple types. But be aware that it is not represented in bytecode. The typealiases are simply replaced by the type they represent and so can't be used for function signatures. See also Type aliases
Issues
By using typealiases code can become fuzzy very quickly.…
- Spring Boot
- Funny
Q1: Is there any value for i where the following statement prints "true"?
public class Q1 {
public static void main(String[] args) {
int i = ???;
if( i != 0 && i == -i) {
System.out.println(… - WTF code fragments
Those code fragments are real-life production fragments used in large corporate systems.
Why should I just return only the value I need?
// Do database query to request all statements matching the filter
accountStatements = listStatements.execute( filter, null, balance.getCurrencyDate(), null, sortFilter, sortOrdering );
AccountStatement lastStatement = null;- DevOxx Antwerpen 2016
Het thema voor mij was om meningen te horen. Meningen over hoe dingen kunnen, moeten en vooral ook hoe ze niet moeten. Meningen van ervaren developers die in de praktijk dingen tegen komen.
In de komende paragrafen werk ik die meningen uit. Veel kan leiden tot discussies. Het zijn daarom ook slechts meningen en inzichten. Ik schrijf het daarom ook vanuit mijn gezichtspunt.
Exte…
- Handle HEAD requests
Most containers handle a HEAD request the same as a GET request and so include all logic to build the page. While only the header is requested this could be a waste of resources.
To solve this a filter can be made that filters HEAD requests and stops further processing of the request.
package app.filters;
import java.io.IOException;
import javax.servlet.F…- JPA autodetect argument type
Doing a query like this:
Query query = entityManager.createQuery("FROM Employee e WHERE :type IS NULL OR e.empoyeeType = :type");
query.setParameter("type", employeeType); // employeeType is an ENUMThis results in hibernate not being able to determine the type of the parameter and uses VARBINARY. This results in empty resultsets if employeeType…
- Generic tricks
- jar files can add dependecies to the classpath by setting them in the MANIFEST.MF
- Tomcat - Pickup logging.properties while starting from Eclipse
- Goto "Servers" and double click the server you would like to log
- Click "Open launch configuration"
- Open the "Arguments" tab
- Add The following to the "VM arguments":
-Djava.util.logging.config.file=/usr/share/tomcat-8/conf/logging.properties
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager- JAXB marshalling issues
Invalid content was found starting with element 'xxx:xxx'. One of '{"xxx":xxx}' is expected
Interceptor for {http://www.xxx.nl/xxx/service}xxx#{http://www.xxx.nl/xxx/service}xxx has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Marshalling Error: cvc-complex-type.2.4.a: Invalid content was found starting with element 'erf:DierSoort'. One of '{"http://www.xxx.n…- Het beste van twee werelden, JSF en AngularJS
Restfull JSF of AngularJS beans?
Het beste van twee werelden
- Restfull access to JSF ManagedBeans
With the rising of the popularity of REST with JSON, JSF becomes a bit of a hassle in situations with mixed technologies. JSF @ManagedBean's are not accessable through REST.
By adding a REST service that accesses the JSF beans this can be solved. Problem is that the REST has no JSF context and so can't access the @ManagedBean's. But current JSF also works with CDI @Named beans and those…
- Use Webjars in JSF
When using webjars in jsf like:
<h:outputScript id="angular" library="webjars" name="jquery/2.1.4/jquery.js" target="head"/>
You might notice that the version number of the resource is in the tag. This is an annoyance because every time the version is upgraded, the xhtml pages and @ResourceDependency uses must be updated.
Better is to n…
- Trust all certificates with CXF
In development environments it is handy if CXF soap calls over HTTPS don't complain about invalid certificates. In https.get java code this is done with
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;- "a |= b" differs from "a = a || b;"
This runs without problem:
Integer a = null;
boolean error = true;
error = error || (a.intValue() > 0);But this gives an NPE:
Integer a = null;
boolean error = true;
error |= (a.intValue() > 0);This is because |= is bitwise or and || is logical or. A boolean could technica…
- org.apache.jasper.JasperException: java.lang.IllegalStateException: No Java compiler available
To compile JSP pages Tomcat needs a compiler.
/usr/share/eclipse-ecj/ecj.jar
needs to be in the tomcat classpath.In Gentoo this can be done (for tomcat-8) in /etc/conf.d/tomcat by adding:
TOMCAT_EXTRA_CLASSPATH="/usr/share/tomcat-servlet-api-3.1/lib/servlet-api.jar:/usr/share/tomcat-servlet-api-3.1/lib/jsp-api.jar:/usr/share/tomcat-servlet-api-3.1/lib/el-api.…
- DevOxx Antwerpen 2016