Creating slim Database Projections using JPA2 Constructor Expressions

One common question that you may encounter one day when using object-relational-mapping in your application is how to slim down data that you’re retrieving from the persistence layer down to a specific subset for your use-case in an efficient manner and without using complex additional mapping frameworks. In some situations you might declare lazy loaded fields but another approach that I’d like to share with you here are JPA2 constructor expressions. ...

April 14, 2013 · 9 min · 1744 words · Micha Kops

Snippet: XML-Pull-Parser with XPP3

When there is XML to be parsed sometimes we’re chosing a DOM parser, sometimes a SAX parser and sometimes we’re using an XML pull parser, especially on Android. The following short snippet shows how to use the xpp3 xml pull parse to fetch some information in xml format from a public issue tracker and to extract issue details. Adding Dependencies Just one dependency needed here: xpp3 SBT Simply use the following build.sbt ...

December 28, 2012 · 3 min · 459 words · Micha Kops

Contract-First Web-Services using JAX-WS, JAX-B, Maven and Eclipse

Using the contract-first approach to define a web service offers some advantages in contrast to the code-first approach. In the following tutorial we’re going to take a look at some details of this approach and we’re going to implement a real SOAP service using JAX-WS, Maven and the Eclipse IDE. Finally we’re going to run our service implementation on an embedded Jetty instance and we’re going to take a look at soapUI and how to test our service using this neat tool. ...

August 23, 2011 · 9 min · 1777 words · Micha Kops

Google Docs Snippets

Importing XML Data in Google Sheets Use the XMLIMPORT function The syntax is XMLIMPORT("url", "xpath") e.g. for importing an XML sitemap =IMPORTXML("https://www.hascode.com/sitemap.xml", "//\*[local-name()='url']/*[local-name()='loc']") Select the preceding cell in Google Sheets =INDIRECT(ADDRESS(ROW()-1,COLUMN()) Create a Todo List Counter in Google Sheets Each empty cell is a todo, each filled cell is done. That allows us the following output, that counts all preceding cells of each type: ="Done: "&(COUNTA(B3:INDIRECT(ADDRESS(ROW()-1,COLUMN())))&" Todo: " &COUNTIF(B3:INDIRECT(ADDRESS(ROW()-1,COLUMN())),"")) This outputs a label like "Done: 35 Todo: 142" ...

March 1, 2010 · 1 min · 78 words · Micha Kops

Java Snippets

Remote Debug a Pod’s Java Process Simple steps for remote debugging a Java process running on a k8 pod: Edit deployment and add the following parameters to the Java start line: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005 Also add the following port mapping at the section container → ports in the deployment: - containerPort: 5005 protocol: TCP Safe, wait for the new pods and then add a port forward for port 5005 for this pod: kubectl port-forward podname 5005 ...

March 1, 2010 · 13 min · 2583 words · Micha Kops

Liquibase Snippets

Precondition: Postgres Schema exists Using this precondition should run a migration only if the schema my_schema exists. <preConditions onFail="CONTINUE"> <sqlCheck expectedResult="1"> SELECT COUNT(1) FROM information_schema.schemata WHERE schema_name = 'my_schema'; </sqlCheck> </preConditions> Resources: https://docs.liquibase.com/concepts/changelogs/preconditions.html

March 1, 2010 · 1 min · 33 words · Micha Kops

Spring Boot Snippets

Define and Configure Log Groups This allows to configure a group of loggers at the same time Define a log group named myaspect with two packages application.properties logging.group.myaspect=com.hascode.package1,com.hascode.package2 Configure the log group and set all loggers to level TRACE application.properties logging.level.myaspect=TRACE This is also possible as parameter on startup java -Dlogging.level.myaspect=TRACE myapp.jar Use JUnit 5 with Spring Boot Use newer versions of Surefire and Failsafe plugins: <properties> [..] <maven-failsafe-plugin.version>2.22.0</maven-failsafe-plugin.version> <maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version> </properties> ...

March 1, 2010 · 6 min · 1082 words · Micha Kops

XML Snippets

Ignore Namespaces in XPath Query e.g. Query for all xxx nodes ignoring their namespace: xmllint --xpath '//*[local-name()="xxx"]' input.xml An example parsing URLs from a sitemap XML. The URLs are located in //url/loc where all nodes are bound to the namespace http://www.sitemaps.org/schemas/sitemap/0.9. The following query ignores the namespace xmllint --xpath '//*[local-name()="url"]/*[local-name()="loc"]' sitemap.xml Pretty Print XML in the Console using xmllint echo '<blogs><blog url="https://www.hascode.com/">hasCode.com</blog></blogs>' | xmllint --format - <?xml version="1.0"?> <blogs> <blog url="https://www.hascode.com/">hasCode.com</blog> </blogs> ...

March 1, 2010 · 1 min · 99 words · Micha Kops