-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to fix illegal mongo state exception (#41)
- Loading branch information
Showing
3 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 15 additions & 2 deletions
17
src/main/java/pro/jazzman/odmiana/repositories/HistoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
package pro.jazzman.odmiana.repositories; | ||
|
||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.stereotype.Repository; | ||
import pro.jazzman.odmiana.entities.History; | ||
|
||
public interface HistoryRepository extends MongoRepository<History, String> { | ||
@Repository | ||
public class HistoryRepository { | ||
private final MongoTemplate mongo; | ||
|
||
@Autowired | ||
public HistoryRepository(MongoTemplate mongo) { | ||
this.mongo = mongo; | ||
} | ||
|
||
public History save(History history) { | ||
return mongo.save(history); | ||
} | ||
} |
26 changes: 24 additions & 2 deletions
26
src/main/java/pro/jazzman/odmiana/repositories/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
package pro.jazzman.odmiana.repositories; | ||
|
||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.stereotype.Repository; | ||
import pro.jazzman.odmiana.entities.users.User; | ||
|
||
public interface UserRepository extends MongoRepository<User, Long> { | ||
@Repository | ||
public class UserRepository { | ||
private final MongoTemplate mongo; | ||
|
||
@Autowired | ||
public UserRepository(MongoTemplate mongo) { | ||
this.mongo = mongo; | ||
} | ||
|
||
public boolean existsById(Long id) { | ||
Query query = new Query(); | ||
query.addCriteria(Criteria.where("_id").is(id)); | ||
|
||
return mongo.exists(query, User.class); | ||
} | ||
|
||
public User save(User user) { | ||
return mongo.save(user); | ||
} | ||
} |