Spring Services
-
Upload
kasun-madusanke -
Category
Software
-
view
65 -
download
0
Transcript of Spring Services
hSenid Lanka: Spring Services
hSenid Lanka: Spring Services
What is Spring?
What Does Spring Offer?
Spring Services
Task Execution and Scheduling
Demo-Scheduling
2
hSenid Lanka: Spring Services
3
Demo-Email
Data Access With JDBC
Demo-Data Access
Transaction Management
Demo-Database Transaction
hSenid Lanka: Spring Services
4
• Spring is an open source layered Java/J2EE application
framework.
• Philosophy: J2EE should be easier to use,
“Lightweight Container” concept
• Spring performs two major roles for a Java
application.
hSenid Lanka: Spring Services
5
• A Container
o Creates objects and makes them available to your
application.
First Spring is a container that manages all or
some of the objects used by the application.
Behind the scenes Spring configures your objects
with what they need to in order to perform their
roles in the application.
hSenid Lanka: Spring Services
6
• A Framework
o Provides an infrastructure of classes that make
it easier to accomplish tasks.
Spring is also a framework because it provides
libraries of classes that make it easier to
accomplish common tasks such as transaction
management, database integration, email, and web
applications.
hSenid Lanka: Spring Services
7
• Lightweight container and framework.
• Manages dependencies between your objects.
o Encourages use of interfaces
o Lessens “coupling” between objects
• Providing services to simplify tasks.
o Task scheduling
o Email sending
o Data access
o Database Transaction
hSenid Lanka: Spring Services
8
• Where to use scheduling?
o Generate periodic reports
o Invoke batch process
o Execute periodic application maintenance tasks
• Spring provides support for scheduling
• Quartz: Open source solution by OpenSymphony
• Trigger: SimpleTrigger, CronTrigger, etc.
hSenid Lanka: Spring Services
9
1.Using the MethodInvokingJobDetailFactoryObject
2.Using Annotations
3.Using Quartz Scheduler
4.Using Trigger (SimpleTrigger, CronTrigger)
hSenid Lanka: Spring Services
10
• The Spring Framework provides a helpful utility library for sending
email.
• The org.springframework.mail package is the root level package for
the Spring Framework’s email support.Timers: Java's built in
scheduler
• The central interface for sending emails is the MailSender
interface; a simple value object encapsulating the properties of a
simple mail such as from and to (plus many others) is the
SimpleMailMessage class.
hSenid Lanka: Spring Services
11
1.Textual Email
2.Email with attachment
hSenid Lanka: Spring Services
12
Action Spring You
Define connection parameters. X
Open the connection. X
Specify the SQL statement. X
Declare parameters and provide parameter values X
Prepare and execute the statement. X
Set up the loop to iterate through the results (if any). X
Do the work for each iteration. X
Process any exception. X
Handle transactions. X
Close the connection, statement and resultset. X
hSenid Lanka: Spring Services
13
• The JdbcTemplate class is the central class in the JDBC core
package.
• It simplifies the use of JDBC since it handles the creation and
release of resources.
• This helps to avoid common errors such as forgetting to always
close the connection.
• It executes the core JDBC workflow like statement creation and
execution, leaving application code to provide SQL and extract
results.
hSenid Lanka: Spring Services
14
hSenid Lanka: Spring Services
15
• Data Integrity.
• Consistency.
• Data and Resources may be corrupted and left in an
inconsistent state.
• Important for recovering from unexpected errors in a
concurrent and distributed environment.
hSenid Lanka: Spring Services
16
• The concept of transactions can be described with
following four key properties.
Atomicity
Consistency
Isolation
Durability
hSenid Lanka: Spring Services
17
• Atomicity
o A transaction should be treated as a single unit of operation
which means either the entire sequence of operations is
successful or unsuccessful.
• Consistency
o Once all actions of a transaction have completed, the
transaction is committed. Then your data and resources will be
in a consistent state that confirms to business rules.
hSenid Lanka: Spring Services
18
• Isolation
o Because there may be many transactions processing with the same
data set at the same time, each transaction should be isolated
from others to prevent data corruption.
hSenid Lanka: Spring Services
19
• Durability
o Once a transaction has completed, the results of this
transaction have to be made permanent and cannot be erased
from the database due to system failure.(imagine if the
power to your machine was cut right in the middle of a
transaction’s commit). Usually, the result of a
transaction is written to persistent storage.
hSenid Lanka: Spring Services
20
hSenid Lanka: Spring Services
21
• Brief Introduction to Spring
• Spring Services
• Scheduling (Annotations, Quartz, Trigger,
MethodInvokingJobDetailFactoryObject)
• Email (With and without an attachment)
• Data Accessing
• Database Transaction
hSenid Lanka: Spring Services
Demo projects can be found in GitHub
• Spring Scheduling - MethodInvokingTimerTaskFactoryBean
• Spring Scheduling – Annotation based
• Spring Scheduling – Simple, Quartz and Cron triggers
• Spring JDBC Template with Transaction Management