How many times did you have to use java enums in your JPA/Hubernate entities ? Yes, instead of having some relations with reference-tables, which are some sort of dictionaries, you wrote simple field with varchar type Something like class Model with RowStatus enum RowStatus is used to detemine whether row is deleted from the system, or row is active.It seems, that this should be enough to have no problems while using this functionality. But there is one potential problem: When we set enum in our system, we made a contract, that we will send only values from RowStatus enum. But how about updating data outside our system ? For example, system administrator of your database made some critical update and committed some critical bug - instead of values from RowStatus - ACTIVE, DELETED he updated row with syntax error - DELITED. From now on, when Hibernate will try to map such row - he will throw an exception. That’s an issue. Possible solutions ? The only solution that I can offer you is that you will controll adding your data on database. You can use database enums, constraints, triggers, etc… I choosed postgres enums. To add such, you simply need...
How many times did you experienced issue, when you need to clean your database from unused data ?For example, you have a qa server with thousands of rows, which you don’t need anymore, so it’s time to delete them. To clean up your database, someone call separate scripts for each table, someone create-drops database.I decided to delete all tables. To remove all rows, you can use maven sql plugin, which has powerful possibilities for doing work with sql. First of all, if you have your maven application, I would reccomend to create separate module for sql. If you don’t want to do this, just leave it as it is in your root pom.xml. You will need to add Maven Sql Plugin. Then, you need to map execution to install goal. You will need to create resource folder.This will be the place, where you will store your scripts. Before we start I don’t want anyone to think, that such module is the best place for storing your database schemas creation.For this purposes there is a good framework called liquibase - it saves migration history and can surely know, what should be updated, and what should not. Such module is always good...
It has been more than two years since I first acquainted with Spring Dependency Injection technology. At first, I didn’t understood what it was, but after few weeks I realized what powerful instrument do I have. From that time I started to love this type of object instantiation and I really don’t want to instantiate objects in some other way. But today I want to represent you a new framework for bean instantiation - Google Guice. So, how to try this Google Guice dependency injection framework ? First of all, open your Eclipse/InteliJIDEA IDE and create maven project: write groupId, artifactId and other things. After that, go to your pom.xml file and add additional dependency: Then, you should create interface NotificationService: We will have multiple implementations of above service to show posibillities of Google Guice Email service is one of the implementations of NotificationService One thing that I noticed is that Google Guice has it’s own @Singleton annotation - from JSR330. Google Guice 3.0 added the support for JSR-330 and we can use annotations from com.google.inject or javax.inject package. Next, we will create second implementation of NotificationService - FacebookService: Consumer class Since we are implementing dependency injection in our application,...
You all know, that spring supports xml namespaces for defining custom bean definition. For example, if you want to set mvn annotation driven benavior, you can write such code in your xml As you noticed, there is no <bean … /> in this piece of code, but there is So, who is responsible for handling this namespaces? Answer is: NamespaceHandler For example, here is AnnotationDrivenBeanDefinitionParser implementation. Every Spring namespace has an associated NamespaceHandler implementation. The namespace schemas are mapped to schema files inside Spring JARs in various spring.schemas files. The XML schema namespaces are also mapped to handler classes in spring.handlers files (several as each Spring JAR might introduce different namespaces). For your convenience here is a list of most common namespaces: Spring core aop - AopNamespaceHandler c - SimpleConstructorNamespaceHandler cache - CacheNamespaceHandler context - ContextNamespaceHandler jdbc - JdbcNamespaceHandler jee - JeeNamespaceHandler jms - JmsNamespaceHandler lang - LangNamespaceHandler mvc - MvcNamespaceHandler oxm - OxmNamespaceHandler p - SimplePropertyNamespaceHandler task - TaskNamespaceHandler tx - TxNamespaceHandler util - UtilNamespaceHandler Spring Security security - SecurityNamespaceHandler oauth - OAuthSecurityNamespaceHandler Spring integration int - IntegrationNamespaceHandler amqp - AmqpNamespaceHandler event - EventNamespaceHandler feed - FeedNamespaceHandler file - FileNamespaceHandler ftp - FtpNamespaceHandler gemfire - GemfireIntegrationNamespaceHandler groovy - GroovyNamespaceHandler...
I position myself as backend developer, but I truly undestand, that I should know more about frontend world. So, by this post, I will start investigating frontend world. This time I will try angular.js - popular framework for building responsive web applications. Notice, that raw angular.js withour any thirdparty libraries is not so powerful, so I will be using Yeoman, Grunt and Bower in this article for convenient work. Expectation This tutorial will cover: Generating of bare angular.js project. Use Grunt to make testing Use Grunt to deploy application Use Bower to add thirdparty plugins Making some little changes to our application. I assume that you have already installed npm package manager. Prerequisites To be confident during this tutorial I recommend you to have the following skills and resources available: Basic knowledge of command line node.js and npm Knowledge of HTML, CSS, JS Ready, and tested Vanilla JS framework :D (Just joke) Resources You can find this project on his GitHub page Installation Before installation, I should say some words about setting up npm. When I first downloaded and installed npm on OS X and tried to configure project from various tutorials - I received plenty of permission exceptions in...