Wednesday, October 6, 2021
Leveraging Java 17 with Micronaut
Monday, May 10, 2021
What is a Testable Unit?
Last week I had a conversation with my good friend, John Hubb, about the various philosophies of TDD (Test Driven Development). This harkened me back to the halcyon days of my ACCA/ARGON lectures at Concordia where I met James Coplien, and his various musings about Unit Testing, TDD, BDD (Behavior Driven Development) and Agile methodologies.
The stand-out observation for me was the question, "What is a testable unit?" Modern developers, especially in object-oriented languages, tend to think every public class is the testable unit. Coplien challenges this notion, to think about functional units of code, with externally verifiable expectations, are the unit, and around which quality unit tests will congregate. Think business expectations, e.g. "Given X, when Y, then Z," and not "When I invoke this public function with A, it should return B."
https://rbcs-us.com/documents/Why-Most-Unit-Testing-is-Waste.pdf
"Tests should be designed with great care. Business people, rather than programmers, should design most functional tests. Unit tests should be limited to those that can be held up against some 'third-party' success criteria."
-- James Coplien, Why Most Unit Testing is Waste
Thursday, November 14, 2013
Adventures in marshalling multiple Java class objects from a custom database query in Spring JPA Hibernate
THE SETUP
I am using Hibernate via Spring JPA to marshal two database tables to POJOs in my Java application. 99% of the time it is perfectly sufficient to use the Spring JPA standard call to EntityManager#createQuery() to retrieve database records and marshal them to the appropriate List<Class> collection.In this particular example I have the following two classes:
@Entity
public class Library {
@Id
private String id;
@Column
private String name;
@OneToMany(fetch=javax.persistence.FetchType.LAZY)
@JoinColumn(name="id")
private List<Book> books;
....
}
@Entity
public class Book {
@Id
private String bookId;
private String name;
private String libraryId;
....
}
Then in the corresponding HQL query you can simply write:
SELECT DISTINCT library
FROM Library library
LEFT JOIN FETCH library.books
And results from createQuery().getResultsList() would be returned as a convenient java object collection like so:
List<Library> libraries = entityManager.createQuery(hql).getResultsList();
THE DILEMMA
We use Sybase. Sybase is great, as long as your table statistics are up-to-date. So if you can imagine with me a world where statistics haven't been updated in over 6 months, and you have a scenario where explicitly specifying an index can mean the difference of tens of thousands of physical or logical reads. RE: PERFORMANCE.But hibernate doesn't let you specify index hints in HQL, nor add them to the Query object after the fact. I also wanted to avoid modifying the existing entity models, so no cheating and changing fetch.LAZY to fetch.EAGER for a single use-case.
SELECT library.*, book.*
FROM Library library (index idx_library_pk)
LEFT JOIN Book book (index idx_book_library_id)
ON (library.Id = book.libraryId)
POTENTIAL SOLUTIONS... (that didn't work)
SELECT book.*
FROM Library library (index idx_library_pk)
LEFT JOIN Book book (index idx_book_library_id)
ON (library.Id = book.libraryId)
WHERE library.Id = ?
THE SOLUTION
Session session = (Session)entityManager.getDelegate();
SQLQuery query = session.createSQLQuery(sql);
SQLQuery query = session.createSQLQuery(sql) .addEntity( "library", Library.class );
SQLQuery query = session.createSQLQuery(sql) .addEntity( "library", Library.class ) .addJoin( "book", "library.books" );
SQLQuery query = session.createSQLQuery(sql) .addEntity( "library", Library.class ) .addJoin( "book", "library.books" ) .addEntity( "library", Library.class ) .setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );
List<Library> libraries = query.list();
SUMMARY
Friday, January 25, 2013
It's the little things that make me hate Solaris
*/5 * * * * ~/my-awesome-script.shBut in Solaris, trying to load this into your crontab generates a syntax error. Instead, you are expected to do something like this:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * ~/my-awesome-script.shWhy? Because Solaris 10 is still running a cron that's older than dirt. It's the little things that are starting to make me really hate Solaris.
Friday, January 18, 2013
Reflections on "A Memory of Light", the last novel in The Wheel of Time
A little over fifteen years ago +Jason Christ introduced the epic WoT series to a skinny Freshman student who had just started working together at a small University tech department. Jason carried a hefty hardback, and the characteristic cover-art of Darrell K. Sweet caught my curiosity, as I had read and loved the Lord of the Rings series by J.R.R. Tolkien since my mother had read to me The Hobbit as a small child. While I was a bit skeptical that any other author could come close to the same depth of character and the scope of their world and plots, I took the recommendation and dove into the first 6 novels that were available at the time. There may have been a few hundred slow pages in the middle, but overall Robert Jordan's vision well met the expectations set by the truly great first volume, "The Eye of the World".
To avoid being too spoiler-ish, for now I will refrain from jumping into a critique of specific plot points in AMoL. But I can say that it was gripping, emotional, mostly satisfying, and sometimes intentionally exhausting end to the series. Brandon Sanderson did a great job of picking up where Robert Jordan left off, and crafted a balanced, well-paced and compelling conclusion to the struggles of characters that readers have seen grown from small-country-folk into complex personalities of nearly deistic powers. The conclusion of the Last Battle between the forces of good and evil felt genuinely climactic, while allowing for a good resolution to *most* of the plot lines that had been building across thousands of pages and in our imaginations for years.
I certainly looked forward to reading this last entry in the series, but to paraphrase Robert Jordan it did not feel as much like The Ending, but it was an ending, and I hope that The Wheel of Time might someday come back around to us again.
Thursday, November 1, 2012
New city, new focus
So as usual, thanks for following geekmode.com, and stay tuned for more!
Thursday, September 27, 2012
Android 4.1 Jelly Bean coming to the ASUS Transformer Pad Infinity TF700 and Prime TF201
ASUS stated yesterday that the official Android 4.1 Jelly Bean update will be rolling out to two of the ASUS Transformer Pads over the next two days.
There are reports over at XDA that the update has been rolling out to the ASUS Transformer Pad Prime TF201 starting early this morning.
I very recently picked up the ASUS Transformer Infinity TF700, and I absolutely love it, but felt a bit snubbed that the TF300 received the Jelly Bean update before my newer model tablet. It really is a slick device, and nearly a laptop replacement with the attachable keyboard-dock. I will be very excited to get the Jelly Bean goodness of Google Now and Butter UI running on my Infinity when it rolls out tomorrow.
UPDATE: XDA is reporting that the Jelly Bean update started rolling out to TF700's this morning. I can confirm this, as I finished installing the update myself minutes ago. I will try to post my impressions of the update soon!
--
Original Press Release from: https://www.facebook.com/ASUS
Via: http://www.talkandroid.com/133753-asus-confirms-jelly-bean-for-transformer-prime-and-transformer-pad-infinity-coming-soon/