Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DAAExample
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Miguel Ferreiro Díaz
DAAExample
Commits
0ae8f660
Commit
0ae8f660
authored
Feb 13, 2019
by
miferreiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created the pet entity
- Created the pet table - Created the pet class
parent
87613f0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
157 additions
and
0 deletions
+157
-0
mysql-with-inserts.sql
db/mysql-with-inserts.sql
+15
-0
mysql.sql
db/mysql.sql
+11
-0
Pet.java
src/main/java/es/uvigo/esei/daa/entities/Pet.java
+131
-0
No files found.
db/mysql-with-inserts.sql
View file @
0ae8f660
DROP
SCHEMA
IF
EXISTS
`daaexample`
;
CREATE
DATABASE
`daaexample`
;
CREATE
DATABASE
`daaexample`
;
CREATE
TABLE
`daaexample`
.
`people`
(
CREATE
TABLE
`daaexample`
.
`people`
(
...
@@ -14,6 +15,16 @@ CREATE TABLE `daaexample`.`users` (
...
@@ -14,6 +15,16 @@ CREATE TABLE `daaexample`.`users` (
PRIMARY
KEY
(
`login`
)
PRIMARY
KEY
(
`login`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`daaexample`
.
`pet`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
50
)
NOT
NULL
,
`breed`
varchar
(
50
)
NOT
NULL
,
`idOwner`
int
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
FOREIGN
KEY
(
`idOwner`
)
REFERENCES
`people`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
GRANT
ALL
ON
`daaexample`
.
*
TO
'daa'
@
'localhost'
IDENTIFIED
BY
'daa'
;
GRANT
ALL
ON
`daaexample`
.
*
TO
'daa'
@
'localhost'
IDENTIFIED
BY
'daa'
;
INSERT
INTO
`daaexample`
.
`people`
(
`id`
,
`name`
,
`surname`
)
VALUES
(
0
,
'Antón'
,
'Pérez'
);
INSERT
INTO
`daaexample`
.
`people`
(
`id`
,
`name`
,
`surname`
)
VALUES
(
0
,
'Antón'
,
'Pérez'
);
...
@@ -30,3 +41,7 @@ INSERT INTO `daaexample`.`users` (`login`,`password`,`role`)
...
@@ -30,3 +41,7 @@ INSERT INTO `daaexample`.`users` (`login`,`password`,`role`)
VALUES
(
'admin'
,
'713bfda78870bf9d1b261f565286f85e97ee614efe5f0faf7c34e7ca4f65baca'
,
'ADMIN'
);
VALUES
(
'admin'
,
'713bfda78870bf9d1b261f565286f85e97ee614efe5f0faf7c34e7ca4f65baca'
,
'ADMIN'
);
INSERT
INTO
`daaexample`
.
`users`
(
`login`
,
`password`
,
`role`
)
INSERT
INTO
`daaexample`
.
`users`
(
`login`
,
`password`
,
`role`
)
VALUES
(
'normal'
,
'7bf24d6ca2242430343ab7e3efb89559a47784eea1123be989c1b2fb2ef66e83'
,
'USER'
);
VALUES
(
'normal'
,
'7bf24d6ca2242430343ab7e3efb89559a47784eea1123be989c1b2fb2ef66e83'
,
'USER'
);
INSERT
INTO
`daaexample`
.
`pet`
(
`id`
,
`name`
,
`breed`
,
`idOwner`
)
VALUES
(
0
,
'Rex'
,
'Pastor Aleman'
,
1
);
INSERT
INTO
`daaexample`
.
`pet`
(
`id`
,
`name`
,
`breed`
,
`idOwner`
)
VALUES
(
0
,
'Idefix'
,
'Terrier'
,
2
);
INSERT
INTO
`daaexample`
.
`pet`
(
`id`
,
`name`
,
`breed`
,
`idOwner`
)
VALUES
(
0
,
'Snoopy'
,
'Beagle'
,
3
);
\ No newline at end of file
db/mysql.sql
View file @
0ae8f660
DROP
SCHEMA
IF
EXISTS
`daaexample`
;
CREATE
DATABASE
`daaexample`
;
CREATE
DATABASE
`daaexample`
;
CREATE
TABLE
`daaexample`
.
`people`
(
CREATE
TABLE
`daaexample`
.
`people`
(
...
@@ -14,4 +15,14 @@ CREATE TABLE `daaexample`.`users` (
...
@@ -14,4 +15,14 @@ CREATE TABLE `daaexample`.`users` (
PRIMARY
KEY
(
`login`
)
PRIMARY
KEY
(
`login`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`daaexample`
.
`pet`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
50
)
NOT
NULL
,
`breed`
varchar
(
50
)
NOT
NULL
,
`idOwner`
int
NOT
NULL
,
PRIMARY
KEY
(
`id`
),
FOREIGN
KEY
(
`idOwner`
)
REFERENCES
`people`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
GRANT
ALL
ON
`daaexample`
.
*
TO
'daa'
@
'localhost'
IDENTIFIED
BY
'daa'
;
GRANT
ALL
ON
`daaexample`
.
*
TO
'daa'
@
'localhost'
IDENTIFIED
BY
'daa'
;
src/main/java/es/uvigo/esei/daa/entities/Pet.java
0 → 100644
View file @
0ae8f660
package
es
.
uvigo
.
esei
.
daa
.
entities
;
import
static
java
.
util
.
Objects
.
requireNonNull
;
/**
* An entity that represents a pet.
*
* @author Miguel Ferreiro Diaz
*/
public
class
Pet
{
private
int
id
;
private
String
name
;
private
String
breed
;
private
int
idOwner
;
// Constructor needed for the JSON conversion
Pet
()
{}
/**
* Constructs a new instance of {@link Person}.
*
* @param id identifier of the pet.
* @param name name of the pet.
* @param breed breed of the pet.
* @param idOwner owner of the pet
*/
public
Pet
(
int
id
,
String
name
,
String
breed
,
int
idOwner
)
{
this
.
id
=
id
;
this
.
setName
(
name
);
this
.
setBreed
(
breed
);
this
.
setIdOwner
(
idOwner
);
}
/**
* Returns the identifier of the pet.
*
* @return the identifier of the pet.
*/
public
int
getId
()
{
return
id
;
}
/**
* Returns the name of the pet.
*
* @return the name of the pet.
*/
public
String
getName
()
{
return
name
;
}
/**
* Set the name of this pet.
*
* @param name the new name of the pet.
* @throws NullPointerException if the {@code name} is {@code null}.
*/
public
void
setName
(
String
name
)
{
this
.
name
=
requireNonNull
(
name
,
"Name can't be null"
);
}
/**
* Returns the breed of the pet.
*
* @return the breed of the pet.
*/
public
String
getBreed
()
{
return
breed
;
}
/**
* Set the breed of this pet.
*
* @param breed the new breed of the person.
* @throws NullPointerException if the {@code breed} is {@code null}.
*/
public
void
setBreed
(
String
breed
)
{
this
.
breed
=
requireNonNull
(
breed
,
"Name can't be null"
);
}
/**
* Returns the owner of the pet
*
* @return the owner of the pet
*/
public
int
getIdOwner
()
{
return
idOwner
;
}
/**
* Set the owner of the pet
*
* @param idOwner the new owner of the pet
* @throws NullPointerException if the {@code idOwner} is {@code null}.
*/
public
void
setIdOwner
(
int
idOwner
)
{
this
.
idOwner
=
requireNonNull
(
idOwner
,
"Name can't be null"
);
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
breed
==
null
)
?
0
:
breed
.
hashCode
());
result
=
prime
*
result
+
id
;
result
=
prime
*
result
+
idOwner
;
result
=
prime
*
result
+
((
name
==
null
)
?
0
:
name
.
hashCode
());
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
Pet
other
=
(
Pet
)
obj
;
if
(
breed
==
null
)
{
if
(
other
.
breed
!=
null
)
return
false
;
}
else
if
(!
breed
.
equals
(
other
.
breed
))
return
false
;
if
(
id
!=
other
.
id
)
return
false
;
if
(
idOwner
!=
other
.
idOwner
)
return
false
;
if
(
name
==
null
)
{
if
(
other
.
name
!=
null
)
return
false
;
}
else
if
(!
name
.
equals
(
other
.
name
))
return
false
;
return
true
;
}
}
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