-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/com/skiwi/githubhooksechatservice/dao/FollowedRepoDAO.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.skiwi.githubhooksechatservice.dao; | ||
|
||
import java.util.List; | ||
|
||
import com.skiwi.githubhooksechatservice.model.FollowedRepository; | ||
|
||
|
||
public interface FollowedRepoDAO { | ||
|
||
void update(String name, long lastChecked, long lastEventId); | ||
List<FollowedRepository> getAll(); | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/skiwi/githubhooksechatservice/dao/FollowedRepoDAOImpl.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.skiwi.githubhooksechatservice.dao; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hibernate.Query; | ||
import org.hibernate.Session; | ||
import org.hibernate.SessionFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.skiwi.githubhooksechatservice.model.FollowedRepository; | ||
|
||
@Repository | ||
public class FollowedRepoDAOImpl implements FollowedRepoDAO { | ||
|
||
@Autowired | ||
private SessionFactory sessionFactory; | ||
|
||
private Session openSession() { | ||
return sessionFactory.getCurrentSession(); | ||
} | ||
|
||
@Override | ||
public void update(String name, long lastChecked, long lastEventId) { | ||
try { | ||
Query query = openSession().createQuery("from FollowedRepository repo where repo.name = :name"); | ||
query.setParameter("name", name); | ||
FollowedRepository repo = (FollowedRepository) query.uniqueResult(); | ||
if (repo != null) { | ||
repo.setLastChecked(lastChecked); | ||
repo.setLastEventId(lastEventId); | ||
openSession().merge(repo); | ||
return; | ||
} | ||
|
||
repo = new FollowedRepository(); | ||
repo.setName(name); | ||
repo.setLastChecked(lastChecked); | ||
repo.setLastEventId(lastEventId); | ||
openSession().persist(repo); | ||
} | ||
catch (Exception ex) { | ||
System.out.println("BIG FAT ERROR: " + ex); | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public List<FollowedRepository> getAll() { | ||
try { | ||
Query query = openSession().createQuery("from FollowedRepository repo"); | ||
@SuppressWarnings("unchecked") | ||
List<FollowedRepository> repos = query.list(); | ||
return repos; | ||
} | ||
catch (Exception ex) { | ||
System.out.println("BIG FAT ERROR: " + ex); | ||
ex.printStackTrace(); | ||
return new ArrayList<FollowedRepository>(); | ||
} | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/skiwi/githubhooksechatservice/model/FollowedRepository.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.skiwi.githubhooksechatservice.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name="followed_repo") | ||
public class FollowedRepository { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
|
||
private String name; | ||
|
||
private long lastChecked; | ||
|
||
private long lastEventId; | ||
|
||
private String roomIds; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public long getLastChecked() { | ||
return lastChecked; | ||
} | ||
|
||
public long getLastEventId() { | ||
return lastEventId; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public void setLastChecked(long lastChecked) { | ||
this.lastChecked = lastChecked; | ||
} | ||
|
||
public void setLastEventId(long lastEventId) { | ||
this.lastEventId = lastEventId; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getRoomIds() { | ||
return roomIds; | ||
} | ||
|
||
public void setRoomIds(String roomIds) { | ||
this.roomIds = roomIds; | ||
} | ||
|
||
} |