/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/Mailbox.java |
---|
0,0 → 1,170 |
package ak.webcontrol.core.model; |
import java.util.Date; |
import ak.webcontrol.util.Digest; |
/** |
* |
* @hibernate.class table="mailboxes" |
*/ |
public class Mailbox |
implements ModelObject |
{ |
private Long id; |
private String login; |
private String password; |
private InetDomain domain; |
private User owner; |
private Boolean virusCheck; |
private Boolean spamCheck; |
private SystemUser systemUser; |
private Date modStamp; |
protected Mailbox() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getLogin() |
{ |
return login; |
} |
public void setLogin(String login) |
{ |
this.login = login; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getPassword() |
{ |
return password; |
} |
public void setPassword(String password) |
{ |
this.password = password; |
} |
public void setNewPassword(String password) |
{ |
if(password == null) |
throw new NullPointerException("Null password"); |
this.password = Digest.encode(password); |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public InetDomain getDomain() |
{ |
return domain; |
} |
public void setDomain(InetDomain domain) |
{ |
this.domain = domain; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
public void setOwner(User owner) |
{ |
this.owner = owner; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getVirusCheck() |
{ |
return virusCheck; |
} |
public void setVirusCheck(Boolean virusCheck) |
{ |
this.virusCheck = virusCheck; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Boolean getSpamCheck() |
{ |
return spamCheck; |
} |
public void setSpamCheck(Boolean spamCheck) |
{ |
this.spamCheck = spamCheck; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public SystemUser getSystemUser() |
{ |
return systemUser; |
} |
public void setSystemUser(SystemUser systemUser) |
{ |
this.systemUser = systemUser; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_MAILBOX; |
} |
public String getIdentificationString() |
{ |
return getLogin() + "@" + getDomain().getName(); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAlias.java |
---|
0,0 → 1,123 |
package ak.webcontrol.core.model; |
import java.util.Collection; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="mailaliases" |
*/ |
public class MailAlias |
implements ModelObject |
{ |
private Long id; |
private String address; |
private InetDomain domain; |
private User owner; |
private Collection destinations; // Collection(MailAliasDestintion) |
private Date modStamp; |
protected MailAlias() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getAddress() |
{ |
return address; |
} |
public void setAddress(String address) |
{ |
this.address = address; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public InetDomain getDomain() |
{ |
return domain; |
} |
public void setDomain(InetDomain domain) |
{ |
this.domain = domain; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
public void setOwner(User owner) |
{ |
this.owner = owner; |
} |
/** |
* @return Collection(MailAliasDestination) |
* |
* @hibernate.bag inverse="true" cascade="all-delete-orphan" |
* @hibernate.collection-key column="alias" |
* @hibernate.collection-one-to-many class="ak.webcontrol.core.model.MailAliasDestination" |
*/ |
public Collection getDestinations() |
{ |
return destinations; |
} |
/** |
* @param destinations Collection(MailAliasDestination) |
*/ |
protected void setDestinations(Collection destinations) |
{ |
this.destinations = destinations; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_MAIL_ALIAS; |
} |
public String getIdentificationString() |
{ |
return getAddress() + "@" + getDomain().getName(); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasDestination.java |
---|
0,0 → 1,101 |
package ak.webcontrol.core.model; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="mailaliasdests" |
*/ |
public class MailAliasDestination |
implements ModelObject |
{ |
private Long id; |
private MailAlias alias; |
private Mailbox mailbox; |
private String email; |
private Date modStamp; |
protected MailAliasDestination() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public MailAlias getAlias() |
{ |
return alias; |
} |
public void setAlias(MailAlias alias) |
{ |
this.alias = alias; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public Mailbox getMailbox() |
{ |
return mailbox; |
} |
public void setMailbox(Mailbox mailbox) |
{ |
this.mailbox = mailbox; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getEmail() |
{ |
return email; |
} |
public void setEmail(String email) |
{ |
this.email = email; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_MAIL_ALIAS_DESTINATION; |
} |
public String getIdentificationString() |
{ |
return (getMailbox() == null) ? getEmail() : getMailbox().getIdentificationString(); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/SystemUserManager.java |
---|
0,0 → 1,191 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class SystemUserManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(SystemUserManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/SystemUser.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private SystemUserManager() |
{ |
} |
public SystemUser create() |
{ |
return new SystemUser(); |
} |
public SystemUser get(Long id) |
throws ModelException |
{ |
try { |
return (SystemUser)HibernateUtil.currentSession().load(SystemUser.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public SystemUser findForName(String name) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from SystemUser where name=?", name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (SystemUser)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public SystemUser findForUid(Integer uid) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from SystemUser where uid=?", uid, Hibernate.INTEGER); |
if(list.size() == 0) |
return null; |
else |
return (SystemUser)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(SystemUser systemUser) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(systemUser); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(SystemUser systemUser) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(systemUser); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listSystemUsers() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from SystemUser"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static SystemUserManager systemUserManager = null; |
public static SystemUserManager getInstance() |
{ |
if(systemUserManager == null) |
systemUserManager = new SystemUserManager(); |
return systemUserManager; |
} |
public static final Comparator UID_COMPARATOR = new UidComparator(); |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
private static class UidComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof SystemUser) || !(o2 instanceof SystemUser)) |
throw new ClassCastException("not a SystemUser"); |
SystemUser a1 = (SystemUser)o1; |
SystemUser a2 = (SystemUser)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getUid().compareTo(a2.getUid()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof UidComparator); |
} |
} |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof SystemUser) || !(o2 instanceof SystemUser)) |
throw new ClassCastException("not a SystemUser"); |
SystemUser a1 = (SystemUser)o1; |
SystemUser a2 = (SystemUser)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/User.java |
---|
0,0 → 1,124 |
package ak.webcontrol.core.model; |
import java.util.Date; |
import ak.webcontrol.util.Digest; |
/** |
* |
* @hibernate.class table="users" |
*/ |
public class User |
implements ModelObject |
{ |
private Long id; |
private String login; |
private String password; |
private Date modStamp; |
protected User() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getLogin() |
{ |
return login; |
} |
public void setLogin(String login) |
{ |
this.login = login; |
} |
/** |
* |
* @hibernate.property |
*/ |
protected String getPassword() |
{ |
return password; |
} |
protected void setPassword(String password) |
{ |
this.password = password; |
} |
public void setNewPassword(String password) |
{ |
if(password == null) |
throw new NullPointerException("Null password"); |
this.password = Digest.encode(password); |
} |
public boolean checkPassword(String password) |
{ |
if(password == null) |
throw new NullPointerException("Null password"); |
return checkMd5Password(Digest.encode(password)); |
} |
public boolean checkMd5Password(String password) |
{ |
return this.password.equals(password); |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public boolean equals(Object o) |
{ |
if(!(o instanceof User)) return false; |
User u = (User)o; |
return (id != null) && (u.getId() != null) && (id.equals(u.getId())); |
} |
public int hashCode() |
{ |
if(id == null) |
return 0; |
else |
return id.hashCode(); |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_USER; |
} |
public String getIdentificationString() |
{ |
return getLogin(); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/test/Test.java |
---|
0,0 → 1,164 |
package ak.webcontrol.core.model.test; |
import net.sf.hibernate.*; |
import ak.webcontrol.core.model.*; |
import ak.webcontrol.util.*; |
public class Test |
{ |
public static void test() |
throws Exception |
{ |
// delete objects if they are already in the database |
HibernateUtil.currentSession().delete( |
"from MailAlias where address like ?", "%@test.domain", Hibernate.STRING); |
HibernateUtil.currentSession().delete( |
"from SystemUser where uid=?", new Integer(1001), Hibernate.INTEGER); |
HibernateUtil.currentSession().delete( |
"from Mailbox where login=?", "testuser@test.domain", Hibernate.STRING); |
HibernateUtil.currentSession().delete( |
"from InetDomain where name=?", "test.domain", Hibernate.STRING); |
HibernateUtil.currentSession().delete( |
"from User where login=?", "testuser", Hibernate.STRING); |
HibernateUtil.currentSession().flush(); |
User user; |
InetDomain inetDomain; |
Mailbox mailbox; |
MailAlias mailAlias; |
SystemUser systemUser; |
// create objects |
user = UserManager.getInstance().create(); |
user.setLogin("testuser"); |
user.setNewPassword("none"); |
UserManager.getInstance().save(user); |
inetDomain = InetDomainManager.getInstance().create(); |
inetDomain.setName("test.domain"); |
inetDomain.setOwner(UserManager.getInstance().findForLogin("testuser")); |
InetDomainManager.getInstance().save(inetDomain); |
systemUser = SystemUserManager.getInstance().create(); |
systemUser.setUid(new Integer(1001)); |
systemUser.setName("test"); |
SystemUserManager.getInstance().save(systemUser); |
mailbox = MailboxManager.getInstance().create(); |
mailbox.setLogin("testuser@test.domain"); |
mailbox.setDomain(InetDomainManager.getInstance().findForName("test.domain")); |
mailbox.setOwner(UserManager.getInstance().findForLogin("testuser")); |
mailbox.setVirusCheck(new Boolean(true)); |
mailbox.setSpamCheck(new Boolean(false)); |
mailbox.setSystemUser(systemUser); |
MailboxManager.getInstance().save(mailbox); |
mailAlias = MailAliasManager.getInstance().create(); |
mailAlias.setAddress("some.name@test.domain"); |
mailAlias.setDomain(InetDomainManager.getInstance().findForName("test.domain")); |
mailAlias.setOwner(UserManager.getInstance().findForLogin("testuser")); |
MailAliasManager.getInstance().save(mailAlias); |
HibernateUtil.currentSession().flush(); |
} |
public static void testUser() |
throws Exception |
{ |
User user = UserManager.getInstance().findForLogin("testuser"); |
if(user == null) { |
System.out.println("create new user"); |
user = UserManager.getInstance().create(); |
} |
else { |
System.out.println("get existing user"); |
} |
user.setLogin("testuser"); |
// |
// benchmark hibernate update |
// |
int benchmarkCount = 100; |
// first measure object change time |
long startTime = System.currentTimeMillis(); |
for(int i = 0; i < benchmarkCount; i++) { |
user.setNewPassword((i % 2 == 0) ? "a" : "b"); |
} |
// then object change & DB update |
long betweenTime = System.currentTimeMillis(); |
for(int i = 0; i < benchmarkCount; i++) { |
user.setNewPassword((i % 2 == 0) ? "a" : "b"); |
UserManager.getInstance().save(user); |
HibernateUtil.currentSession().flush(); |
} |
// results |
long endTime = System.currentTimeMillis(); |
System.out.println("Object change: " + (betweenTime-startTime) + " ms"); |
System.out.println("DB update: " + (endTime-betweenTime) + " ms"); |
user.setNewPassword("none"); |
UserManager.getInstance().save(user); |
} |
public static void testInetDomain() |
throws Exception |
{ |
InetDomain inetDomain = InetDomainManager.getInstance().findForName("test.domain"); |
if(inetDomain == null) { |
System.out.println("create new domain"); |
inetDomain = InetDomainManager.getInstance().create(); |
} |
else { |
System.out.println("get existing domain"); |
} |
inetDomain.setName("test.domain"); |
inetDomain.setOwner(UserManager.getInstance().findForLogin("testuser")); |
InetDomainManager.getInstance().save(inetDomain); |
} |
public static void main(String[] args) |
throws Exception |
{ |
UserManager.getInstance(); |
InetDomainManager.getInstance(); |
SystemUserManager.getInstance(); |
MailboxManager.getInstance(); |
MailAliasManager.getInstance(); |
try { |
HibernateUtil.beginTransaction(); |
//testUser(); |
//testInetDomain(); |
test(); |
HibernateUtil.commitTransaction(); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
HibernateUtil.rollbackTransaction(); |
throw ex; |
} |
finally { |
HibernateUtil.closeSession(); |
} |
} |
private static String randomString(int len) |
throws java.io.UnsupportedEncodingException |
{ |
byte[] buf = new byte[len]; |
for(int i = 0; i < len; i++) { |
buf[i] = (byte)(Math.random() * 26 + 97); |
} |
return new String(buf, "ascii"); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/InetDomainManager.java |
---|
0,0 → 1,145 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class InetDomainManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(InetDomainManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/InetDomain.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private InetDomainManager() |
{ |
} |
public InetDomain create() |
{ |
return new InetDomain(); |
} |
public InetDomain get(Long id) |
throws ModelException |
{ |
try { |
return (InetDomain)HibernateUtil.currentSession().load(InetDomain.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public InetDomain findForName(String name) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from InetDomain where name=?", name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (InetDomain)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(InetDomain inetDomain) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(inetDomain); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(InetDomain inetDomain) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(inetDomain); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listInetDomains() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from InetDomain"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static InetDomainManager inetDomainManager = null; |
public static InetDomainManager getInstance() |
{ |
if(inetDomainManager == null) |
inetDomainManager = new InetDomainManager(); |
return inetDomainManager; |
} |
public static final Comparator NAME_COMPARATOR = new NameComparator(); |
private static class NameComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof InetDomain) || !(o2 instanceof InetDomain)) |
throw new ClassCastException("not a InetDomain"); |
InetDomain a1 = (InetDomain)o1; |
InetDomain a2 = (InetDomain)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getName().compareToIgnoreCase(a2.getName()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof NameComparator); |
} |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/SystemUser.java |
---|
0,0 → 1,88 |
package ak.webcontrol.core.model; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="systemusers" |
*/ |
public class SystemUser |
implements ModelObject |
{ |
private Long id; |
/** user id in the OS */ |
private Integer uid; |
private String name; |
private Date modStamp; |
protected SystemUser() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public Integer getUid() |
{ |
return uid; |
} |
public void setUid(Integer uid) |
{ |
this.uid = uid; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_SYSTEM_USER; |
} |
public String getIdentificationString() |
{ |
return getName() + " (" + getUid() + ")"; // FIXME: is it really so good style? |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailboxManager.java |
---|
0,0 → 1,158 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class MailboxManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(MailboxManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/Mailbox.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private MailboxManager() |
{ |
} |
public Mailbox create() |
{ |
return new Mailbox(); |
} |
public Mailbox get(Long id) |
throws ModelException |
{ |
try { |
return (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Mailbox findForLogin(String login) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from Mailbox where login=?", login, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (Mailbox)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(Mailbox mailbox) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailbox); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(Mailbox mailbox) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(mailbox); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailboxes() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from Mailbox"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailboxes(User owner) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from Mailbox where owner=?", owner, Hibernate.entity(User.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static MailboxManager mailboxManager = null; |
public static MailboxManager getInstance() |
{ |
if(mailboxManager == null) |
mailboxManager = new MailboxManager(); |
return mailboxManager; |
} |
public static final Comparator LOGIN_COMPARATOR = new LoginComparator(); |
private static class LoginComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof Mailbox) || !(o2 instanceof Mailbox)) |
throw new ClassCastException("not a Mailbox"); |
Mailbox a1 = (Mailbox)o1; |
Mailbox a2 = (Mailbox)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getLogin().compareToIgnoreCase(a2.getLogin()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof LoginComparator); |
} |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/InetDomain.java |
---|
0,0 → 1,86 |
package ak.webcontrol.core.model; |
import java.util.Date; |
/** |
* |
* @hibernate.class table="domains" |
*/ |
public class InetDomain |
implements ModelObject |
{ |
private Long id; |
private String name; |
private User owner; |
private Date modStamp; |
protected InetDomain() |
{ |
} |
/** |
* |
* @hibernate.id generator-class="native" |
*/ |
public Long getId() |
{ |
return id; |
} |
public void setId(Long id) |
{ |
this.id = id; |
} |
/** |
* |
* @hibernate.property |
*/ |
public String getName() |
{ |
return name; |
} |
public void setName(String name) |
{ |
this.name = name; |
} |
/** |
* |
* @hibernate.many-to-one |
*/ |
public User getOwner() |
{ |
return owner; |
} |
public void setOwner(User owner) |
{ |
this.owner = owner; |
} |
/** |
* |
* @hibernate.timestamp column="mod_stamp" |
*/ |
public Date getModStamp() |
{ |
return modStamp; |
} |
public void setModStamp(Date modStamp) |
{ |
this.modStamp = modStamp; |
} |
public String getTypeKey() |
{ |
return ak.webcontrol.core.CoreResources.TYPE_DOMAIN; |
} |
public String getIdentificationString() |
{ |
return getName(); |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasManager.java |
---|
0,0 → 1,160 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class MailAliasManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(MailAliasManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/MailAlias.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private MailAliasManager() |
{ |
} |
public MailAlias create() |
{ |
MailAlias alias = new MailAlias(); |
alias.setDestinations(new ArrayList()); |
return alias; |
} |
public MailAlias get(Long id) |
throws ModelException |
{ |
try { |
return (MailAlias)HibernateUtil.currentSession().load(MailAlias.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public MailAlias findForName(String name) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from MailAlias where name=?", name, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (MailAlias)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(MailAlias mailAlias) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAlias); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(MailAlias mailAlias) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(mailAlias); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailAliases() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from MailAlias"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailAliases(User owner) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from MailAlias where owner=?", owner, Hibernate.entity(User.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static MailAliasManager mailAliasManager = null; |
public static MailAliasManager getInstance() |
{ |
if(mailAliasManager == null) |
mailAliasManager = new MailAliasManager(); |
return mailAliasManager; |
} |
public static final Comparator ADDRESS_COMPARATOR = new AddressComparator(); |
private static class AddressComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof MailAlias) || !(o2 instanceof MailAlias)) |
throw new ClassCastException("not a MailAlias"); |
MailAlias a1 = (MailAlias)o1; |
MailAlias a2 = (MailAlias)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getAddress().compareToIgnoreCase(a2.getAddress()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof AddressComparator); |
} |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/ModelObject.java |
---|
0,0 → 1,8 |
package ak.webcontrol.core.model; |
public interface ModelObject |
{ |
public String getTypeKey(); |
public String getIdentificationString(); |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailAliasDestinationManager.java |
---|
0,0 → 1,135 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class MailAliasDestinationManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(MailAliasDestinationManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/MailAliasDestination.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private MailAliasDestinationManager() |
{ |
} |
public MailAliasDestination create() |
{ |
return new MailAliasDestination(); |
} |
public MailAliasDestination get(Long id) |
throws ModelException |
{ |
try { |
return (MailAliasDestination)HibernateUtil.currentSession() |
.load(MailAliasDestination.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(MailAliasDestination mailAliasDestination) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(mailAliasDestination); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(MailAliasDestination mailAliasDestination) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(mailAliasDestination); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listMailAliasesDestination() |
{ |
return null; |
} |
public Collection listMailAliasesDestination(MailAlias alias) |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find( |
"from MailAliasDestination where alias=?", |
alias, Hibernate.entity(MailAlias.class)); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
private static MailAliasDestinationManager mailAliasDestinationManager = null; |
public static MailAliasDestinationManager getInstance() |
{ |
if(mailAliasDestinationManager == null) |
mailAliasDestinationManager = new MailAliasDestinationManager(); |
return mailAliasDestinationManager; |
} |
public static final Comparator EMAIL_COMPARATOR = new EmailComparator(); |
private static class EmailComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof MailAliasDestination) || !(o2 instanceof MailAliasDestination)) |
throw new ClassCastException("not a MailAliasDestination"); |
MailAliasDestination a1 = (MailAliasDestination)o1; |
MailAliasDestination a2 = (MailAliasDestination)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getEmail().compareToIgnoreCase(a2.getEmail()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof EmailComparator); |
} |
} |
} |
/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/UserManager.java |
---|
0,0 → 1,162 |
package ak.webcontrol.core.model; |
import java.util.*; |
import net.sf.hibernate.*; |
import ak.webcontrol.util.HibernateUtil; |
import ak.webcontrol.util.ModelException; |
public class UserManager |
{ |
private static boolean registered = false; |
protected static void register() |
{ |
synchronized(MailboxManager.class) { |
if(registered) return; |
registered = true; |
try { |
HibernateUtil.getConfiguration().addResource( |
"/ak/webcontrol/core/model/User.hbm.xml"); |
} |
catch(Exception ex) { |
ex.printStackTrace(); |
throw new RuntimeException(ex.getMessage()); |
} |
} |
} |
static { |
register(); |
} |
private UserManager() |
{ |
} |
public User create() |
{ |
return new User(); |
} |
public User get(Long id) |
throws ModelException |
{ |
try { |
return (User)HibernateUtil.currentSession().load(User.class, id); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public User findForLogin(String login) |
throws ModelException |
{ |
try { |
List list = HibernateUtil.currentSession().find( |
"from User where login=?", login, Hibernate.STRING); |
if(list.size() == 0) |
return null; |
else |
return (User)list.get(0); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void save(User user) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().saveOrUpdate(user); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public void delete(User user) |
throws ModelException |
{ |
try { |
HibernateUtil.currentSession().delete(user); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public Collection listUsers() |
throws ModelException |
{ |
try { |
return HibernateUtil.currentSession().find("from User"); |
} |
catch(HibernateException ex) |
{ |
throw new ModelException(ex); |
} |
} |
public User loginUser(String login, String password) |
throws ModelException |
{ |
if(login == null || password == null) |
return null; |
User user = findForLogin(login); |
if(user != null) { |
if(user.checkPassword(password)) |
return user; |
} |
// wrong login or password |
return null; |
} |
private static UserManager userManager = null; |
public static UserManager getInstance() |
{ |
if(userManager == null) |
userManager = new UserManager(); |
return userManager; |
} |
public static final Comparator LOGIN_COMPARATOR = new LoginComparator(); |
private static class LoginComparator |
implements Comparator |
{ |
public int compare(Object o1, Object o2) |
{ |
if(!(o1 instanceof User) || !(o2 instanceof User)) |
throw new ClassCastException("not a User"); |
User a1 = (User)o1; |
User a2 = (User)o2; |
if(a1 == null && a2 == null) |
return 0; |
else if(a1 == null && a2 != null) |
return -1; |
else if(a1 != null && a2 == null) |
return 1; |
else |
return a1.getLogin().compareToIgnoreCase(a2.getLogin()); |
} |
public boolean equals(Object obj) |
{ |
return (obj instanceof LoginComparator); |
} |
} |
} |