Here they are:
the superclass Account
Code:
package de.splendid.cca.modules.email.model.beans;
import java.util.Date;
/**
* Represents an account belonging to a
* {@link de.splendid.cca.modules.email.model.beans.Domain} of a
* {@link de.splendid.cca.model.beans.Company}.
*
* @hibernate.class
* table="account"
* @hibernate.discriminator
* column="account_type"
*
*/
public abstract class Account
implements IAccount
{
/**
* the id of this account.
*/
protected int accountId;
protected String localpart;
protected String description;
protected Domain domain;
protected Date creationDate;
protected String accountType;
protected Account()
{
/* hibernate needs default constructor */
}
public Account(String localpart, Domain domain)
{
this.localpart = localpart;
this.domain = domain;
domain.addAccount(this);
}
/**
* @hibernate.property
* column="creation_date"
* not-null="true"
*/
public Date getCreationDate()
{
return creationDate;
}
/**
* @hibernate.property
* column="description"
* not-null="true"
*/
public String getDescription()
{
return description;
}
/**
* @hibernate.many-to-one
* column="domain_id"
* not-null="true"
* cascade="save-update"
*
* @return
*/
public Domain getDomain()
{
return domain;
}
/**
* @hibernate.property
* column="localpart"
* not-null="true"
*/
public String getLocalpart()
{
return localpart;
}
/**
* @hibernate.id
* column="account_id"
* generator-class="identity"
*
* @return
*/
public int getAccountId()
{
return accountId;
}
public void setAccountId(int accountId)
{
this.accountId = accountId;
}
public void setCreationDate(Date creationDate)
{
this.creationDate = creationDate;
}
public void setDescription(String description)
{
this.description = description;
}
public void setLocalpart(String localpart)
{
this.localpart = localpart;
}
/**
* Returns the name of the underlying domain.
*
* @return the name of the underlying domain
*/
public String getDomainName()
{
return domain.getName();
}
/**
* Returns the email address of this account which is
* <code>localpart</code>@<code>domainName</code>.
*
* @return the email address of this account
*/
public String getEmailAddress()
{
return getLocalpart()+"@"+getDomainName();
}
/**
* Two accounts are equal if they have the same localpart and
* domain.
*/
public boolean equals(Object obj)
{
boolean result = true;
try {
Account otherAccount = (Account) obj;
result = (this.localpart.equals(otherAccount.localpart)) &&
(this.domain.equals(otherAccount.domain));
} catch (ClassCastException e) {
result = false;
}
return result;
}
public int hashCode()
{
return this.localpart.hashCode()+this.domain.getName().hashCode();
}
protected void setDomain(Domain domain)
{
this.domain = domain;
}
/**
* The hibernate mapping definition comes from a merge file
* since xdoclet 1.2.2 does not seem to support the 'insert' and
* 'update' attributes of the (@)hibernate.property. We
* need these attributes since this property is the discriminator
* for the subclasses.
*
* @return
*/
public String getAccountType()
{
return accountType;
}
public void setAccountType(String accountType)
{
this.accountType = accountType;
}
}
The xdoclet-merge file isCode:
<!--
hibernate-properties-Account.xml
xdoclet 1.2.2 does not support the insert and update attribute
in a (@)hibernate.property. Therefore we need to merge this
property.
-->
<property
name="accountType"
type="java.lang.String"
column="account_type"
not-null="true"
insert="false"
update="false"
/>
One of the subclassesCode:
package de.splendid.cca.modules.email.model.beans;
import java.util.Date;
import java.util.Set;
/**
* A real account has a physical size on a mail cluster.
*
* @hibernate.subclass
* discriminator-value="RA"
*
*/
public class RealAccount
extends Account
{
/**
* The size of the account in MB.
*/
private int size;
/**
* The amount of MB already in use.
* This value can only be achieved by requesting it from the
* mail cluster. When this value is set the timestamp
* {@link #used_updated} will be updated.
*/
private int used;
/**
* Timestamp in milliseconds since 1.1.1970
* of the last update of the {@link #used} value.
* May be 0 to indicate that the {@link #used} value is
* still undefined.
* This value can not be set directly, only indirectly via
* {@link #setUsed(int)}.
*/
private long usedUpdated;
/**
* The owner of the account in plain text.
*/
private String owner;
/**
* The set of {@link AliasAccount alias accounts}.
*/
private Set aliasSet;
protected RealAccount()
{
/* Hibernate needs default constructor */
}
public RealAccount(
String localpart,
Domain domain,
int size,
String owner)
{
super(localpart,domain);
this.size = size;
this.owner = owner;
this.creationDate = new Date();
this.description = "";
}
/**
* @hibernate.property
* column="owner"
*
* @return
*/
public String getOwner()
{
return owner;
}
public void setOwner(String owner)
{
this.owner = owner;
}
/**
* @hibernate.property
* column="size"
*
* @return
*/
public int getSize()
{
return size;
}
public void setSize(int size)
{
this.size = size;
}
/**
* @hibernate.property
* column="used"
*
* @return
*/
public int getUsed()
{
return used;
}
/**
* Sets the value {@link #usedUpdated} to the current time
* ({@link System#currentTimeMillis()}), too.
*
* @param used
*/
public void setUsed(int used)
{
this.used = used;
this.usedUpdated = System.currentTimeMillis();
}
/**
* @hibernate.property
* column="used_updated"
*
* @return
*/
public long getUsedUpdated()
{
return usedUpdated;
}
/**
* // TODO define hibernate mapping
* @return
*/
public Set getAliasSet()
{
return aliasSet;
}
public void setAliasSet(Set aliasSet)
{
this.aliasSet = aliasSet;
}
protected void setUsedUpdated(long usedUpdated)
{
this.usedUpdated = usedUpdated;
}
public String toString()
{
StringBuffer result = new StringBuffer();
result.append("RealAccount[");
result.append(getEmailAddress());
result.append(",size=").append(getSize()).append("MB");
result.append(",owner=").append(getOwner());
result.append(",type=").append(getAccountType());
result.append("]");
return result.toString();
}
public RealAccount addAliasAccount(AliasAccount aliasAccount)
{
this.getAliasSet().add(aliasAccount);
aliasAccount.setRealAccount(this);
return this;
}
}
hibernate mapping fileCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="de.splendid.cca.modules.email.model.beans.Account"
table="account"
>
<id
name="accountId"
column="account_id"
type="int"
>
<generator class="identity">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Account.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator
column="account_type"
/>
<property
name="creationDate"
type="java.util.Date"
column="creation_date"
not-null="true"
/>
<property
name="description"
type="java.lang.String"
column="description"
not-null="true"
/>
<many-to-one
name="domain"
class="de.splendid.cca.modules.email.model.beans.Domain"
cascade="save-update"
outer-join="auto"
column="domain_id"
not-null="true"
/>
<property
name="localpart"
type="java.lang.String"
column="localpart"
not-null="true"
/>
<!--
hibernate-properties-Account.xml
xdoclet 1.2.2 does not support the insert and update attribute
in a (@)hibernate.property. Therefore we need to merge this
property.
-->
<property
name="accountType"
type="java.lang.String"
column="account_type"
not-null="true"
insert="false"
update="false"
/>
<subclass
name="de.splendid.cca.modules.email.model.beans.AliasAccount"
discriminator-value="AA"
>
<many-to-one
name="realAccount"
class="de.splendid.cca.modules.email.model.beans.RealAccount"
cascade="none"
outer-join="auto"
column="real_account_id"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-AliasAccount.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="de.splendid.cca.modules.email.model.beans.RealAccount"
discriminator-value="RA"
>
<property
name="owner"
type="java.lang.String"
column="owner"
/>
<property
name="size"
type="int"
column="size"
/>
<property
name="used"
type="int"
column="used"
/>
<property
name="usedUpdated"
type="long"
column="used_updated"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-RealAccount.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
<subclass
name="de.splendid.cca.modules.email.model.beans.MailList"
discriminator-value="ML"
>
<set
name="accountSet"
table="maillist_account"
lazy="false"
cascade="none"
sort="unsorted"
>
<key
column="maillist_id"
>
</key>
<many-to-many
class="de.splendid.cca.modules.email.model.beans.Account"
column="account_id"
outer-join="auto"
/>
</set>
<set
name="externalAccountSet"
table="maillist_externalaccount"
lazy="true"
cascade="none"
sort="unsorted"
>
<key
column="maillist_id"
>
</key>
<many-to-many
class="de.splendid.cca.modules.email.model.beans.ExternalAccount"
column="external_account_id"
outer-join="auto"
/>
</set>
<property
name="name"
type="java.lang.String"
column="maillistname"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-MailList.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</class>
</hibernate-mapping>
An example of a query build by hibernate is
Code:
select accountset0_.domain_id as domain_id__, accountset0_.account_id as account_id__, accountset0_.account_id as account_id0_, accountset0_.account_type as account_2_0_, accountset0_.creation_date as creation3_0_, accountset0_.description as descript4_0_, accountset0_.domain_id as domain_id0_, accountset0_.localpart as localpart0_, accountset0_.real_account_id as real_acc7_0_, accountset0_.owner as owner0_, accountset0_.size as size0_, accountset0_.used as used0_, accountset0_.used_updated as used_up11_0_, accountset0_.maillistname as maillis12_0_ from account accountset0_ where accountset0_.domain_id=? order by accountset0_.localpart