Sunday, July 8, 2018

Esempio di Progettazione Concettuale: la concessionaria di automobili multimarca

Esempio di Progettazione Concettuale: la concessionaria di automobili multimarca

Il sistema per la concessionaria di automobili gestisce vendite di auto nuovo ed usato. Per l'usato si ha una gestione delle riparazioni, per il nuovo si ha una gestione degli optional venduti. Si suppone che l'utente possa acquistare piu' automobili. Si hanno i seguenti vincoli sulle auto usate: 1) non devono esistere riparazioni con spese inferiori ai 1000 eur, 2) non si devono vendere auto immatricolate prima del 2008, 3) non si possono vendere auto che abbiano percorso piu' di 100.000 Km.

 

Gli attributi dell'entità cliente sono i soliti: nome, cognome, indirizzo, tel., con attributo chiave il codice fiscale.
L'associazione Acquista, di tipo uno a molti, tra le entita' Cliente ed Automobile, contiene gli attributi data acquisto e sconto.
Sia l'automobile nuova che l'auto usata viene descritta dagli attributi: N.telaio, marca, modello, prezzo e anni di garanzia (di solito 1 anno per l'usato e 2 anni per il nuovo), per cui questi attributi li generalizzo e li porto sull'entità padre. Un'auto usata ha degli attributi in piu' rispetto a quella nuova, che sono km percorsi ed anno di immatricolazione; le auto nuove sono immatricolate dal concessionario al momento della vendita.
L'associazione opzionale Usato:Riparazione di tipo M:N, con codice, tipo (ad es. frizione, freni), descrizione (cosa ho fatto alla macchina) e il costo. In questo modo potro' fare delle ricerche su database del tipo: quante auto ho venduto che hanno richiesto una riparazione ai freni.
L'associazione opzionale Nuovo:Optional di tipo M:N, con codice, descrizione (ad es. cerchi in lega) e prezzo. L'auto nuova puo' avere 0...N optional, un optional puo' avere 1...N auto.
Se io voglio sapere le auto vendute che motorizzazione hanno, ad es. la cilindrata, se e' diesel o benzina, allora devo introdurre una nuova entità che chiamo motorizzazione. L'associazione Auto:Motorizzazione e' di tipo 1:N. Poiche' il prezzo dell'auto dipende dalla motorizzazione, sposto l'attributo prezzo dall'entità Automobile a quella Motorizzazione.
Il prezzo finale dell'auto e' dato da: P = (prezzo dell'auto) + (prezzo optional) + (costo riparazione) - (sconto).
In questo modello la parte della vendita non prende in considerazione la fatturazione, ovviamente questa e' una semplificazione della realta' di un concessionario auto.

Saturday, July 7, 2018

Esempio di progettazione concettuale: la gestione dei prestiti dei libri di una bilioteca

Esempio di progettazione concettuale: la gestione dei prestiti dei libri di una bilioteca

I lettori hanno una tessera su cui e' scritto un numero progressivo, il nome, il cognome, l'indirizzo, e il numero di telefono. I libri hanno un codice ISBN, un titolo, una lista di autori e possono esistere in piu' copie. I lettori effettuano richieste di prestito per le copie dei libri che sono catalogati nella biblioteca. A seguito di una richiesta, viene prima consultato l'archivio delle copie disponibili, cioe' non in prestito. Se la copia e' disponibile, si procede alla ricerca della copia nello scaffale, poi la copia viene classificata come in prestito e consegnata al lettore. Terminata la consultazione, la copia viene inserita in biblioteca e nuovamente classificato come disponibile. Per un prestito si tiene nota di ora e data di acquisizione e di riconsegna.

 

Il diagramma ER contiene tre entità: Utente, Copia e Libro: Utente ha come attributo chiave il numero della tessera della biblioteca. Libro ha come attributo chiave l'ISBN. Copia non ha un attributo chiave naturale, per cui introduciamo un numero progressivo. L'associazione Utente:Copia di tipo M:N e si chiama PrendeInPrestito. PrendeInPrestito ha attributi propri: data prestito e data consegna. L'associazione PrendeInPrestito e' opzionale in entrambi i versi, perche' l'utente puo' prendere in prestito nessun libro e ci possono essere dei libri che non sono mai consultati. L'attributo data prestito e' obbligatorio, l'attributo data consegna e' opzionale. Quando l'utente prende in prestito un libro il campo data consegna e' NULL e sara' valorizzato quando lo consegna. Quindi per vedere i prestiti attualmente aperti per un utente, io faccio una ricercare per utente e vedo quanti valori NULL ha in prestito.

Allo schema si possono aggiungere dei vincoli definiti dall'utente.

  • data consegna >= data prestito.
  • un utente non puo' prendere in prestito piu' di quattro libri
  • il tempo massimo di prestito sia di 30 giorni. In pseudocodice si scrive:
    IF dataConsegna == NULL
        IF (dataAttuale - dataPrestito) > 30
        THEN Sollecito Utente
    

Operazioni sul sistema biblioteca

  • inserimento tesserato
  • inserimento libro
  • inserimento copia libro
  • ricerca di un libro tramite titolo e autore
  • controllo della disponibilita' di una copia di un libro
  • ricerca della collocazione delle copie di un libro
  • registrazione di un prestito e di una restituzione
  • ricerca di tutte le copie prestate

Errori su database e chiavi primarie

Anche Il Ministero delle Finanze fa dei controlli sul proprio database: se il contribuente non ha presentato il 730, c’è un campo con valore NULL e il Ministero invia una cartella. Se avviene un errore sul codice fiscale, il ministero manda la cartella lo stesso. Infatti, un operatore che riempie una base di dati commette statisticamente un errore ineliminabile del 2 per mille. Se vi arriva una cartella ICI e' possibile che un operatore abbia sbagliato il codice_comune o il codice_fiscale, ad esempio ha inserito una F invece di una P. Alcuni incongruenze si possono risolvere corregendo i vincoli di integrita' tra le entità, in modo che se un contribuente paga le tasse da 10 anni sul database devono risultare tutti e 10 i versamenti.

Friday, July 6, 2018

Basi di Dati: Il modello concettuale

Content:

  1. Database
  2. DBMS
  3. MODELLI DEI DATI
  4. PROGETTAZIONE DI UNA BASE DI DATI
  5. PROGETTAZIONE CONCETTUALE
  6.     5.1 Il Modello E-R
        5.2 Le entità
        5.3 Gli Attributi
        5.4 Le Associazioni
        5.5 Vincoli di Integrita'

1 DATABASE

Cosa e' un sistema informativo?

Durante qualunque attivita' e' necessario avere a disposizione una quantita' di informazioni, per cui le organizzazioni si dotano di un sistema informativo per gestire le informazioni.

Dati e Informazioni

  • dati = rappresentazione grezza
  • informazione = significato ottenuto interpretando i dati

Le informazioni vengono codificate e scambiate.
I dati sono la rappresentazione codificata delle informazioni. Opportunamente interpretati, i dati permettono di ottenere informazioni.

Cosa sono le basi di dati?

Le basi di dati sono una collezione di dati, raccolti allo scopo di rappresentare le informazioni usate in un sistema informativo. In altre parole, un database e' una base di dati è una collezione organizzata di dati correlati che descrivono una specifica realta' di interesse.

Esempi:

  • quando facciamo una operazione allo sportello dell'ufficio postale, l'operatore in inserisce dei dati dal terminale che sono registrati in un database, il database dei versamenti.
  • quando andiamo in banca e facciamo delle operazioni, l'operatore inserisce dei dati, parte una transazione e i dati immessi popolano un database.
  • voi vi sieti iscritti a questo corso, i vostri dati sono stati registrati in un database.
  • tutti i dati che descrivono una realta' costituiscono un database.

Friday, June 15, 2018

Java SE 8 Date and Time API

Time is a scalar quantity, so it would only need a number to express a time value.
Since you want to relate time to calendars, which are made for humans, things get more complicated.

Java date and time classes' history:

  • the java.util.Date class was introduced in Java 1.0
  • the java.util.Calendar class was introduced in Java 1.1
  • third-party date and time libraries, such as Joda-Time, were used by developer to overcome Java standard API's issues
  • the java.time API was introduced in Java 1.8 to fix the flaws in the previous versions of the platforms

1 The Time Line

The unit of time is the second, which is derived from the Earth's rotation around its axis.

Universal Time

  • Earth rotation is not uniform: in 1967, a more precise definition of second was derived from the property of atoms of caesium-133 and atomic clocks were introduced to keep the official time.
  • Since rotation rate of Earth varies with climate events, official time keepers synchronize absolute time with solar mean time
    • official time keepers add or remove a second to keep the Universal Time close to the mean solar time
  • In UTC, a day has 24 * 60 * 60 = 86400 seconds.
    • the number of seconds in a minute is usually 60, but with an occasional leap second it may be 61.

Universal Time and Computer Systems

  • Computer system keeps 86400 seconds per day and do not respect leap seconds.
  • when a leap second is officially introduced, computer systems slow down or speed up before the leap second.

Java Date and Time API specification for the time scale:

  • A day has 86,400 seconds
  • Time scale matches the official time at noon each day

The Time Line in Java and the Instant class

  • the Instant class represents a point in the time line
  • The static method Instant.now() returns the current instant
  • time is measured on time scale with origin set at midnigth of January 1, 1970 at Greenwich meridian
  • from that origin, time is measured in 86,400 seconds per day
  • Instant.MIN and Instant.MAX are one billion behind and ahead the origin

The Duration class represents the amount of time between two instants

  • the static method Duration.between gives the difference between two instants

Example:

 Instant start = Instant.now();
 callMethod();
 Instant stop = Instant.now();
 Duration timeElapsed = Duration.between(start, stop);
 long millis = timeElapsed.toMillis(); 

Wednesday, May 23, 2018

UTC Date Time System and ISO Representation

1 UTC Date Time System

1.1 UTC Time standard definition

Coordinated Universal Time (UTC) is the time standard by which the world regulates clocks and time.

The UTC is defined by an International Telecommunications Union recommendation and is based on International Atomic Time.

  • the standard adopt leap seconds to adjust UTC Time and compensate for the slowing of Earth's rotation.
  • Greenwich Mean Time (GMT) was formerly used as the international time standard, then UTC superseded GMT.
1.2 How UTC Time works

UTC divides time into days, hours, minutes and seconds.

UTC days

  • are identified using the Gregorian calendar.
  • contain 24 hours and each hour contains 60 minutes.
  • almost all UTC days contain exactly 86,400 SI seconds.

UTC minutes:

  • usually a minute contains 60 seconds, but (with an occasional leap second) a minute may contain 61 or 59.
  • because of leap seconds, the minute and all larger time units are of variable duration.

UTC seconds:

  • is the smaller time units of constant duration.
1.3 UTC Time Zones

Time zones are regions of the earth where the local time is defined as differing the UTC Time by an integer number of hours

  • but some countries have established time zones that differ by a number of half-hours or quarter-hours from UTC.
  • this difference or offset is positive or negative:
    • the westernmost time zone is twelve hours behind UTC and is UTC-12
    • the easternmost time zone is fourteen hours ahead of UTC and is UTC+14

Civil Time

Civil Time indicates the time designated by authorities or local time indicated by clocks.

  • civil time is generally standard time in a time zone at a fixed offset from Coordinated Universal Time (UTC), adjusted by daylight saving time during part of the year.

The Civil Time in a particular time zone can be determined from the UTC Time by adding or subtracting the number of hours and minutes specified by the UTC offset.

1.4 Daylight Saving Time

UTC does not observe daylight saving time and does not change with seasons

Local Time or Civil Time may change if a time zone jurisdiction observes Daylight Saving Time (summer time).

Example:

  • local time on the east coast of the United States is five hours behind UTC during winter, but four hours behind UTC during summer.
1.5 Who uses UTC

UTC is used by Computer systems and the Internet

  • in the internet and World Wide Web standards
  • the Network Time Protocol synchronizes the clocks of computers over the internet, using the UTC system
  • email systems and other messaging systems time-stamp messages using UTC
  • database records that include a time stamp use UTC

UTC is also the time standard used in aviation, weather forecasts, maps, amateur radio operators

Friday, April 6, 2018

Introduction to GIT

Content:

  1. Getting a Git Repository
  2.     1.1 How to get a Git repository
        1.2 Initializing a Repository in an Existing Directory
        1.3 Cloning an Existing Repository
  3. Recording Changes to the Repository
  4.     2.1 Recording Changes to the Repository
        2.2 Checking the Status of Your Files
        2.3 Adding a new file to your projecty
        2.4 Tracking New Files
        2.5 Staging Modified Files
        2.6 Ignoring Files
        2.7 Viewing Your Staged and Unstaged Changes
        2.8 Committing Your Changes
        2.9 Removing Files
        2.10 Moving Files
  5. Viewing the Commit History
  6.     3.1 Viewing the Commit History
  7. Working with Remotes
  8.     4.1 Working with Remotes
        4.2 Showing Your Remotes
        4.3 Adding Remote Repositories
        4.4 Fetching and Pulling from Your Remotes
        4.5 Pushing to Your Remotes
        4.6 Inspecting a Remote
        4.7 Renaming and Removing Remotes
  9. Branching
  10. Rewriting History
  11. Configuration

0 Getting Started

Git differs from other VCS in that it makes snapshots not differences

Git stores and thinks about information in a very different way than other VCSs.

  • Other version control systems store informations as a set of base files and the changes made to each file over time, this is commonly described as delta-based version control. Instead, Git stores the data as series of snapshots of a filesystem.
  • To store the state of the your project, Git makes a copy, or snapshot, all the files of the project and save them. To be more efficient, if a file has not changed, Git doesn’t store the file again but a link to the already saved file in a previous snapshot.
  • This is an important distinction between Git and all other VCSs, that makes Git more like a mini filesystem. This have many benefits when branching a Git project.

Saturday, March 17, 2018

Introduzione a Git

1. Introduzione

Git e' un sistema di version control (http://git-scm.org). Lo scopo di Git e' quello di tener traccia di tutti i cambiamenti effettuati all'interno di un progetto software in modo da assicurare sempre una versione di backup delle versioni precedenti. In questo modo, se qualcosa va storto, e' possibile invertire le modifiche e ripristinare il precedente stato funzionante del software.
A differenza degli altri sistemi di versionamento, quasi tutte le operazioni in Git non hanno bisogno di una connessione internet, perché sono operazioni che avvengono su disco locale. Git salva lo storico completo del progetto direttamente su disco locale e recuperare una vecchia versione di un file dalla history é una operazione istantanea. Anche le commit avvengono sul database locale

1.1 Git vs GitHub

Git e GitHub sono due cose diverse: GitHub è un servizio online basato su Git, ma non è indispensabile per usare Git e creare un repository. GitHub permette di hostare online un repository creato con Git e condividerlo con altri sviluppatori. L'hosting pubblico su GitHub è gratuito, l'hosting privato è a pagamento. Per questo motivo gli sviluppatori usano altri servizi online per condividere repository Git, come GitLab.com e bitbucket.org.

1.2 Le aree di lavoro di Git

Git e' composto da quattro aree di lavoro:


Il luogo dove lo sviluppatore crea e modifica il codice del progetto e' rappresentato dalla working directory di Git, che contiene i file che andranno a costituire il repository Git.

Friday, February 23, 2018

Enterprise Beans

Enterprise beans run in the EJB container:

  • the EJB container is a runtime environment within a Java application server
  • the EJB container provides system-level services to enterprise beans such as transactions and security

Content:

  1. What Is an Enterprise Bean?
  2. What Is a Session Bean?
  3. What Is a Message-Driven Bean?

1 What Is an Enterprise Bean?

An enterprise bean is a server-side component that contains the application's business logic

  • for example, in an auction application, the AuctionManager enterprise bean implements the business logic in the methods named createAuction, placeBid, closeAuction.
1.1 Benefits of Enterprise Beans

Enterprise beans simplify the development of large applications:

  • the EJB container, not the developer, is responsible for system level services such as transaction management and security authorization
  • the beans not the clients contain the business logic, the clients only contain the presentation. As a consequence, application clients are thinner
  • enterprise beans are portable, they are portable accross any compliant Java EE server and developers can build new applications from existing beans
1.2 When to Use Enterprise Beans

You should consider using enterprise beans if your application has any of the following requirements:

  • the application must be scalable to support more users and you need to distribute application's components to multiple machines
  • transactions must ensure data consistency
  • application will be accessed by a variety of clients
1.3 Types of Enterprise Beans

There are two types of enterprise beans, which fulfill different purposes:

  • Session: a session bean performs a task for a client
  • Message-driven: a message-driven bean acts as a listener for messages

Tuesday, January 16, 2018

Introduction to Java Platform, Enterprise Edition

Companies need distributed, transactional and portable applications: enterprise java applications fulfill the business logic for the enterprise.

Java platform provides APIs to developers and shortens developement time

The Java Community Process (JCP) writes Java Specification Requests (JSRs) to define the Java EE technologies

The Java EE 7 platform simplifies the programming model:

  • Developers can use annotations in Java source files, instead of optional XML deployment descriptors. The Java EE server reads annotations and configures components at deployment and runtime
  • With dependency Injection, required resources can be injected in component, instead of using JNDI lookup code. Dependency injection can be used in any container type: EJB container, web container and application client container. The container is aware of annotations and inject references to other component/resource

1 Java EE Application Model

Java EE applications implement enterprise services for customers, access data from different sources and distribute applications to a variety of clients

The business functions of Java enterprise applications are in the middle tier: the middle tier is usually on a dedicated server hardware.

The Java application model architecture implements the customer's services as multitier applications

The Java model partitions the work in two parts:

  • business logic and presentation implemented by developers
  • standard services provided by Java EE platform

Friday, September 15, 2017

Requirements of Java EE 7 Enterprise Applications

The Java EE technology elements

Java EE specifications incorporates a group of other technologies and specifications to provide server-side functionalities for enterprise application developers

  • application components: these components allow creation of application business logic and control elements
  • integration: integration elements allow to interact with the functionalities from other applications and systems
  • container management: these elements provide runtime support for Java EE application components

Monday, August 28, 2017

Creating a Simple Maven Project

1 Generating a simple project with Maven and Eclipse

To generate a project with maven from command line:

 mvn -B archetype:generate \
  -DgroupId=com.company.application \
  -DartifactId=project \
  -Dpackage=com.company.application \
  -Dversion=1.0 
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  • the maven command mvn archetype:generate executes the generate goal of the archetype plugin
  • an archetype is defined as a "model from which similar thing are patterned; a prototype"
  • when you run the archetype:generate goal you pass the goal parameter: archetypeArtifactId=maven-archetype-quickstart
  • you can select the maven archetypes that fits your purpose
  • the maven-archetype-quickstart is the most basic archetype to create a java project