Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CommitEventEntity. fixes #350 @50m
- Loading branch information
みぞ@CrazyBeatCoder
committed
Mar 1, 2018
1 parent
23b5808
commit bb80b7e
Showing
7 changed files
with
104 additions
and
6 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
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
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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/mizo0203/komeiji/repo/OfyRepository.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,18 @@ | ||
package com.mizo0203.komeiji.repo; | ||
|
||
import com.googlecode.objectify.ObjectifyService; | ||
import com.mizo0203.komeiji.repo.objectify.entity.CommitEventEntity; | ||
|
||
public class OfyRepository { | ||
private static final OfyRepository ourInstance = new OfyRepository(); | ||
|
||
private OfyRepository() {} | ||
|
||
public static OfyRepository getInstance() { | ||
return ourInstance; | ||
} | ||
|
||
public void saveKeyEntity(CommitEventEntity entity) { | ||
ObjectifyService.ofy().save().entity(entity).now(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/mizo0203/komeiji/repo/objectify/OfyHelper.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,27 @@ | ||
package com.mizo0203.komeiji.repo.objectify; | ||
|
||
import com.googlecode.objectify.ObjectifyService; | ||
import com.mizo0203.komeiji.repo.objectify.entity.CommitEventEntity; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
|
||
/** | ||
* OfyHelper, a ServletContextListener, is setup in web.xml to run before a JSP is run. This is | ||
* required to let JSP's access OfyRepository. | ||
*/ | ||
public class OfyHelper implements ServletContextListener { | ||
|
||
@Override | ||
public void contextInitialized(ServletContextEvent event) { | ||
// This will be invoked as part of a warmup request, or the first user | ||
// request if no warmup | ||
// request. | ||
ObjectifyService.register(CommitEventEntity.class); | ||
} | ||
|
||
@Override | ||
public void contextDestroyed(ServletContextEvent event) { | ||
// App Engine does not currently invoke this method. | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/mizo0203/komeiji/repo/objectify/entity/CommitEventEntity.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,37 @@ | ||
package com.mizo0203.komeiji.repo.objectify.entity; | ||
|
||
import com.googlecode.objectify.annotation.Entity; | ||
import com.googlecode.objectify.annotation.Id; | ||
import com.mizo0203.komeiji.repo.objectify.OfyHelper; | ||
|
||
/** | ||
* The @Entity tells Objectify about our entity. We also register it in {@link OfyHelper} Our | ||
* primary key @Id is set automatically by the Google Datastore for us. | ||
* | ||
* <p>We add a @Parent to tell the object about its ancestor. We are doing this to support many | ||
* guestbooks. Objectify, unlike the AppEngine library requires that you specify the fields you want | ||
* to index using @Index. Only indexing the fields you need can lead to substantial gains in | ||
* performance -- though if not indexing your data from the start will require indexing it later. | ||
* | ||
* <p>NOTE - all the properties are PUBLIC so that can keep the code simple. | ||
*/ | ||
@SuppressWarnings({"FieldCanBeLocal", "unused"}) | ||
@Entity | ||
public class CommitEventEntity { | ||
|
||
@Id private long statusId; | ||
|
||
private String repositoryName; | ||
|
||
private String commitId; | ||
|
||
public CommitEventEntity() { | ||
// CommitEventEntity must have a no-arg constructor | ||
} | ||
|
||
public CommitEventEntity(long statusId, String repositoryName, String commitId) { | ||
this.statusId = statusId; | ||
this.repositoryName = repositoryName; | ||
this.commitId = commitId; | ||
} | ||
} |
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