Wednesday, April 23, 2014

JSR 250


  • Spring JSR-250 Annotations
Spring also JSR-250 based annotations which include @PostConstruct, @PreDestroy and @Resource annotations. Though these annotations are not really required because you already have other alternate
http://www.tutorialspoint.com/spring/spring_jsr250_annotations.htm

  • JSR 250 is a Java Specification Request with the objective to develop annotations (that is, information about a software program that is not part of the program itself) for common semantic concepts in the Java SE and Java EE platforms
http://en.wikipedia.org/wiki/JSR_250

pojo id in hibernate

  • Suppose you are developing a course management system for a training center.
The first class you create for this system is Course.
This class is called an entity class or a persistent class because it represents a  real-world entity and its instances will be persisted to a database.
Remember that for each entity class to be persisted by an ORM framework, a default constructor with no argument is required.


public class Course {
private Long id;
...
// Constructors, Getters and Setters
}

For each entity class, you must define an identifier property to uniquely identify an entity.
It’s a best practice to define an auto-generated identifier because this has no business meaning and thus won’t be changed under any circumstances.
this identifier will be used by the ORM framework to determine an entity’s state.
If the identifier value is null, this entity will be treated as a new and unsaved entity.
When this entity is persisted, an insert SQL statement will be issued; otherwise, an update statement will.
To allow the identifier to be null, you should choose a primitive wrapper type like
java.lang.Integer and java.lang.Long for the identifier

Spring Recipes: A Problem-Solution Approach

Connection pooling

  • Hibernate's own connection pooling algorithm is, however, quite rudimentary.
You should use a third party pool for best performance and stability.
Just replace the hibernate.connection.pool_size property with connection pool specific settings.
This will turn off Hibernate's internal pool.

C3P0 is an open source JDBC connection pool distributed along with Hibernate in the lib directory.
Hibernate will use its org.hibernate.connection.C3P0ConnectionProvider for connection pooling if you set hibernate.c3p0.* properties.
If you would like to use Proxool, refer to the packaged hibernate.properties

The following is an example hibernate.properties file for c3p0:
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/session-configuration.html#configuration-optional


  • hibernate.c3p0.min_size – Minimum number of JDBC connections in the pool. Hibernate default: 1
hibernate.c3p0.max_size – Maximum number of JDBC connections in the pool. Hibernate default: 100
hibernate.c3p0.timeout – When an idle connection is removed from the pool (in second). Hibernate default: 0, never expire.
hibernate.c3p0.max_statements – Number of prepared statements will be cached. Increase performance. Hibernate default: 0 , caching is disable.
hibernate.c3p0.idle_test_period – idle time in seconds before a connection is automatically validated. Hibernate default: 0

Toad test to see connections
http://www.mkyong.com/hibernate/how-to-configure-the-c3p0-connection-pool-in-hibernate/


  • Using a properties (flat text) file. For instance

jdbc-0.proxool.alias=property-test
jdbc-0.proxool.driver-url=jdbc:hsqldb:.
jdbc-0.proxool.driver-class=org.hsqldb.jdbcDriver
jdbc-0.user=sa
jdbc-0.password=
jdbc-0.proxool.maximum-connection-count=10
jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE

http://proxool.sourceforge.net/configure.html



hibernate.hbm2ddl.auto

  • Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-optional


  •     validate: validate the schema, makes no changes to the database.
    update: update the schema.
    create: creates the schema, destroying previous data.
    create-drop: drop the schema at the end of the session.
http://stackoverflow.com/questions/438146/hibernate-hbm2ddl-auto-possible-values-and-what-they-do


  • Hibernate creators discourage doing so in a production environment in their book "Java Persistence with Hibernate"

excerpt:
We've seen Hibernate users trying to use SchemaUpdate to update the schema of a production database automatically. This can quickly end in disaster and won't be allowed by your DBA.

http://stackoverflow.com/questions/221379/hibernate-hbm2ddl-auto-update-in-production

JSF - Custom Converter

  • Defining a custom converter in JSF is a three step process
1    Create a converter class by implementing javax.faces.convert.Converter interface.
2    Implement getAsObject() and getAsString() methods of above interface.
3    Use Annotation @FacesConvertor to assign a unique id to the custom convertor.
http://www.tutorialspoint.com/jsf/jsf_customconvertor_tag.htm

  • Steps
1. Create a converter class by implementing javax.faces.convert.Converter interface.
2. Override both getAsObject() and getAsString() methods.
3. Assign an unique converter ID with @FacesConverter annotation.
4. Link your custom converter class to JSF component via f:converter tag.
http://www.mkyong.com/jsf2/custom-converter-in-jsf-2-0/

hot deployment

  • Jetty is fully hot deployable, but does not have any native hot deployers
What this means is that Jetty contexts, servlets and filters may be added, stopped, started and reloaded dynamically, but that Jetty does not have any services that trigger these events.
http://67-23-9-112.static.slicehost.net/faq?s=200-General&t=HotDeploy


  1. How to work with Java hot-deploy
You don't really have to restart the server after you change java code,launch RJR with Debug Mode (debug-as -> Run Jetty) and you are now able to enjoy the default hot-deploy feature from JDK

RJR refers to rujettyrun
https://code.google.com/p/run-jetty-run/wiki/UserGuide

Code Bubbles

  • Code Bubbles
Code Bubbles is a front end to Eclipse designed to simplify programming by making it easy for the programmer to define and use working sets.
http://cs.brown.edu/~spr/codebubbles/

JREAP

  • JREAP
The Joint Range Extension Applications Protocol ("JREAP") extends the range of Tactical Data Link by permitting tactical data messages to be transmitted over long-distance networks, e.g. satellite links.
http://en.wikipedia.org/wiki/JREAP

Extensible Messaging and Presence Protocol (XMPP)

  • Extensible Messaging and Presence Protocol (XMPP)
a communications protocol for message-oriented middleware based on XML (Extensible Markup Language)
the protocol has also been used for publish-subscribe systems, signalling for VoIP, video, file transfer, gaming, Internet of Things applications such as the smart grid, and social networking services.
http://en.wikipedia.org/wiki/XMPP

Rules Engine

  • Should I use a Rules Engine?
commands in sequence with conditionals and loops, it provides a list of production rules. Each rule has a condition and an action - simplistically you can think of it as a bunch of if-then statements.

The subtlety is that rules can be written in any order and the system can choose to evaluate them in whatever order makes sense for it. A good way of thinking of it is that the system runs through all the rules, picks the ones for which the condition is true, and then evaluates the corresponding actions.

http://martinfowler.com/bliki/RulesEngine.html


  • Getting Started With the Java Rule Engine API (JSR 94): Toward Rule-Based Applications
For many mission-critical applications, the process of automating business policies, procedures, and business logic is simply too dynamic to manage effectively as application source code

The Business Rules Group defines a business rule as a statement that defines or constrains some aspect of the business; a business rule is intended to assert business structure or to control or influence the business's behavior

A rule engine evaluates and executes rules, which are expressed as if-then statements. The power of business rules lies in their ability both to separate knowledge from its implementation logic and to be changed without changing source code.

http://www.oracle.com/technetwork/articles/javase/javarule-139829.html



  • Open Source Rule Engines in Java


Drools
https://www.jboss.org/drools/
Mandarax
JLisa
JEOPS - The Java Embedded Object Production System
OpenRules
Open Lexicon
SweetRules
JRuleEngine
http://java-source.net/open-source/rule-engines

Enterprise resource planning

  • Enterprise resource planning
Enterprise resource planning (ERP) is business management software—usually a suite of integrated applications—that a company can use to store and manage data from every stage of business, including:

    Product planning, cost and development
    Manufacturing
    Marketing and sales
    Inventory management
    Shipping and payment
http://en.wikipedia.org/wiki/Enterprise_resource_planning

Business support system

  • Business support system
Business support systems (BSS) are the components that a telephone operator or telco uses to run its business operations towards customer

Basically it deals with the taking of orders, payment issues, revenues etc.
The role of business support systems in a service provider is to cover four main areas:

    Product management
    Order management
    Revenue management
    Customer management
http://en.wikipedia.org/wiki/Business_support_system

Operations support system

  • Operations support system
Operations support systems are computer systems used by telecommunications service providers.
The term OSS most frequently describes "network systems" dealing with the telecom network itself, supporting processes such as maintaining network inventory, provisioning services, configuring network components, and managing faults

The complementary term, business support systems or BSS, is a newer term and typically refers to “business systems” dealing with customers, supporting processes such as taking orders, processing bills, and collecting payments. The two systems together are often abbreviated OSS/BSS, BSS/OSS or simply B/OSS.

 OSS covers at least the application areas:

    Network management systems
    Service delivery
    Service fulfillment, including the network inventory, activation and provisioning
    Service assurance
    Customer care
http://en.wikipedia.org/wiki/Operations_support_system

Decision support system

  • Decision support system
A Decision Support System (DSS) is a computer-based information system that supports business or organizational decision-making activities.
DSSs serve the management, operations, and planning levels of an organization (usually mid and higher management) and help to make decisions, which may be rapidly changing and not easily specified in advance (Unstructured and Semi-Structured decision problems). Decision support systems can be either fully computerized, human or a combination of both.

Typical information that a decision support application might gather and present includes:

    inventories of information assets (including legacy and relational data sources, cubes, data warehouses, and data marts),
    comparative sales figures between one period and the next,
    projected revenue figures based on product sales assumptions
   
http://en.wikipedia.org/wiki/Decision_support_system