Service-oriented architecture (soA) involves building software applications as a collection of
services that communicate with each other to perform various funitións.
A SOA approach Is one where our overall appleation makes use of the services of other
applications.
Advantages of SOA:
We can go to a single web site and book air travels ,hotels, and automobiles all from a single
site.
.the data for hotels is not stored on the airline computers. Instead, the airline computers
contact the services on the hotel computers and retrieve the hotel data and present it to the
user
A SOA always maintain only one copy of data
The owners of data can set the rules about the use pf their data.
• An SoA system is carefully designed to have good performance and meet the user’s needs.
. And when it comes time to change your credit used for the whole transaction, still other
computers become involved in the process
Automatically creating primary keys
consider the example, where we arbitrarily assigned Frank the primary key of 42.
•However when we are inserting millions of rows, it is nice to have the database automatically
generate the values for the id column.
We do this by declaring the id column as a PRIMARY KEY and leave out the id value when
inserting the row:
DROP TABLE IF EXISTS Artist;
CREATE TABLE Artist (id INTEGER PRIMARY KEY,name TEXT,eyes TEXT);
INSERT INTO artist (name, eyes)
VALUES (‘Frank Sinatra, ‘blue’);
Logical keys for fast lookup.
If we had a table full of artists and a table full of tracks, each with a foreign key link to a row in a
table full of artists and we wanted to list all the tracks that were sung by ‘Frank sinatra’
SELECT title, plays, name, eyes FROM track JOIN artist
ON [Link] = [Link]
WHERE [Link]=’Frank Sinatra’;
* if we are going to have millions of records in the artist table and going to do a lot of lookups
by artist name, we would benefit if we gave the database hint about our intended use of the
name column
* We do this by adding an “index” to a text that we intend to use in WHERE clauses:
CREATE INDEX artist_name ON artist (name);
1) the INSERT stalement specifies the table name, then a list of fields /cdlumns that you would
like to set in the new row and then the keyword VALves and wrresponding values for lach of the
fields. INSERT INTO track (title, plays) VALUES (‘my way’)
2)Tge SQL SELECT commands is listed to retrieve rows and columns from a database. The SELECT
staterment lets you specify which columns you would like to retriive as will as a WHERE clause
to select which rows you would like to see. It also allows all optional ORDER.
SELECT* FROM track WHERE title = ‘my way’
3) The UPDATE statement specifies a table and then a list of fields and values to change after
the SET keyword and then an optional WHERE clause to select the rows that are to be updated.
UPDATE track SET plays = 16 WHERE title =’ my way’
4)to remove a row you need a WHERE clause on an SQL DELETE statement, The WHERE clause
determines which rows are to be deleted.
DELETE FROM track WHERE title = ‘my way’
Using Urllib, you can treat a web page much like a file.. You Simply indicate which Web page you
would like to retrieve and urllib handles all of the HTTP protocol & header details .The
Equivalent Code to read the [Link] file from the web using urllib is as follows:
Import [Link]
Fhand = urllib. Request. Urlopen (‘http: //data. Pr4e. org/[Link]’)
For line in fhand:
Print([Link]().strip())
*The program to retrieve data for romeo. Txt & Compute the frequency of each word in the file
as follows:
• import Urllib. Request, Urllib. Parse, Urllib. Error
Fhand = [Link]. Urlopen (‘http: //data. Pr4e. org./[Link]’) Counts = dict()
For line in fhand:
Words = line. Decode(). Split()
For word in words:
Counts [word) = [Link](word, 0)+1
Print (Counts)
Again,Once we have opened the web page,we Can read it like a local file.
Import Socket
Mysock = [Link] (socket. AF-INET, Socket.SOCK_STREAM)
Mysock. Connect ((‘data. Pr4e. org’, 80))
Cmd = ‘GET [Link] [Link]/[Link] HTTP/1.0\r\n\r\n’.encode()
[Link](cmd)
While True:
Data=[Link](512)
If len (data) <1:
Break
Print (data. Decode(), End =’ ‘) mysock. Close()
#Code: https: // www. .py4e. Com/Code 3/[Link]
This program Creates a Socket Connection to the local. Web Server on port 80, sends a GET
request for the root document, & prints the response from the server.
Python has a special library specifically designed to support the HTTP protocol for the retrieval
of documents and data over the web.
You can change the state of an object by making an assignment toone of its attributes.
[Link] = [Link] +50
Box. Height = box. Height +100
You san also write functions that modify objects
Def grow_rectangle (react, dwidth,dheight):
Rect. Width + = dwidth
[Link] += dheight
Here is an example that demonstrate the effect:
>>>box. Width, box .height
(150.0, 300.0)
>>> grow – rectangle (box, 50, 100)
>>> box. Width,[Link]
(200.0,100.0)
Inside the function , rect is an alias for box, so when the function modifies rect, box changes.
The Class Variables
The class variable are Shared among all instances of a class
Declared within the Class, outside any Methods
* Stored in the class’s namespace.
* Can be accessed using the class name or an instance
Modifying a class variable affects all instances
• Used for attribute that Should be same for all instances
Ex Class Dog:
Species=”canis familiaris”
Instance Variable
* The instance Variables are Unique to eachinstance of a class
* Declared within Methods, usually the init method,
* Stored in the instance’s namespace
*Accessed only through an instance
Modifying an instance variable only affects that Specific instance
Used for attributes that vary from one instance to another.
Ex:- def init(Self,name):
[Link] =name
Operator Overloading :- By defining other Special methods, you can specify the behavior of
operation on programmer defined types.
If you define a method named add for Time Class, you can use + operator on Time objects.
• Class Time: Def add (Self, other):
Seconds=Self.time_to_ int()+ other. Time_to_int()
Return int_to_time (seconds)
Start = Time (9,45)
Duration = Time (1, 35)
Print (start + duration)
11:20:00
When you apply the + operator to Time objects python invokes add, when you print the result,
python invokes str
Changing the behaviour of an operator so that It works with programmer – defined types is
called operation overloading
Polymorphism: Functions that work with Several types are called polymorphic. Polymorphism
can facilitate code reuse
*For Example we used histogram to count the number of times Each letter appears ina word
Def histogram(s):
D= dict()
For c in s:
If c net to d:
D[c]=1
Else:
D[c]= d[c]+1
Return d
This function also works for lists, tuples, & Even dictionaries, as long as the Elements of s are
hashable, So they can be used as keys in d
>>> t = [‘spam’, ‘Egg’, Spam’, Spam’, ‘bacon’, ‘Spam’]
>>>histogram (t)
{‘bacon’:1,’egg’:1,’spam’:4}
In general, if all of the operations inside a function work with a given type, the function works
with that type
The init method: (Short for “initialization”)
It is a Special Method that gets invoked when an object is instantiated. It’s full name is init. An
init method for the time look like this
# inside Class Time:
Def init(self, hour =0, minute =0, Second=0):
Self. Hour = hour
Self. Minute = minute
Self. Second = Second.
It is common for parameters of init to have same names as attributes .
The parameters are optional, So if you call time with no arguments, you get the default values.
>>>time=Time()
>>>time.print_time()
00:00:00
If you provide one/two arguments, they override hour. /hour& minute
>>> time = Time (9)
>>>time.print_time()
09:00:00
>>>time=Time(9,45)
>> > time :print_time ()
09:45:00
And if you provide 3 arguments. They override all three default values.
The Str method
It is a Special method which returns a string representation of an object & useful for debugging
for Example, here is a str method for Time objects:
#inside Class Time:
defStr(Self):
return ‘%.2d:%.2d:%.2d’% (self. Hour, Self. Minute, Self. Second)
When you print an object, python invokes the Str method:
Time = Time (9, 45)
Print (time)
09:45:00