Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_dzienna_15_09
Commits
3df0d996
Commit
3df0d996
authored
Oct 04, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wydzielenie interfejsu repository
parent
f745cf05
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
18 deletions
+35
-18
ProductRepository.java
...ing/src/main/java/sklep/repository/ProductRepository.java
+4
-18
ProductRepositoryImpl.java
...src/main/java/sklep/repository/ProductRepositoryImpl.java
+31
-0
No files found.
PC30-SklepSpring/src/main/java/sklep/repository/ProductRepository.java
View file @
3df0d996
...
...
@@ -3,27 +3,12 @@ package sklep.repository;
import
java.util.List
;
import
java.util.Optional
;
import
javax.persistence.EntityManager
;
import
javax.persistence.TypedQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Repository
;
import
sklep.model.Product
;
@Repository
public
class
ProductRepository
{
@Autowired
private
EntityManager
em
;
public
interface
ProductRepository
{
public
List
<
Product
>
findAll
()
{
TypedQuery
<
Product
>
query
=
em
.
createNamedQuery
(
"Product.findAll"
,
Product
.
class
);
return
query
.
getResultList
();
}
List
<
Product
>
findAll
();
public
Optional
<
Product
>
findById
(
int
productId
)
{
Product
product
=
em
.
find
(
Product
.
class
,
productId
);
return
Optional
.
ofNullable
(
product
);
}
Optional
<
Product
>
findById
(
int
productId
);
}
\ No newline at end of file
PC30-SklepSpring/src/main/java/sklep/repository/ProductRepositoryImpl.java
0 → 100644
View file @
3df0d996
package
sklep
.
repository
;
import
java.util.List
;
import
java.util.Optional
;
import
javax.persistence.EntityManager
;
import
javax.persistence.TypedQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Repository
;
import
sklep.model.Product
;
@Repository
public
class
ProductRepositoryImpl
implements
ProductRepository
{
@Autowired
private
EntityManager
em
;
@Override
public
List
<
Product
>
findAll
()
{
TypedQuery
<
Product
>
query
=
em
.
createNamedQuery
(
"Product.findAll"
,
Product
.
class
);
return
query
.
getResultList
();
}
@Override
public
Optional
<
Product
>
findById
(
int
productId
)
{
Product
product
=
em
.
find
(
Product
.
class
,
productId
);
return
Optional
.
ofNullable
(
product
);
}
}
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