Wednesday, April 25, 2012

Spring Annotations


Context Configuration Annotations :
These annotations are used by Spring to guide creation and injection of beans

@Required indicates that the affected bean property must be populated at configuration time Method
@Autowired Marks a constructor, field, setter method or config method as to be autowired by Spring's dependency injection facilities. Constructor, Field,
Method
@Inject can be used in place of Spring's @Autowired. does not have a required property

@Qualifier @Qualifier which takes a string property to discriminate among multiple injection candidates and can be placed on annotations as well as types, fields, methods,
constructors, and parameters.
Field, Parameter,
Type,
Annotation Type
@Configurable Marks a class as eligible for Spring-driven configuration Type
@Order Annotation that defines ordering Type, Method,
Field
@Scope Specifies the scope of a bean, either singleton, prototype, request, session,or some custom scope. Type







Spring Java Configuration :

@Configuration Indicates that a class declares one or more Bean methods and may be processed by the Spring container to generate bean definitions Type
@Bean Indicates that a method produces a bean to be managed by the Spring container. Method
@Import allows for loading @Bean definitions from another configuration class: Type
@ExternalValue same as @Value annotation and use of Spring EL. Method,
Field
@ImportXml allows for loading bean definitions from another xml Type
@AnnotationDrivenConfig enable the @Autowired annotation Type
@ComponentScan Spring's @Service and @Repository stereotype annotations are each meta-annotated with Type
@AnnotationDrivenTx Like Spring XML's <tx:annotation-driven> element, @AnnotationDrivenTx expects the presence of a bean named transactionManager Type
@AspectJAutoProxy detects any@Aspect beans and generates proxies as appropriate to weave the advice methods in those aspectsagainst other beans in the containe Type
@MBeanExport equivalent to Spring XML's <context:mbean-export/> element, JavaConfig provides the @MBeanExport annotation. Type
@DependsOn Beans on which the current bean depends. Type
@Primary indicates that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency. methods
annotated with Bean.
@Lazy Indicates whether a bean is to be lazily initialized. Type
@ImportResource Like @Import Type,
Method
@Async Annotation that marks a method as a candidate for asynchronous execution. Can also be used at the type level, in which case all of the type's methods are considered as asynchronous. Type

Stereotyping Annotations :

These annotations are used to stereotype classes with regard to the application tier that they belong to. Classes that are annotated with one of these annotations will automatically be registered in the Spring application context if <context:component-scan> is in the Spring XML configuration.

@Component Generic stereotype annotation for any Spring-managed component. Type
@Controller Stereotypes a component as a Spring MVC controller Type
@Repository Stereotypes a component as a repository. Also indicates that SQLExceptions thrown from the component’s methods should be translated into Spring DataAccessExceptions. Type
@Service Stereotypes a component as a service Type


Spring MVC Annotations:

These annotations were introduced in Spring 2.5 to make it easier to create Spring MVC applications,<context:component-scan> is required

@PathVariable Annotation which indicates that a method parameter should be bound to a URItemplate variable. Supported for RequestMapping annotated handler methods in Servlet environments. Parameter
@InitBinder Annotation that identifies methods which initialize the WebDataBinder which will be used for populating command and form object arguments of annotated handler methods. Method
@ModelAttribute @ModelAttribute is a Spring-MVC specific annotation used for preparing the model data. It is also used to define the command object that would be bound with the HTTP request data. The annotation works only if the class is a Controller class. ModelAttribute can be applied on both methods as well as method-parameters. It accepts an optional "value", which indicates the name of the attribute. If no value is supplied to the annotation, then the value would be defaulted to the return type name in case of methods and parameter type name in case of
method-parameters.

The way Spring processes this annotation is, Before invoking the handler method, Spring invokes all the methods that have @ModelAttribute annotation. It adds the data returned by these methods to a temporary Map object. The data from this Map would be added to the final Model after the execution of the handler method.Then it prepares to invoke the the handler method. To invoke this method, it has to resolve the arguments. If the method has a parameter with @ModelAttribute, then it would search in the temporary Map object with the value of @ModelAttribute. If it finds, then the value from the Map is used for the handler method parameter.It it doesn't find it in the Map, then it checks if there is a SessionAttributes annotation applied on the controller with the given value. If the annotation is present, then the object is retrieved from the session and used for the handler method parameter. If the session doesn't contain the object despite of the @SessionAttributes, then an error is raised.If the object is not resolved through Map or @SessionAttribute, then it creates an instance of the parameter-type and passes it as the handler method parameter. Therefore, for it to create the instance, the parameter type should be a concrete-class-type (interfaces or abstract class types would again raise an error).Once the handler is executed, the parameters marked with @ModelAttributes are added to the Model.
Parameter
Method
@RequestMapping Maps a URL pattern and/or HTTP method to a method or controller . Method, Type
@RequestParam Binds a request parameter to a method parameter. Parameter,
Method
@SessionAttributes Specifies that a model attribute should be stored in the session. Type
@RequestHeader Allows a method parameter to be bound to a request header Parameter
@CookieValue Allows a method parameter to be bound to the value of an HTTP cookie Parameter
@ExceptionHandler

Method


Spring Validation Annotation :

@NumberFormat This annotation allows either a number style or pattern to be specified Field
@DateTimeFormat format a java.util.Date as required Field
@NotNull

Field
@Size

Field
@Min

Field
@Valid The Validator instance invoked when a @Valid method argument is encountered may be configured Parameter


Spring Expression Language (SpEL) :

@Value
Declares transactional boundaries and rules on a bean and/or its methods.
Method, Type

Transaction Annotations :
require <tx:annotation-driven>

@Transactional
Declares transactional boundaries and rules on a bean and/or its methods.
Method, Type

Aspect Annotations :
<aop:aspectj-autoproxy> required

@Aspect Declares a class to be an aspect. Type
@After Declares a method to be called after a pointcut completes. Method
@AfterReturning Declares a method to be called after a pointcut returns successfully. Method
@AfterThrowing Declares a method to be called after a pointcut throws an exception. Method
@Around Declares a method that will wrap the pointcut. Method
@Before Declares a method to be called before proceeding to the pointcut. Method
@DeclareParents Declares that matching types should be given new parents,that is, it introduces new functionality into matching types. Static Field
@Pointcut the method serving as the pointcut signature must have a void return type. method must have an empty method body and must not have any throws clause .
upported Pointcut Designators are execution,within,this, target, args, @target, @args,@within,@annotation
Method


JMX Annotations :
<context:mbean-export/> required

@ManagedAttribute Used on a setter or getter method to indicate that the bean's property should be exposed as a MBean attribute Method
@ManagedNotification Indicates a JMX notification emitted by a bean. Type
@ManagedNotifications Indicates a JMX notifications emitted by a bean. Type
@ManagedOperation Specifies that a method should be exposed as a MBean operation. Method
@ManagedOperationParameter Used to provide a description for an operation parameter. Method
@ManagedOperationParameters Used to provide a descriptions for an operation parameter. Method
@ManagedResource Specifies that all instances of a class should be exposed a MBeans. Type


JSR-250 ANOTATION :

@Resource Spring also supports injection using the JSR-250 @Resource annotation on fields or bean property setter methods Method,Field
@PostConstruct indicates a method to be invoked after a bean has been created and dependency injection is complete. Used to perform any initialization work necessary. Method
@PreDestroy Indicates a method to be invoked just before a bean is removed from the Spring context. Used to perform any cleanup work necessary. Method


Testing Annotations :

@AfterTransaction Used to identify a method to be invoked after a transaction has completed. Method
@BeforeTransaction Used to identify a method to be invoked before a transaction starts. Method
@ContextConfiguration Configures a Spring application context for a test. Type
@DirtiesContext Indicates that a method dirties the Spring container and thus it must be rebuilt after the test completes. Method
@ExpectedException Indicates that the test method is expected to throw a specific exception. The test will fail if the exception is not thrown. Method
@IfProfileValue Indicates that the test class or method is enabled for a specific profile configuration. Type, Method
@NotTransactional Indicates that a test method must not execute in a transactional context. Method
@ProfileValueSourceConfiguration Identifies an implementation of a profile value source. The absence of this annotation cause profile values to be loaded from system properties Method
@Repeat Indicates that the test method must be repeated a specific number of times. Method
@Rollback Specifies whether or not the transaction for the annotated method should be rolled back or not. Method
@TestExecutionListeners Identifies zero or more test execution listeners for a test class. Type
@Timed Specifies a time limit for the test method. If the test does not complete before the time has expired, the test will fail. Method
@TransactionConfiguration Configures test classes for transactions, specifying the transaction manager and/or the default rollback rule for all test methods in a test class. Type
@RunWith specifies the Spring configuration to load for this test fixture Type
@Test Indicate test Method


Friday, October 7, 2011

RabbitVCS icon is missing in contex menu

In my last post try to explain how to install  RabbitVCS in ubuntu. i later when i start to use Ubutu10.10 found that all the steps are fine for Ubutu10.4 and i need a fix for it. after spending a lot I found that Gnome in  10.10 is different. see that it's a bug in the extension code, but you might be able to work  around it if you disable "show attributes" in the settings

try this command to enable:

gconftool-2 --type boolean --set /desktop/gnome/interface/menus_have_icons  true

i hope this time RabbiVcs will appear in you Context Menu.

Tuesday, April 5, 2011

New jQuery version into Liferay Portal

Copy the file "top_head.jsp" located in folder "liferay-portal-src-[version]\portal-web\docroot\html\common\themes\" into the EXT-folder 'liferay-portal-ext\ext-web\docroot\html\common\themes\'

>Open the copied file in your EXT
>Add the following lines:
<script  src="/html/js/jQuery1.3.2/jquery1.3.2.js" type="text/javascript"></script>
<script  src="/html/js/jQuery1.3.2/ui.jquery1.7.js" type="text/javascript"></script>
<script >="" src="/html/js/jQuery1.3.2/ui.stars.js" type="text/javascript"></script>

<script type="text/javascript">
var $132 = jQuery.noConflict(true);
 </script>
> Now you can access jQuery 1.3.2'.

Saturday, December 25, 2010

how to use ZTE Modem in linux


To intall Citycell ZTE Modem in linux you should follow following steps

  1. Plug Modem to PC
  2. open terminal and use lsusb command which will show usb device plugged at the time in my case I get following out put
#lsusb
    Bus 007 Device 002: ID 0a5c:2101 Broadcom Corp. Bluetooth Controller
    Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 006 Device 002: ID 15d9:0a4c Trust International B.V.
    Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 005 Device 003: ID 19d2:fff1 ONDA Communication S.p.A.
    Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 002: ID 064e:a101 Suyin Corp. Acer CrystalEye Webcam
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
bold line is my ZTE Modem from that output I get vendor is 19d2 and product id fff1

  1. now load driver using modprobe command
    # sudo modprobe usbserial vendor=0x19d2 product=0xfff
  2. now edit wvdial config
    #sudo gedit /etc/wvdial.conf
    insert followin lines
    [Dialer Defaults]
    Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    Modem Type = Analog Modem
    ISDN = 0
    Init1 = ATZ
    Modem = /dev/ttyUSB0
    Baud = 9600
    [Modem0]
    Init1 = ATZ
    SetVolume = 0
    Modem = /dev/ttyUSB0
    Baud = 230400
    FlowControl = Hardware (CRTSCTS)
    Dial Command = ATDT
    [Dialer citycell]
    Stupid Mode = 1
    Inherits = Modem0
    Password = waps
    Username = waps
    Phone = #777
  3. now dial you moden using following command
    #sudo wvdial citycell
If you do not have wvdial installed in you pc then install follwing:
  1. wvdial_1.60.1
  2. libxplc0.3.13_0.3.13-1
  3. libwvstreams4.4-base
  4. libwvstreams
  5. libuniconf

Thursday, December 23, 2010

Ubuntu USB file transfer is slow

Some time you might experence Ubuntu USB file transfer is slow then you can try following solution
$ sudo gedit /etc/default/grub

edit as following
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash pci=noacpi pci=routeirq"

then reload
$ sudo grub-mkconfig -o /boot/grub/grub.cfg


This fix might not work for every one.

RabbitVCS an alternative to TortoiseSVN

TortoiseSVN is not avail able for linux but we can use rabbitVCS as an alternative to Tortoise. Check following to install rabbitVCS in ubuntu.

Add repository source
$ sudo add-apt-repository ppa:rabbitvcs/ppa

update source list
$ sudo apt-get update

install rabbitvcs core
$ sudo apt-get install rabbitvcs-core

Install nautilus,thunar,gedit and command line plugins
$ sudo apt-get install rabbitvcs-nautilus rabbitvcs-thunar rabbitvcs-gedit rabbitvcs-cli


rabbitVCS installed in your ubutu system. Enjoy it.

If you can't see rebbitVCS in you context menu check this link

Wednesday, September 8, 2010

Hibernate Basics


Hibernate is an open source object relational mapping library. Hibernate provides a solution to map database tables to a class. It copies one row of the database data to a class. In the other direction it supports to save objects to the database. Objects are transformed to one or more tables.


Hibernate solves Object-Relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions.


Basic classes used while working with Hibernate are:
§         SessionFactory
§         Session
§         Transaction

SessionFactory
A thread safe, immutable cache of compiled mappings for a database. The SessionFactory is created from a Configuration object.

The SessionFactory is an expensive object to create. It like is usually created during application start up. However, unlike the Configuration object, it should be created once and kept for later use. The SessionFactory object is used by all the threads of an application.

SessionFactory object is created per database. Multiple SessionFactory objects (each requiring a separate Configuration) are created when connecting to multiple databases.

Session
A single-threaded, short-lived object representing a conversation between the application and the persistent store.  
Session objects are not thread safe. Therefore, session objects should not be kept open for a long time. Applications create and destroy these as needed.  Typically, they should be created to complete a single unit of work, but may span many units.


Transaction

Transaction object created from Session. Single-threaded, short-lived object used by the application. A Transaction represents a unit of work with the database (and potentially other systems). Transactions in Hibernate are handled by an underlying transaction manager and transaction.

Instance states

An instance of persistent classes may be in one of three different states

Transient:
The instance is not, and has never been associated with any persistence context (A persistence context is a set of entity instances in which any persistent entity identity is unique). It has no persistent identity.

Persistent:
The instance is currently associated with a persistence context. It has a persistent identity (primary key value) and, perhaps, a corresponding row in the database.

Detached
The instance was once associated with persistence context, a detached instance is an has been persistent, but its Session has been closed. The reference to the object is still valid, and the detached instance might even be modified in this state.  detached instance can be reattached to a new Session at a later point in time, making it (and all the modifications) persistent again. Can be reattachment of detached instances using the session.update() or Session.merge()  methods

Session and transaction scopes

Session-per-operation: open and close a Session for every simple database call in a single thread

Session-per-request: The most common pattern in a multi-user client/server application. In this model, a request from the client is send to the server (where the Hibernate persistence layer runs), a new Hibernate Session is opened, and all database operations are executed in this unit of work. Once the work has been completed (and the response for the client has been prepared), the session is flushed and closed. 

Open Session in View: scope of a Session and database transaction until the "view has been rendered"

Session-per-conversation: The Hibernate Session may be disconnected from the underlying JDBC connection after the database transaction has been committed, and reconnected when a new client request occurs.

 


Locking:
There are two common strategies when dealing with updates to database records, pessimistic locking and optimistic locking.

Optimistic locking is a strategy where you read a record, take note of a version number and check that the version hasn't changed before you write the record back. Optimistic assumes that nothing's going to change while you're reading it.

Pessimistic Lock is where you lock the record/data for your exclusive use until you have finished with it so that no one can access it in between.

 


Hibernate Automatic Dirty Check:


Hibernate automatically detects object state changes in order to synchronize the updated state with the database, this is called dirty checking. An important note here is, Hibernate will compare objects by value, except for Collections, which are compared by identity. For this reason you should return exactly the same collection instance as Hibernate passed to the setter method to prevent unnecessary database updates.

Hibernate can perform dirty checks only when the objects are loaded and changed in the scope of a single Session

AWS Services

      1.         Identity Access Management (IAM): Used to control Identity (who) Access (what AWS resources).                   1....