+++ /dev/null
-/*
- Copyright 2009 senju@users.sourceforge.jp
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-package jp.sourceforge.rabbitBTS;
-
-import javax.jdo.PersistenceManagerFactory;
-
-public final class PMF {
- // private static final PersistenceManagerFactory pmfInstance = JDOHelper
- // .getPersistenceManagerFactory("transactions-optional");
-
- private PMF() {
- };
-
- public static PersistenceManagerFactory get() {
- return PMFSupport.getPmf();
- }
-}
+++ /dev/null
-/*
- Copyright 2009 senju@users.sourceforge.jp
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-package jp.sourceforge.rabbitBTS;
-
-import javax.jdo.PersistenceManagerFactory;
-
-import org.springframework.beans.factory.annotation.Autowired;
-
-/**
- * 一時的に実装するクラス。
- *
- * TODO:DAO化が完了したら削除されるべき
- */
-public class PMFSupport {
- private static PersistenceManagerFactory pmf;
-
- /**
- * @return the pmf
- */
- public static PersistenceManagerFactory getPmf() {
- Sht.log(PMFSupport.class).warning("getPmf() called.");
- return pmf;
- }
-
- /**
- * @param pmf
- * the pmf to set
- */
- @Autowired
- public void setPmf(PersistenceManagerFactory pmf) {
- PMFSupport.pmf = pmf;
- }
-
-}
public Account findAccountByEmail(String email);
+ public Account findAccountByNickName(String nickName);
+
}
public Account findAccountByEmail(String email) {
final Collection<Account> c = getJdoTemplate().find(Account.class,
"email == e", "String e", new Object[] { email });
- if (c.size() == 0) {
+ if (c.isEmpty()) {
+ return null;
+ } else {
+ return c.iterator().next();
+ }
+ }
+
+ public Account findAccountByNickName(String nickName) {
+ final Collection<Account> c = getJdoTemplate().find(Account.class,
+ "nickName == n", "String n", new Object[] { nickName });
+ if (c.isEmpty()) {
return null;
} else {
return c.iterator().next();
}
public boolean exists(PK id) {
- final T entity = (T) getJdoTemplate().getObjectById(
- this.persistentClass, id);
- return entity != null;
+ try {
+ getJdoTemplate().getObjectById(this.persistentClass, id);
+ return true;
+ } catch (final ObjectRetrievalFailureException e) {
+ return false;
+ }
}
+ @SuppressWarnings("unchecked")
public T get(PK id) {
final T entity = (T) getJdoTemplate().getObjectById(
this.persistentClass, id);
-
- if (entity == null) {
- throw new ObjectRetrievalFailureException(this.persistentClass, id);
- }
-
return entity;
}
+ @SuppressWarnings("unchecked")
public T getByKey(Key id) {
final T entity = (T) getJdoTemplate().getObjectById(
this.persistentClass, id);
-
- if (entity == null) {
- throw new ObjectRetrievalFailureException(this.persistentClass, id);
- }
-
return entity;
}
import java.util.Date;
import java.util.List;
-import javax.jdo.JDOObjectNotFoundException;
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-
-import jp.sourceforge.rabbitBTS.PMF;
import jp.sourceforge.rabbitBTS.Sht;
import jp.sourceforge.rabbitBTS.dao.AccountDao;
import jp.sourceforge.rabbitBTS.exceptions.HasNotValidIdException;
import jp.sourceforge.rabbitBTS.models.Account;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
}
/**
- * 指定されたアカウントを登録する。
+ * 指定されたアカウントを登録する。 TODO: トランザクション
*
* @param account
* 登録するアカウント
* 既に登録済みの場合
*/
public void registAccount(Account account) throws RabbitBTSException {
+ // 登録済みチェック
+ if (this.accountDao.findAccountByEmail(account.getEmail()) != null) {
+ throw new RabbitBTSException("既に登録されています。");
+ }
- final PersistenceManager pm = PMF.get().getPersistenceManager();
- final Transaction tx = pm.currentTransaction();
- try {
- tx.begin();
- try {
- // 登録済みチェック
- final Account up = this.fetchAccount();
- if (up != null) {
- throw new RabbitBTSException("既に登録されています。");
- }
- } catch (final HasNotValidIdException e) {
- throw new RabbitBTSException("googleにログインしてください。", e);
- }
-
- // 最初のスーパーユーザーかチェック
- if (account.getEmail().equals(this.firstSuperUser)) {
- account.setAdmin(true);
- Sht.log(this).warning(
- "Admin Account Created. " + this.firstSuperUser);
- }
-
- // nickName重複チェック
- if (fetchAccountByNickName(account.getNickName()) != null) {
- Sht.log(this).info(
- "nickName " + account.getNickName()
- + " is already used.");
- throw new RabbitBTSException("nickNameが重複しています。");
- }
-
- // 登録処理
- account.setLastAccess(new Date());
- pm.makePersistent(account);
-
- // TODO: メッセージ追加
-
- tx.commit();
- } finally {
- if (tx.isActive()) {
- tx.rollback();
- }
+ // 最初のスーパーユーザーかチェック
+ if (account.getEmail().equals(this.firstSuperUser)) {
+ account.setAdmin(true);
+ Sht.log(this).warning(
+ "Admin Account Created. " + this.firstSuperUser);
}
+
+ // nickName重複チェック
+ if (this.accountDao.findAccountByNickName(account.getNickName()) != null) {
+ Sht.log(this).info(
+ "nickName " + account.getNickName() + " is already used.");
+ throw new RabbitBTSException("nickNameが重複しています。");
+ }
+
+ // 登録処理
+ account.setLastAccess(new Date());
+ this.accountDao.save(account);
+
+ // TODO: メッセージ追加
+
}
/**
* 検索するアカウントのニックネーム
* @return 見つかったアカウント。無い場合null。
*/
- @SuppressWarnings("unchecked")
public Account fetchAccountByNickName(String nickName) {
- final PersistenceManager pm = PMF.get().getPersistenceManager();
- final Query q = pm.newQuery(Account.class);
- q.setFilter("nickName == n");
- q.declareParameters("String n");
- final List<Account> accList = (List<Account>) q.execute(nickName);
- if (accList.size() == 0) {
- return null;
- }
- return accList.get(0);
+ final Account account = this.accountDao.findAccountByNickName(nickName);
+ return account;
}
/**
* @return 見つかったアカウント。見つからない場合null。
*/
public Account fetchAccountById(Long id) {
- final PersistenceManager pm = PMF.get().getPersistenceManager();
try {
- final Account account = pm.getObjectById(Account.class, id);
- return account;
- } catch (final JDOObjectNotFoundException e) {
+ return this.accountDao.get(id);
+ } catch (final DataRetrievalFailureException e) {
return null;
}
}
*
* @return 取得したアカウントのリスト
*/
- @SuppressWarnings("unchecked")
public List<Account> fetchAccounts() {
- final PersistenceManager pm = PMF.get().getPersistenceManager();
- final List<Account> accList = (List<Account>) pm
- .newQuery(Account.class).execute();
- return accList;
+ return this.accountDao.getAll();
}
/**
* 削除するアカウント。
*/
public void deleteAccount(Account account) {
- final PersistenceManager pm = PMF.get().getPersistenceManager();
- pm.deletePersistent(account);
+ this.accountDao.remove(account.getAccountId());
}
/**
[#assign title="アカウント削除"]
[#include "/common/head.ftl"]
<h1 class="admin">アカウント削除</h1>
-[@rbts.showGlobalErrors "accForDel" /]
[#if accForDel??]
+[@rbts.showGlobalErrors "accForDel" /]
<p>以下のアカウントを削除します。削除されたアカウントは復元できません。</p>
<form method="post" action="">
<table>