Agility, Java programming, New technologies and more…
  • rss
  • Home
  • Management
  • Agile Programming
  • Technology
  • Linux
  • Event
  • Android app
  • Contact
  • About the author
  • English
  • Francais

Manage a sequence database with Spring

Fabian Piau | Sunday September 22nd, 2013 - 07:36 PM
  • Print
  • Twitter
  • LinkedIn
  • Facebook
  • Pocket

 Version française disponible

Note
It is better to let Hibernate manage technical identifiers (primary keys). But, if you need to generate a business identifier, an Hibernate generator can be not enough. In my case, my business identifier was not generated all the time, I mean its value could also be set manually. Unfortunately, when the new element is inserted in database (unless I’m mistaken, but I did not find…), the generator always overwrites the value of my business identifier with a generated one.

Database

A small and useful note (very technical) if you use Spring in your project.

You want to retrieve / increment the value of a database sequence and the Sequence Generator of Hibernate does not meet your needs (see the note).

Rather than go through a DAO with Hibernate code (or worse use JDBC), Spring can do it for you in 2 minutes…


  • To do this, simply declare a new bean in the Spring configuration of your project:
          <bean id='mySequenceIncrementer' class='org.springframework.jdbc.support.incrementer.H2SequenceMaxValueIncrementer'>
    	      <property name='dataSource' ref='<Name of your datasource>' />
    	      <property name='incrementerName' value='<Name of your sequence>' />
          </bean>
    

    Note: there are several implementations of incrementer for different databases (I use H2DB but MySQL, PostgreSQL, Oracle, etc. are also available.)

  • Inject this bean in the class of your choice.
  • And now, you can do:
    final Long newIdSequence = mySequenceIncrementer.nextLongValue();
    


Tested and approved!

Related posts

Java EE vs SpringJava EE & CDI vs. Spring springQCon London 2016 – Spring Framework 5 – Preview & Roadmap
Comments
5 Comments »
Categories
Agile programming
Tags
database, hibernate, sequence, spring
Comments rss Comments rss

Optimize your website for print in 5 minutes

Fabian Piau | Sunday September 15th, 2013 - 01:23 PM
  • Print
  • Twitter
  • LinkedIn
  • Facebook
  • Pocket

 Version française disponible

Is it really useful? I think so! People who print pages on the Internet are probably more numerous than one might think. And it takes 5 minutes, so just do it!


Printer

Let’s take a screenplay (almost) like in Hollywood movies:

Mister Nextdoor will not have access either to Internet or to his computer this weekend and did not have enough time to read a long article, but very important for what’s happening next. So he decides to print it to read it later on the plane (yes, Mr. Nextdoor is lucky, he is going on vacation). Once the printing is done, he realizes a little jaded (because yes it’s not the first time) that absolutely all the internet page came out. He ends up with 7 printed pages of an article that needed maybe 3… The menu, related articles, social media sharing links… Everything is there! Anyway, Mr. Nextdoor is relieved, he will be able to read his article “How to conquer your fear of flying?”.

To continue on the same idea of the article explaining how to make your site responsive, I will show you how to make your website optimized for print.


Principle is similar by using the CSS language.


You have to declare a dedicated CSS file for printing. In the header of your pages, you have to add a link to this file by specifying “print” for the “media” attribute, unlike others which usually specify the media “all” (screen, printer, etc.). Check out this page to know more about the media types.

In my case, I use a “print.css” file for my blog, so I add this line:

<link rel="stylesheet" href="https://blog.fabianpiau.com/wp-content/themes/freshy2/print.css" type="text/css" media="print">

This CSS style file will be used only in case of printing. Thus, you can use it to remove all unwanted content such as:

  • Header
  • Sidebars
  • Footer
  • Related articles
  • Etc.

Here is an excerpt of my “print.css” file:

@media print {
	.sidebar div div {
		display:none !important;
	}
	#header {
		display:none !important;
	}
	#footer {
		display:none !important;
	}
	.yarpp-related {
		display:none !important;
	}
	.meta {
		display:none !important;
	}
	.wp-pagenavi {
		display:none !important;
	}
	.sharedaddy {
		display:none !important;
	}
	#breadcrumbs {
		display:none !important;
	}
	.navigation {
		display:none !important;
	}
	.noprint {
		display:none !important;
	}
}

Printing guaranteed logo

Note: I use the “!important” keyword to redefine a style already present. The value specified with the “!important” will always overwrite the others.

@media print { [my CSS code here] } is useful to make a CSS code interpretable only in case of printing. If you use this annotation around a piece of CSS code, then you can integrate it into a CSS file used for all media (media="all"). I used both the annotation and the “print” media, just to be sure, but this is not mandatory.


Another (often complementary) solution is to add a dedicated CSS class to hide particular elements when printing. This is useful when the item has no specific attributes (no identifier or a too generic CSS class that we don’t want to hide on the whole page…).

For instance, I have this “noprint” class:

.noprint {
	display:none !important;
}

Now, any element of my site that uses the “noprint” class will be hidden when printed. It cannot be easier!


To see the result in action, you can print this article (consider the planet by doing a print preview or printing as a PDF…).

Related posts

wordpress-hackerTips to make your WordPress website secure Clean browser cacheCSS and Javascript files play hide and seek in browsers’ cache WordPress qTranslateMake your WordPress site multilingual with qTranslate Responsive Web DesignDoing Responsive Web Design: yes, but easily!
Comments
No Comments »
Categories
Agile programming
Tags
css, design, print, printer, mobile computing
Comments rss Comments rss
Page 2 of 3123
Download CarmaBlog App

RSS feeds

  • RSS feed RSS - Posts
  • RSS feed RSS - Comments

Most viewed posts

  • Changing the language in Firefox - 116,369 views
  • Using Google Forms / Drive / Docs to create an online survey - 64,395 views
  • FAQ – Online survey with Google Forms / Drive / Docs - 56,229 views
  • Customizing Gnome 3 (Shell) - 30,805 views
  • The meaning of URL, URI, URN - 18,403 views
  • Java EE & CDI vs. Spring - 15,984 views
  • Open Street Map, better map than Google Maps? - 15,796 views
  • Comparing NoSQL: Couchbase & MongoDB - 14,690 views
  • API, REST, JSON, XML, HTTP, URI… What language do you speak? - 13,728 views
  • First steps with Apache Camel - 13,590 views

Recent Comments

  • Fabian Piau on FAQ – Online survey with Google Forms / Drive / DocsOui, dans Google Forms, vous pouvez empêcher les p…
  • BENECH Fabien on FAQ – Online survey with Google Forms / Drive / DocsBonjour, J'ai crée 1 questionnaire via Forms,…
  • SANKARA TIDIANE on Free online MongoDB trainingJ'aimerai suivre
  • Pauline on FAQ – Online survey with Google Forms / Drive / DocsMerci Fabian, mais le but étant que nos clients pu…
  • Fabian Piau on FAQ – Online survey with Google Forms / Drive / DocsProbablement mais ces options sont en général paya…

Recent posts

  • How to write a blog post? At least my way! - 2 years and 5 months ago
  • Bot Attacks: You are not alone… - 4 years and 3 weeks ago
  • Flagger – Monitor your Canary deployments with Grafana - 4 years and 10 months ago
  • Flagger – Canary deployments on Kubernetes - 4 years and 11 months ago
  • Flagger – Get Started with Istio and Kubernetes - 5 years and 2 weeks ago
  • Expedia CoderDojo in London - 5 years and 9 months ago
  • Volunteering at Devoxx4Kids - 6 years and 1 week ago
  • A Java 11 migration successful story - 6 years and 4 months ago
  • Tips to make your WordPress website secure - 6 years and 7 months ago
  • Devoxx UK 2018 – Day 2 - 6 years and 11 months ago
  • Devoxx UK 2018 – Day 1 - 6 years and 11 months ago
  • Wise, Revolut and Monzo, a small revolution for travelers and expats - 7 years and 3 months ago
  • Autocomplete for Git - 7 years and 11 months ago
  • Swagger, the automated API documentation - 8 years and 2 months ago
  • Microservices architecture – Best practices - 8 years and 7 months ago
Buy me a coffee

Language

  • Français
  • English

Follow me!

Follow me on Linkedin
Follow me on Twitter
Follow me on Stackoverflow
Follow me on Github
Follow me on Rss
Link to my Contact

Email subscription

Enter your email address to receive notifications of new posts.

Tags

.net agile agility android bash best practices blog cache cloud computing conference continuous integration css developer devoxx docker eclipse extreme programming firefox flagger google helm hibernate istio java job jug kubernetes london mobile computing overview performance plugin programmer script security sharing society spring tdd test tool ubuntu windows wordpress

Links

  • Blog Ippon Technologies
  • Blog Publicis Sapient
  • Blog Zenika
  • Classpert
  • CommitStrip
  • Coursera
  • Le Touilleur Express
  • Les Cast Codeurs Podcast
  • OCTO talks !
  • The Twelve-Factor App

Categories

  • Event (15)
  • Linux (3)
  • Management (8)
  • Agile programming (29)
  • Technology (45)

Archives

  • December 2022 (1)
  • April 2021 (1)
  • June 2020 (1)
  • May 2020 (2)
  • July 2019 (1)
  • May 2019 (1)
  • December 2018 (1)
  • October 2018 (1)
  • June 2018 (1)
  • May 2018 (1)
  • January 2018 (1)
  • May 2017 (1)
  • March 2017 (1)
  • October 2016 (1)
  • April 2016 (2)
  • March 2016 (1)
  • November 2015 (1)
  • May 2015 (1)
  • February 2015 (1)
  • December 2014 (1)
  • November 2014 (1)
  • September 2014 (2)
  • August 2014 (1)
  • July 2014 (2)
  • June 2014 (1)
  • April 2014 (1)
  • March 2014 (1)
  • February 2014 (2)
  • January 2014 (1)
  • December 2013 (1)
  • November 2013 (1)
  • October 2013 (3)
  • September 2013 (5)
  • July 2013 (1)
  • June 2013 (1)
  • May 2013 (1)
  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (1)
  • January 2013 (2)
  • December 2012 (2)
  • October 2012 (1)
  • September 2012 (1)
  • July 2012 (1)
  • May 2012 (1)
  • April 2012 (1)
  • March 2012 (1)
  • February 2012 (1)
  • January 2012 (2)
  • December 2011 (1)
  • November 2011 (2)
  • October 2011 (2)
  • September 2011 (1)
  • July 2011 (1)
  • June 2011 (2)
  • April 2011 (1)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • November 2010 (2)
  • September 2010 (1)
  • August 2010 (1)
  • July 2010 (1)
  • June 2010 (1)
  • May 2010 (1)
  • April 2010 (1)
  • March 2010 (1)
  • February 2010 (1)
  • December 2009 (1)
  • November 2009 (1)
  • October 2009 (2)
  • September 2009 (2)
  • August 2009 (3)
  • July 2009 (1)
  • June 2009 (2)
Follow me on Twitter
Follow me on Linkedin
Follow me on Stackoverflow
Follow me on Rss
Link to my Contact
Follow me on Github
 
Fabian Piau | © 2009 - 2025
All Rights Reserved | Top ↑