ディバゲ:聖石スクラッチ、9連×12回引いてみた
スマフォゲーム「ディバインゲート」の聖石スクラッチを108回=9連×12回引いてみた。
その結果、 聖石の個数は次の通り。
虹の聖石が1個出ればいいと思っていたが、3個出たのは驚きだった。
- 風の聖石:2
- 闇の聖石:1
- 無の聖石:1
- 虹の聖石:3
コンピュータ(主にプログラミング)、ゲームについて、その他諸々。
2016年はHaskellの勉強!! (^_^)/
import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import org.hibernate.service.jdbc.connections.spi.ConnectionProvider; */ public class HibernateConfigService { private static HibernateConfigService instance = null; private Configuration configration = null; private SessionFactory sessionFactory = null; private ConnectionProvider connProvider = null; protected HibernateConfigService() { String configFileName = System.getenv("hibernateConfig"); if (configFileName == null) { configration = new Configuration().configure(); } else { configration = new Configuration().configure(configFileName); } } public static HibernateConfigService getInstance() { if(instance == null) { instance = new HibernateConfigService(); } return instance; } /** * <p>[ユニットテスト用]{@link HibernateConfigService}インスタンスを取得する</p> * @param pConnectionProvider {@link ConnectionProvider}インスタンス * @return {@link HibernateConfigService}インスタンス */ public static HibernateConfigService getInstance(final ConnectionProvider pConnectionProvider) { if(instance == null) { instance = new HibernateConfigService(); } instance.setConnProvider(pConnectionProvider); return instance; } @SuppressWarnings("deprecation") public SessionFactory getSessionFactory() { if(sessionFactory == null) { ServiceRegistryBuilder builder = new ServiceRegistryBuilder() .applySettings(configration.getProperties()); if (connProvider != null) { builder = builder.addService(ConnectionProvider.class, connProvider); } ServiceRegistry serviceRegistry = builder.buildServiceRegistry(); sessionFactory = configration.buildSessionFactory(serviceRegistry); } return sessionFactory; } private void setConnProvider(ConnectionProvider pConnProvider) { this.connProvider = pConnProvider; } public Configuration getConfigration() { return this.configration; } }
dbSession.createQuery("select count(*) from User") .uniqueResult();
dbSession.createCriteria(User.class) .setFirstResult((pageNo - 1) * MAX_ITEM_PAGE) .setMaxResults(MAX_ITEM_PAGE) .list();
import org.hibernate.Session; import org.slim3.controller.Controller; import org.slim3.controller.Navigation; public class ListController { private final int MAX_ITEM_PAGE = 20; private Session _dbSession = null; @Override protected Navigation setUp() { this._dbSession = sessionScope("dbSession"); if (this._dbSession == null) { HibernateConfigService hibernateConfigService = HibernateConfigService.getInstance(); this._dbSession = hibernateConfigService.getSessionFactory().openSession(); sessionScope("dbSession", this._dbSession); } return super.setUp(); } @Override public Navigation run() throws Exception { List<String> msgList = new ArrayList<String>(); Session dbSession = getDbSession(); Long count = (Long)dbSession.createQuery("select count(*) from User").uniqueResult(); Integer pageNo = asInteger("pageNo"); if (pageNo == null) { pageNo = 1; } requestScope("pageNo", pageNo); long maxPageNo = (count - 1) / MAX_ITEM_PAGE + 1; requestScope("maxPageNo", maxPageNo); List<User> list = (List<User>)dbSession.createCriteria(User.class) .setFirstResult((pageNo - 1) * MAX_ITEM_PAGE) .setMaxResults(MAX_ITEM_PAGE) .list(); requestScope("list", list); return forward("list.jsp"); } protected Session getDbSession() { return this._dbSession; } }
import java.util.Date; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Version; @Entity @Table(name = "User") public class User implements java.io.Serializable { private int id; private String name; private String email; private Date timestamp; private Set<Division> divisions = new HashSet<Division>(); public User() { } public User(String name, Set<Division> divisions) { this.name = name; this.divisions = divisions; } /** * idを取得する * @return id */ @Id @Column(name = "id", unique = true, nullable = false) public int getId() { return this.id; } /** * idを設定する * @param id */ public void setId(int id) { this.id = id; } /** * timestampを取得する * @return timestamp */ @Version @Temporal(TemporalType.TIMESTAMP) @Column(name = "timestamp") public Date getTimestamp() { return this.timestamp; } /** * timestampを設定する * @param timestamp */ public void setTimestamp(Date timestamp) { this.timestamp = timestamp; } /** * divisionsを取得する * @return divisions */ @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name = "UserDivision", joinColumns = { @JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "division_id")}) public Set<Division> getDivisions() { return this.divisions; } /** * divisionsを設定する * @param divisions */ public void setDivisions(Set<Division> divisions) { this.divisions = divisions; } }