Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Adrian
/
EjemploDAE2020
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
044deb99
authored
Nov 09, 2020
by
Adrian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
DDL creado
parent
ff60b127
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
276 additions
and
66 deletions
pom.xml
sqlitesample.db
src/main/java/com/springboot/sqlite/SQLDialect.java
src/main/java/es/ujaen/dae/ujacoin/app/AppUjaBank.java
src/main/java/es/ujaen/dae/ujacoin/beans/ServicioUjaBankImpl.java
src/main/java/es/ujaen/dae/ujacoin/entidades/Cliente.java
src/main/java/es/ujaen/dae/ujacoin/entidades/Cuenta.java
src/main/java/es/ujaen/dae/ujacoin/entidades/Movimiento.java
src/main/java/es/ujaen/dae/ujacoin/entidades/ServicioBancario.java
src/main/java/es/ujaen/dae/ujacoin/entidades/Tarjeta.java
src/main/resources/application.properties
pom.xml
View file @
044deb99
...
...
@@ -21,10 +21,20 @@
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.xerial
</groupId>
<artifactId>
sqlite-jdbc
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
...
...
sqlitesample.db
0 → 100644
View file @
044deb99
No preview for this file type
src/main/java/com/springboot/sqlite/SQLDialect.java
0 → 100644
View file @
044deb99
package
com
.
springboot
.
sqlite
;
import
java.sql.Types
;
import
org.hibernate.dialect.Dialect
;
import
org.hibernate.dialect.function.StandardSQLFunction
;
import
org.hibernate.dialect.function.SQLFunctionTemplate
;
import
org.hibernate.dialect.function.VarArgsSQLFunction
;
import
org.hibernate.Hibernate
;
import
org.hibernate.type.StringType
;
public
class
SQLDialect
extends
Dialect
{
public
SQLDialect
()
{
registerColumnType
(
Types
.
BIT
,
"integer"
);
registerColumnType
(
Types
.
TINYINT
,
"tinyint"
);
registerColumnType
(
Types
.
SMALLINT
,
"smallint"
);
registerColumnType
(
Types
.
INTEGER
,
"integer"
);
registerColumnType
(
Types
.
BIGINT
,
"bigint"
);
registerColumnType
(
Types
.
FLOAT
,
"float"
);
registerColumnType
(
Types
.
REAL
,
"real"
);
registerColumnType
(
Types
.
DOUBLE
,
"double"
);
registerColumnType
(
Types
.
NUMERIC
,
"numeric"
);
registerColumnType
(
Types
.
DECIMAL
,
"decimal"
);
registerColumnType
(
Types
.
CHAR
,
"char"
);
registerColumnType
(
Types
.
VARCHAR
,
"varchar"
);
registerColumnType
(
Types
.
LONGVARCHAR
,
"longvarchar"
);
registerColumnType
(
Types
.
DATE
,
"date"
);
registerColumnType
(
Types
.
TIME
,
"time"
);
registerColumnType
(
Types
.
TIMESTAMP
,
"timestamp"
);
registerColumnType
(
Types
.
BINARY
,
"blob"
);
registerColumnType
(
Types
.
VARBINARY
,
"blob"
);
registerColumnType
(
Types
.
LONGVARBINARY
,
"blob"
);
// registerColumnType(Types.NULL, "null");
registerColumnType
(
Types
.
BLOB
,
"blob"
);
registerColumnType
(
Types
.
CLOB
,
"clob"
);
registerColumnType
(
Types
.
BOOLEAN
,
"integer"
);
registerFunction
(
"concat"
,
new
VarArgsSQLFunction
(
StringType
.
INSTANCE
,
""
,
"||"
,
""
));
registerFunction
(
"mod"
,
new
SQLFunctionTemplate
(
StringType
.
INSTANCE
,
"?1 % ?2"
));
registerFunction
(
"substr"
,
new
StandardSQLFunction
(
"substr"
,
StringType
.
INSTANCE
));
registerFunction
(
"substring"
,
new
StandardSQLFunction
(
"substr"
,
StringType
.
INSTANCE
));
}
public
boolean
supportsIdentityColumns
()
{
return
true
;
}
public
boolean
hasDataTypeInIdentityColumn
()
{
return
false
;
// As specify in NHibernate dialect
}
public
String
getIdentityColumnString
()
{
// return "integer primary key autoincrement";
return
"integer"
;
}
public
String
getIdentitySelectString
()
{
return
"select last_insert_rowid()"
;
}
public
boolean
supportsLimit
()
{
return
true
;
}
protected
String
getLimitString
(
String
query
,
boolean
hasOffset
)
{
return
new
StringBuffer
(
query
.
length
()
+
20
).
append
(
query
).
append
(
hasOffset
?
" limit ? offset ?"
:
" limit ?"
)
.
toString
();
}
public
boolean
supportsTemporaryTables
()
{
return
true
;
}
public
String
getCreateTemporaryTableString
()
{
return
"create temporary table if not exists"
;
}
public
boolean
dropTemporaryTableAfterUse
()
{
return
false
;
}
public
boolean
supportsCurrentTimestampSelection
()
{
return
true
;
}
public
boolean
isCurrentTimestampSelectStringCallable
()
{
return
false
;
}
public
String
getCurrentTimestampSelectString
()
{
return
"select current_timestamp"
;
}
public
boolean
supportsUnionAll
()
{
return
true
;
}
public
boolean
hasAlterTable
()
{
return
false
;
// As specify in NHibernate dialect
}
public
boolean
dropConstraints
()
{
return
false
;
}
public
String
getAddColumnString
()
{
return
"add column"
;
}
public
String
getForUpdateString
()
{
return
""
;
}
public
boolean
supportsOuterJoinForUpdate
()
{
return
false
;
}
public
String
getDropForeignKeyString
()
{
throw
new
UnsupportedOperationException
(
"No drop foreign key syntax supported by SQLiteDialect"
);
}
public
String
getAddForeignKeyConstraintString
(
String
constraintName
,
String
[]
foreignKey
,
String
referencedTable
,
String
[]
primaryKey
,
boolean
referencesPrimaryKey
)
{
throw
new
UnsupportedOperationException
(
"No add foreign key syntax supported by SQLiteDialect"
);
}
public
String
getAddPrimaryKeyConstraintString
(
String
constraintName
)
{
throw
new
UnsupportedOperationException
(
"No add primary key syntax supported by SQLiteDialect"
);
}
public
boolean
supportsIfExistsBeforeTableName
()
{
return
true
;
}
public
boolean
supportsCascadeDelete
()
{
return
false
;
}
}
src/main/java/es/ujaen/dae/ujacoin/app/AppUjaBank.java
View file @
044deb99
...
...
@@ -7,6 +7,7 @@ package es.ujaen.dae.ujacoin.app;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
/**
*
...
...
@@ -15,6 +16,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
/** Clase principal de arranque de la aplicación basada en SpringBoot */
@SpringBootApplication
(
scanBasePackages
=
"es.ujaen.dae.ujacoin.beans"
)
@EntityScan
(
basePackages
=
"es.ujaen.dae.ujacoin.entidades"
)
public
class
AppUjaBank
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/es/ujaen/dae/ujacoin/beans/ServicioUjaBankImpl.java
View file @
044deb99
...
...
@@ -107,9 +107,6 @@ public class ServicioUjaBankImpl implements ServicioUjaBank {
cliente
.
a
ñ
adirTarjeta
(
tarjeta
);
tarjeta
.
setClienteAsociado
(
cliente
);
tarjeta
.
setActivado
(
true
);
}
@Override
...
...
@@ -118,7 +115,8 @@ public class ServicioUjaBankImpl implements ServicioUjaBank {
throw
new
SaldoRestanteNoCero
();
}
cuenta
.
setActivado
(
false
);
cuenta
.
getTitular
().
desenlazarCuenta
(
cuenta
);
cuentas
.
remove
(
cuenta
.
getNumero
());
}
...
...
src/main/java/es/ujaen/dae/ujacoin/entidades/Cliente.java
View file @
044deb99
...
...
@@ -9,15 +9,23 @@ import es.ujaen.dae.ujacoin.excepciones.TarjetaYaVinculada;
import
java.time.LocalDate
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.MapKey
;
import
javax.persistence.OneToMany
;
import
javax.persistence.Transient
;
/**
* Clase cliente de UjaBank
*
* @author Adrian
*/
@Entity
public
class
Cliente
{
/**Dni del cliente*/
@Id
private
String
dni
;
/**Nombre del cliente*/
private
String
nombre
;
...
...
@@ -32,10 +40,18 @@ public class Cliente {
/**Contraseña del cliente*/
private
String
clave
;
/**Cuentas de las que es titular*/
@OneToMany
(
mappedBy
=
"titular"
)
@MapKey
(
name
=
"numero"
)
private
Map
<
String
,
Cuenta
>
cuentasAsociadas
;
/**Cuentas de las que es titular*/
@OneToMany
@JoinColumn
@MapKey
(
name
=
"numero"
)
private
Map
<
String
,
Tarjeta
>
tarjetasAsociadas
;
public
Cliente
()
{
}
public
Cliente
(
String
dni
,
String
nombre
,
LocalDate
fechaNacimiento
,
String
direccion
,
String
telefono
,
String
email
,
String
clave
)
{
this
.
dni
=
dni
;
this
.
nombre
=
nombre
;
...
...
@@ -105,6 +121,14 @@ public class Cliente {
}
/**
* Desenlaza la cuenta del usuario
* @param cuenta cuenta a remover
*/
public
void
desenlazarCuenta
(
Cuenta
cuenta
){
cuentasAsociadas
.
remove
(
cuenta
.
getNumero
());
}
/**
* Añade una tarjeta al cliente
* @param tarjeta
*/
...
...
src/main/java/es/ujaen/dae/ujacoin/entidades/Cuenta.java
View file @
044deb99
...
...
@@ -10,18 +10,36 @@ import es.ujaen.dae.ujacoin.excepciones.CuentaNoValida;
import
es.ujaen.dae.ujacoin.excepciones.SaldoInsuficiente
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.MapKey
;
import
javax.persistence.OneToMany
;
import
javax.persistence.Transient
;
/**
* Cuenta de UjaCoins
*
* @author Adrian
*/
public
class
Cuenta
extends
ServicioBancario
{
@Entity
public
class
Cuenta
{
/**
* Número de identificación de la cuenta
*/
@Id
private
String
numero
;
/**
* Titular de la cuenta
*/
@ManyToOne
@JoinColumn
(
name
=
"titularCuenta"
)
private
Cliente
titular
;
/**
* Saldo de la cuenta
*/
...
...
@@ -29,7 +47,11 @@ public class Cuenta extends ServicioBancario{
/**
* Movimientos de la cuenta
*/
private
ArrayList
<
Movimiento
>
movimientos
;
@OneToMany
private
List
<
Movimiento
>
movimientos
;
public
Cuenta
()
{
}
public
Cuenta
(
String
numero
,
Cliente
titular
)
{
...
...
@@ -39,8 +61,7 @@ public class Cuenta extends ServicioBancario{
this
.
numero
=
numero
;
this
.
saldo
=
0
;
this
.
activado
=
true
;
this
.
clienteAsociado
=
titular
;
this
.
titular
=
titular
;
this
.
movimientos
=
new
ArrayList
<>();
}
...
...
@@ -52,11 +73,15 @@ public class Cuenta extends ServicioBancario{
return
saldo
;
}
public
Cliente
getTitular
()
{
return
titular
;
}
public
void
setSaldo
(
float
saldo
)
{
this
.
saldo
=
saldo
;
}
public
Array
List
<
Movimiento
>
getMovimientos
()
{
public
List
<
Movimiento
>
getMovimientos
()
{
return
movimientos
;
}
...
...
src/main/java/es/ujaen/dae/ujacoin/entidades/Movimiento.java
View file @
044deb99
...
...
@@ -10,30 +10,62 @@ import es.ujaen.dae.ujacoin.excepciones.CuentaNoValida;
import
es.ujaen.dae.ujacoin.excepciones.TarjetaNoValida
;
import
es.ujaen.dae.ujacoin.excepciones.TipoMovimientoInvalido
;
import
java.time.LocalDateTime
;
/**Movimientos asociados a las cuentas
import
javax.persistence.Entity
;
import
javax.persistence.ForeignKey
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.OneToOne
;
/**
* Movimientos asociados a las cuentas
*
* @author Adrian
*/
@Entity
public
class
Movimiento
{
/**Tipo de movimiento*/
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
int
identificador
;
/**
* Tipo de movimiento
*/
private
TipoMovimiento
tipo
;
/**Importe del movimiento*/
/**
* Importe del movimiento
*/
private
float
importe
;
/**Fecha y hora del movimiento*/
/**
* Fecha y hora del movimiento
*/
private
LocalDateTime
fechaHora
;
/**Cuenta destino/origen*/
/**
* Cuenta destino/origen
*/
@OneToOne
@JoinColumn
(
name
=
"cuentaOD"
)
private
Cuenta
cuenta
;
/**Tarjeta destino/origen*/
/**
* Tarjeta destino/origen
*/
@OneToOne
@JoinColumn
(
name
=
"tarjetaOD"
)
private
Tarjeta
tarjeta
;
public
Movimiento
()
{
}
public
Movimiento
(
TipoMovimiento
tipo
,
float
importe
,
LocalDateTime
fechaHora
,
Tarjeta
tarjeta
)
{
if
(!(
tipo
==
TipoMovimiento
.
TMIngreso
||
tipo
==
TipoMovimiento
.
TMReintegro
))
throw
new
TipoMovimientoInvalido
();
if
(!(
tipo
==
TipoMovimiento
.
TMIngreso
||
tipo
==
TipoMovimiento
.
TMReintegro
))
{
throw
new
TipoMovimientoInvalido
();
}
if
(!
Tarjeta
.
checkNumeroTarjeta
(
tarjeta
.
getNumero
()))
throw
new
TarjetaNoValida
();
if
(!
Tarjeta
.
checkNumeroTarjeta
(
tarjeta
.
getNumero
()))
{
throw
new
TarjetaNoValida
();
}
this
.
tipo
=
tipo
;
this
.
importe
=
importe
;
...
...
@@ -43,9 +75,13 @@ public class Movimiento {
public
Movimiento
(
TipoMovimiento
tipo
,
float
importe
,
LocalDateTime
fechaHora
,
Cuenta
cuenta
)
{
if
(!(
tipo
==
TipoMovimiento
.
TMTransferenciaEmitida
||
tipo
==
TipoMovimiento
.
TMTrasnferenciaRecibida
))
throw
new
TipoMovimientoInvalido
();
if
(!(
tipo
==
TipoMovimiento
.
TMTransferenciaEmitida
||
tipo
==
TipoMovimiento
.
TMTrasnferenciaRecibida
))
{
throw
new
TipoMovimientoInvalido
();
}
if
(!
Cuenta
.
checkNumeroCuenta
(
cuenta
.
getNumero
()))
throw
new
CuentaNoValida
();
if
(!
Cuenta
.
checkNumeroCuenta
(
cuenta
.
getNumero
()))
{
throw
new
CuentaNoValida
();
}
this
.
tipo
=
tipo
;
this
.
importe
=
importe
;
...
...
@@ -69,5 +105,4 @@ public class Movimiento {
return
tarjeta
;
}
}
src/main/java/es/ujaen/dae/ujacoin/entidades/ServicioBancario.java
deleted
100644 → 0
View file @
ff60b127
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
es
.
ujaen
.
dae
.
ujacoin
.
entidades
;
/**
*
* @author UJA
*/
public
class
ServicioBancario
{
public
ServicioBancario
()
{
}
//Servicio marcado como borrado
boolean
activado
;
Cliente
clienteAsociado
;
public
boolean
isActivado
()
{
return
activado
;
}
public
void
setActivado
(
boolean
activado
)
{
this
.
activado
=
activado
;
}
public
Cliente
getClienteAsociado
()
{
return
clienteAsociado
;
}
public
void
setClienteAsociado
(
Cliente
clienteAsociado
)
{
this
.
clienteAsociado
=
clienteAsociado
;
}
}
src/main/java/es/ujaen/dae/ujacoin/entidades/Tarjeta.java
View file @
044deb99
...
...
@@ -8,12 +8,21 @@ package es.ujaen.dae.ujacoin.entidades;
import
es.ujaen.dae.ujacoin.excepciones.TarjetaNoValida
;
import
java.time.LocalDate
;
import
java.util.Random
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
/**Tarjetas de crédito asociadas a clientes
*
* @author Adrian
*/
public
class
Tarjeta
extends
ServicioBancario
{
@Entity
public
class
Tarjeta
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
int
Identificador
;
/** Número de la tarjeta*/
private
String
numero
;
...
...
@@ -24,6 +33,8 @@ public class Tarjeta extends ServicioBancario{
/** Fecha de caducidad de la tarjeta*/
private
LocalDate
fechaCaducidad
;
public
Tarjeta
()
{
}
private
static
Random
rand
=
new
Random
();
...
...
src/main/resources/application.properties
0 → 100644
View file @
044deb99
spring.jpa.database-platform
=
com.springboot.sqlite.SQLDialect
spring.jpa.hibernate.ddl-auto
=
update
spring.datasource.url
=
jdbc:sqlite:sqlitesample.db
spring.datasource.driver-class-name
=
org.sqlite.JDBC
spring.datasource.username
=
spring.datasource.password
=
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment