[mud4j-commit] SF.net SVN: mud4j: [62] trunk/mud4j-core/src/java/net/sf/mud4j
Status: Pre-Alpha
Brought to you by:
mpurland
|
From: <mpu...@us...> - 2006-12-24 23:10:23
|
Revision: 62
http://mud4j.svn.sourceforge.net/mud4j/?rev=62&view=rev
Author: mpurland
Date: 2006-12-24 15:10:20 -0800 (Sun, 24 Dec 2006)
Log Message:
-----------
Add start of dao implementations.
Added Paths:
-----------
trunk/mud4j-core/src/java/net/sf/mud4j/account/
trunk/mud4j-core/src/java/net/sf/mud4j/account/Account.java
trunk/mud4j-core/src/java/net/sf/mud4j/dao/
trunk/mud4j-core/src/java/net/sf/mud4j/dao/AccountDao.java
trunk/mud4j-core/src/java/net/sf/mud4j/dao/CharacterDao.java
trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/
trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/AccountDaoHibernate.java
trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/CharacterDaoHibernate.java
Added: trunk/mud4j-core/src/java/net/sf/mud4j/account/Account.java
===================================================================
--- trunk/mud4j-core/src/java/net/sf/mud4j/account/Account.java (rev 0)
+++ trunk/mud4j-core/src/java/net/sf/mud4j/account/Account.java 2006-12-24 23:10:20 UTC (rev 62)
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2006 Matthew Purland (m.p...@gm...)
+ *
+ * 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 net.sf.mud4j.account;
+
+/**
+ *
+ *
+ * @author Matthew Purland
+ */
+public class Account {
+ // Username of the account
+ private String username;
+ // Password of the account
+ private String password;
+ /**
+ * Get the password.
+ *
+ * @return the password.
+ */
+ public String getPassword() {
+ return this.password;
+ }
+ /**
+ * Set the password.
+ *
+ * @param password the password to set.
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+ /**
+ * Get the username.
+ *
+ * @return the username.
+ */
+ public String getUsername() {
+ return this.username;
+ }
+ /**
+ * Set the username.
+ *
+ * @param username the username to set.
+ */
+ public void setUsername(String username) {
+ this.username = username;
+ }
+}
Added: trunk/mud4j-core/src/java/net/sf/mud4j/dao/AccountDao.java
===================================================================
--- trunk/mud4j-core/src/java/net/sf/mud4j/dao/AccountDao.java (rev 0)
+++ trunk/mud4j-core/src/java/net/sf/mud4j/dao/AccountDao.java 2006-12-24 23:10:20 UTC (rev 62)
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2006 Matthew Purland (m.p...@gm...)
+ *
+ * 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 net.sf.mud4j.dao;
+
+import java.util.List;
+
+import net.sf.mud4j.account.Account;
+
+import org.springframework.dao.DataAccessException;
+import org.springframework.dao.PermissionDeniedDataAccessException;
+
+/**
+ * Account dao interface.
+ *
+ * @author Matthew Purland
+ */
+public interface AccountDao {
+ /**
+ * Get list of accounts.
+ * @return Returns a list of accounts.
+ * @throws DataAccessException in case of data access I/O problems
+ */
+ List getAccounts() throws DataAccessException;
+
+ /**
+ * Load an account from the username.
+ *
+ * @param username Username of the account to load.
+ * @return Returns an account from the username.
+ * @throws DataAccessException in case of data access I/O problems
+ */
+ Account loadAccount(String username) throws DataAccessException;
+
+ /**
+ * Load an account from the username accessed by a password.
+ *
+ * @param username Username of the account.
+ * @param password Password of the account to verify.
+ * @return Returns an account if verified.
+ * @throws DataAccessException in case of data access I/O
+ * @throws PermissionDeniedDataAccessException if password is incorrect
+ */
+ Account loadAccount(String username, String password) throws DataAccessException, PermissionDeniedDataAccessException;
+}
Added: trunk/mud4j-core/src/java/net/sf/mud4j/dao/CharacterDao.java
===================================================================
--- trunk/mud4j-core/src/java/net/sf/mud4j/dao/CharacterDao.java (rev 0)
+++ trunk/mud4j-core/src/java/net/sf/mud4j/dao/CharacterDao.java 2006-12-24 23:10:20 UTC (rev 62)
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2006 Matthew Purland (m.p...@gm...)
+ *
+ * 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 net.sf.mud4j.dao;
+
+import java.util.List;
+
+import org.springframework.dao.DataAccessException;
+
+/**
+ * Character dao interface.
+ *
+ * @author Matthew Purland
+ */
+public interface CharacterDao {
+ /**
+ * Get a character that matches the characterId.
+ *
+ * @param characterId Character id to find character.
+ * @return Returns character from characterId
+ *
+ * @throws DataAccessException in case of data I/O problems
+ */
+ public Character getCharacter(String characterId) throws DataAccessException;
+
+ /**
+ * Get list of characters.
+ *
+ * @return Returns a list of characters.
+ *
+ * @throws DataAccessException in case of data I/O problems
+ */
+ public List getCharacters() throws DataAccessException;
+
+ /**
+ * Save and persist a character.
+ * @param character Character instance to save.
+ *
+ * @throws DataAccessException in case of data I/O problems
+ */
+ public void saveCharacter(Character character) throws DataAccessException;
+
+ /**
+ * Remove a character.
+ *
+ * @param character Character to remove.
+ *
+ * @throws DataAccessException in case of data I/O problems
+ */
+ public void removeCharacter(String characterId) throws DataAccessException;
+}
Added: trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/AccountDaoHibernate.java
===================================================================
--- trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/AccountDaoHibernate.java (rev 0)
+++ trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/AccountDaoHibernate.java 2006-12-24 23:10:20 UTC (rev 62)
@@ -0,0 +1,65 @@
+/**
+ * Copyright 2006 Matthew Purland (m.p...@gm...)
+ *
+ * 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 net.sf.mud4j.dao.hibernate;
+
+import java.util.List;
+
+import org.springframework.dao.DataAccessException;
+import org.springframework.dao.PermissionDeniedDataAccessException;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+import net.sf.mud4j.account.Account;
+import net.sf.mud4j.dao.AccountDao;
+
+/**
+ * Account dao implementation for hibernate.
+ *
+ * @author Matthew Purland
+ */
+public class AccountDaoHibernate extends HibernateDaoSupport implements AccountDao {
+
+ /**
+ * {@inheritDoc}
+ */
+ public List getAccounts() throws DataAccessException {
+ return getHibernateTemplate().find("from Account");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Account loadAccount(String username) throws DataAccessException {
+ Object account = getHibernateTemplate().load(Account.class, username);
+
+ return (Account) account;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Account loadAccount(String username, String password) throws DataAccessException, PermissionDeniedDataAccessException {
+ Account account = (Account) getHibernateTemplate().load(Account.class, username);
+
+ if (!account.getPassword().equals(password)) {
+ throw new RuntimeException("Password is incorrect");
+ //throw new DataAccessException("Password is incorrect.");
+ }
+
+ return account;
+ }
+
+
+}
Added: trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/CharacterDaoHibernate.java
===================================================================
--- trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/CharacterDaoHibernate.java (rev 0)
+++ trunk/mud4j-core/src/java/net/sf/mud4j/dao/hibernate/CharacterDaoHibernate.java 2006-12-24 23:10:20 UTC (rev 62)
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2006 Matthew Purland (m.p...@gm...)
+ *
+ * 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 net.sf.mud4j.dao.hibernate;
+
+import java.util.List;
+
+import net.sf.mud4j.dao.CharacterDao;
+
+import org.springframework.dao.DataAccessException;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+/**
+ * Character dao for hibernate support.
+ *
+ * @author Matthew Purland
+ */
+public class CharacterDaoHibernate extends HibernateDaoSupport implements CharacterDao {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Character getCharacter(String characterId) throws DataAccessException {
+ return (Character) getHibernateTemplate().get(Character.class, characterId);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List getCharacters() throws DataAccessException {
+ return getHibernateTemplate().find("from Character");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeCharacter(String characterId) throws DataAccessException {
+ Object character = getHibernateTemplate().load(Character.class, characterId);
+ getHibernateTemplate().delete(character);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void saveCharacter(Character character) throws DataAccessException {
+ getHibernateTemplate().save(character);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|