How to add loading symbol in angular-ui bootstrap typeahead

add in select menu (lov):

typeahead-loading=”isLoading”

add in  style:

.loadinggif
{
background:
url(”)
no-repeat
right center;
}

note: 

use the bellow loading symbol url

url : 

add in html :

div class=”loadinggif” ng:show=”!!isLoading”
Advertisements

difference between @Entity and @Table

@Entity(name = "someThing") => this name will be used to name Entity
@Table(name = "someThing")  => this name will be used to name a table in DB

So in first case your table and entity will have same name, that will allow you to access your table with same name as entity while writing HQL or JPQL.

And in second case while writing queries you have to use the name given in @Entity and name given in @Table will be used to name the table in DB.

so in HQL your someThing will refer to otherThing in DB

list data sorting based on id in java

Using static method :

example:

@Entity
@Table(name = “service_connection”)
@Getter @Setter
@JsonIgnoreProperties({“hibernateLazyInitializer”, “handler”})
public class ServiceConnection implements Serializable {
private static final long serialVersionUID = 1L;

/* Auto Generation Id */
@Id
@GeneratedValue(strategy = GenerationType.TABLE,generator=”autogen”)
@TableGenerator(name = “autogen”, initialValue = 0, allocationSize = 1)
Long id;

public static Comparator IdComparator = new Comparator() {
@Override
public int compare(ServiceConnection o1, ServiceConnection o2) {
return o1.getId().compareTo(o2.getId());
}
};

}

call static method while sorting :

Collections.sort(connectionList, ServiceConnection.IdComparator);

============================================================================

Using class implement the Comparator interface :

example:

public class CustomComparator implements Comparator<CustomObject> 
{
    @Override
    public int compare(CustomObject o1, CustomObject o2) {
        return o1.getId().compareTo(o2.getId());
    }
}

Then you can use the Collections classes Collections.sort() method:

Collections.sort(list, new CustomComparator());

Spring @Scheduled – 4 Ways to Schedule Tasks

Explaining @Scheduled annotation

This annotation is used for task scheduling. The trigger information needs to be provided along with this annotation. You can use the properties fixedDelay/fixedRate/cron to provide the triggering information.

  1. fixedRate makes Spring run the task on periodic intervals even if the last invocation may be still running.
  2. fixedDelay specifically controls the next execution time when the last execution finishes.
  3. cron is a feature originating from Unix cron utility and has various options based on your requirements.

Example usage can be as below:

@Scheduled(fixedDelay =30000)
public void demoServiceMethod () {... }

@Scheduled(fixedRate=30000)
public void demoServiceMethod () {... }

@Scheduled(cron="0 0 * * * *")
public void demoServiceMethod () {... }

To use @Scheduled in your spring application, you must first define below xml namespace and schema location definition in your application-config.xml file.

Above additions are necessary because we will be using annotation based configurations. Now add below definition to enable annotations.

<task:annotation-driven>

Next step is to create a class and a method inside the class like below:

public class DemoService
{
    @Scheduled(cron="*/5 * * * * ?")
    public void demoServiceMethod()
    {
        System.out.println("Method executed at every 5 seconds. Current time is :: "+ new Date());
    }
}

Using @Scheduled annotation would in turn make Spring container understand that the method underneath this annotation would run as a job.  Remember that the methods annotated with @Scheduled should not have parameters passed to them. They should not return any values too. If you want the external objects to be used within your @Scheduled methods, you should inject them into the DemoService class using autowiring rather than passing them as parameters to the @Scheduled methods.

Method 1) Task scheduling using fixed delay attribute in @Scheduled annotation

In this method, fixedDelay attribute is used with @Scheduled annotation. Alternatively, fixedRate can also be used.

A sample class will look like this:

package com.howtodoinjava.service;
import java.util.Date;
import org.springframework.scheduling.annotation.Scheduled;
public class DemoServiceBasicUsageFixedDelay
{
    @Scheduled(fixedDelay = 5000)
    //@Scheduled(fixedRate = 5000)
    public void demoServiceMethod()
    {
        System.out.println("Method executed at every 5 seconds. Current time is :: "+ new Date());
    }
}

And application configuration will look like this:

Method 2) Task scheduling using cron expression in @Scheduled annotation

In this method, cron attribute is used with @Scheduled annotation. Value of this attribute must be a cron expression.

A sample class will look like this:

package com.howtodoinjava.service;
import java.util.Date;
import org.springframework.scheduling.annotation.Scheduled;
public class DemoServiceBasicUsageCron
{
    @Scheduled(cron="*/5 * * * * ?")
    public void demoServiceMethod()
    {
        System.out.println("Method executed at every 5 seconds. Current time is :: "+ new Date());
    }
}

And application configuration will look like this:

Method 3) Task scheduling using cron expression from properties file 

In this method, cron attribute is used with @Scheduled annotation. Value of this attribute must be a cron expression as in previous method, BUT, this cron expression will be defined in a properties file and key of related property will be used in @Scheduled annotation.

This will decouple the cron expression from source code, thus making changes easy.

A sample class will look like this:

package com.howtodoinjava.service;
import java.util.Date;
import org.springframework.scheduling.annotation.Scheduled;
public class DemoServicePropertiesExample {
    @Scheduled(cron = "${cron.expression}")
    public void demoServiceMethod()
    {
        System.out.println("Method executed at every 5 seconds. Current time is :: "+ new Date());
    }
}

And application configuration will look like this:

<?xml  version="1.0" encoding="UTF-8"?>
    <task:annotation-driven />
    <util:properties id="applicationProps" location="application.properties" />
    <context:property-placeholder properties-ref="applicationProps" />
    <bean id="demoServicePropertiesExample" class="com.howtodoinjava.service.DemoServicePropertiesExample"></bean>
</beans>

Method 4) Task scheduling using cron expression configured in context configuration

In this method, cron expression is configured in properties file, and job scheduling is configured in configuration file using property key for cron expression. Major change is that you do not need to use @Scheduled annotation on any method. Method configuration is also done in application configuration file.

A sample class will look like this:

package com.howtodoinjava.service;
import java.util.Date;
public class DemoServiceXmlConfig
{
    public void demoServiceMethod()
    {
        System.out.println("Method executed at every 5 seconds. Current time is :: "+ new Date());
    }
}

And application configuration will look like this:

<?xml  version="1.0" encoding="UTF-8"?>
    <task:annotation-driven />
    <util:properties id="applicationProps" location="application.properties" />
    <context:property-placeholder properties-ref="applicationProps" />
    <bean id="demoServiceXmlConfig" class="com.howtodoinjava.service.DemoServiceXmlConfig" />
    <task:scheduled-tasks>
        <task:scheduled ref="demoServiceXmlConfig" method="demoServiceMethod" cron="#{applicationProps['cron.expression']}"></task:scheduled>
    </task:scheduled-tasks>
</beans>

Download sourcecode for above examples using below link.

Download Sourcecode

Let me know if I am missing anything.

Happy Learning !!

Reference:
http://forum.springsource.org/showthread.php?83053-Feature-Scheduled-with-Value-cron-expression

Direct self-reference leading to cycle (through reference chain:

In this case you need to annotate the relationships with @JsonManagedReference and @JsonBackReference like this:

 @ManyToOne
 @JoinColumn(name = "company_id", referencedColumnName = "id")
 @JsonBackReference("emp") 
 private Company company 

And

 @OneToMany(mappedBy="company")
 @JsonManagedReference("emp")
 private Set<Employee> employee = new HashSet<Employee>();

@JsonBackReference and @JsonManagedReference, we are using value “emp”. The reason is, if one class contains more than one JsonManagedReference

then we need give a value.other wise we will face the bellow error.

Jackson: Multiple back-reference properties with name ‘defaultReference’