vincenzo 2003/07/17 06:26:12
Modified: src/conf Tag: branch_2_1_fcs sqlResources.xml
src/java/org/apache/james/core Tag: branch_2_1_fcs
MailImpl.java
src/java/org/apache/james/mailrepository Tag: branch_2_1_fcs
JDBCMailRepository.java
Log:
Implementing "forward" compatibility for mail attributes.
Revision Changes Path
No revision
No revision
1.16.4.6 +12 -12 james-server/src/conf/sqlResources.xml
Index: sqlResources.xml
===================================================================
RCS file: /home/cvs/james-server/src/conf/sqlResources.xml,v
retrieving revision 1.16.4.5
retrieving revision 1.16.4.6
diff -u -r1.16.4.5 -r1.16.4.6
--- sqlResources.xml 15 Jul 2003 10:12:44 -0000 1.16.4.5
+++ sqlResources.xml 17 Jul 2003 13:26:12 -0000 1.16.4.6
@@ -225,7 +225,7 @@
remote_host varchar (255) NOT NULL ,
remote_addr varchar (20) NOT NULL ,
message_body longblob NOT NULL ,
- message_attributes longblob NOT NULL ,
+ message_attributes longblob NULL ,
last_updated datetime NOT NULL,
PRIMARY KEY (repository_name, message_name)
)
@@ -241,7 +241,7 @@
remote_host varchar (255) NOT NULL ,
remote_addr varchar (20) NOT NULL ,
message_body varchar NOT NULL ,
- message_attributes varchar NOT NULL ,
+ message_attributes varchar NULL ,
last_updated timestamp NOT NULL,
PRIMARY KEY (repository_name, message_name)
)
@@ -257,7 +257,7 @@
[remote_host] [varchar] (255) NOT NULL ,
[remote_addr] [varchar] (20) NOT NULL ,
[message_body] [image] NOT NULL ,
- [message_attributes] [image] NOT NULL ,
+ [message_attributes] [image] NULL ,
[last_updated] [datetime] NOT NULL,
PRIMARY KEY (repository_name, message_name)
)
@@ -273,7 +273,7 @@
remote_host varchar2(100) NOT NULL ,
remote_addr varchar2(20) NOT NULL ,
message_body long raw NOT NULL ,
- message_attributes long raw NOT NULL ,
+ message_attributes long raw NULL ,
last_updated date NOT NULL ,
PRIMARY KEY (repository_name, message_name)
)
@@ -290,7 +290,7 @@
remote_host varchar (255) NOT NULL ,
remote_addr varchar (20) NOT NULL ,
message_body bytea NOT NULL ,
- message_attributes bytea NOT NULL ,
+ message_attributes bytea NULL ,
last_updated timestamp NOT NULL,
PRIMARY KEY (repository_name, message_name)
)
@@ -306,7 +306,7 @@
remote_host varchar (100) NOT NULL ,
remote_addr varchar (20) NOT NULL ,
message_body long byte NOT NULL ,
- message_attributes long byte NOT NULL ,
+ message_attributes long byte NULL ,
last_updated date NOT NULL,
PRIMARY KEY (repository_name, message_name)
)
@@ -380,7 +380,7 @@
remote_host varchar (255) NOT NULL ,
remote_addr varchar (20) NOT NULL ,
message_body varchar NOT NULL ,
- message_attributes varchar NOT NULL ,
+ message_attributes varchar NULL ,
last_updated timestamp NOT NULL,
PRIMARY KEY (message_name, repository_name)
)
@@ -396,7 +396,7 @@
remote_host varchar (255) NOT NULL ,
remote_addr varchar (20) NOT NULL ,
message_body longblob NOT NULL ,
- message_attributes longblob NOT NULL ,
+ message_attributes longblob NULL ,
last_updated datetime NOT NULL,
PRIMARY KEY (message_name, repository_name)
)
@@ -412,7 +412,7 @@
[remote_host] [varchar] (255) NOT NULL ,
[remote_addr] [varchar] (20) NOT NULL ,
[message_body] [image] NOT NULL ,
- [message_attributes] [image] NOT NULL ,
+ [message_attributes] [image] NULL ,
[last_updated] [datetime] NOT NULL,
PRIMARY KEY (message_name, repository_name)
)
@@ -428,7 +428,7 @@
remote_host varchar2(255) NOT NULL ,
remote_addr varchar2(20) NOT NULL ,
message_body long raw NOT NULL ,
- message_attributes long raw NOT NULL ,
+ message_attributes long raw NULL ,
last_updated date NOT NULL ,
PRIMARY KEY (message_name, repository_name)
)
@@ -444,7 +444,7 @@
remote_host varchar (255) NOT NULL ,
remote_addr varchar (20) NOT NULL ,
message_body bytea NOT NULL ,
- message_attributes bytea NOT NULL ,
+ message_attributes bytea NULL ,
last_updated timestamp NOT NULL,
PRIMARY KEY (message_name, repository_name)
)
@@ -460,7 +460,7 @@
remote_host varchar (255) NOT NULL ,
remote_addr varchar (20) NOT NULL ,
message_body long byte NOT NULL ,
- message_attributes long byte NOT NULL ,
+ message_attributes long byte NULL ,
last_updated date NOT NULL,
PRIMARY KEY (message_name, repository_name)
)
No revision
No revision
1.17.4.4 +30 -12 james-server/src/java/org/apache/james/core/MailImpl.java
Index: MailImpl.java
===================================================================
RCS file: /home/cvs/james-server/src/java/org/apache/james/core/MailImpl.java,v
retrieving revision 1.17.4.3
retrieving revision 1.17.4.4
diff -u -r1.17.4.3 -r1.17.4.4
--- MailImpl.java 15 Jul 2003 10:12:44 -0000 1.17.4.3
+++ MailImpl.java 17 Jul 2003 13:26:12 -0000 1.17.4.4
@@ -80,8 +80,15 @@
import java.util.HashMap;
/**
- * Wraps a MimeMessage adding routing information (from SMTP) and some simple
- * API enhancements.
+ * <P>Wraps a MimeMessage adding routing information (from SMTP) and some simple
+ * API enhancements.</P>
+ * <P>From James version > 2.2.0a8 "mail attributes" have been added.
+ * Backward and forward compatibility is supported:
+ * messages stored in file repositories <I>without</I> attributes by James version
<= 2.2.0a8
+ * will be processed by later versions as having an empty attributes hashmap;
+ * messages stored in file repositories <I>with</I> attributes by James version >
2.2.0a8
+ * will be processed by previous versions, ignoring the attributes.</P>
+ *
* @version CVS $Revision$ $Date$
*/
public class MailImpl implements Disposable, Mail {
@@ -519,14 +526,17 @@
name = (String) in.readObject();
remoteHost = (String) in.readObject();
remoteAddr = (String) in.readObject();
- Object o = in.readObject();
- //this check is done to be backwards compatible with mail repositories
- if (o instanceof Date) {
- setLastUpdated((Date)o);
- attributes = new HashMap();
- } else {
- attributes = (HashMap)o;
- setLastUpdated((Date) in.readObject());
+ setLastUpdated((Date) in.readObject());
+ // the following is under try/catch to be backwards compatible
+ // with messages created with James version <= 2.2.0a8
+ try {
+ attributes = (HashMap) in.readObject();
+ } catch (OptionalDataException ode) {
+ if (ode.eof) {
+ attributes = new HashMap();
+ } else {
+ throw ode;
+ }
}
}
/**
@@ -545,8 +555,8 @@
out.writeObject(name);
out.writeObject(remoteHost);
out.writeObject(remoteAddr);
- out.writeObject(attributes);
out.writeObject(lastUpdated);
+ out.writeObject(attributes);
}
/**
@@ -569,6 +579,7 @@
* Note: This method is not exposed in the Mail interface,
* it is for internal use by James only.
* @return Serializable of the entire attributes collection
+ * @since 2.2.0
**/
public HashMap getAttributesRaw ()
{
@@ -581,6 +592,7 @@
* Note: This method is not exposed in the Mail interface,
* it is for internal use by James only.
* @return Serializable of the entire attributes collection
+ * @since 2.2.0
**/
public void setAttributesRaw (HashMap attr)
{
@@ -589,36 +601,42 @@
/**
* @see org.apache.mailet.Mail#getAttribute(String)
+ * @since 2.2.0
*/
public Serializable getAttribute(String key) {
return (Serializable)attributes.get(key);
}
/**
* @see org.apache.mailet.Mail#setAttribute(String,Serializable)
+ * @since 2.2.0
*/
public Serializable setAttribute(String key, Serializable object) {
return (Serializable)attributes.put(key, object);
}
/**
* @see org.apache.mailet.Mail#removeAttribute(String)
+ * @since 2.2.0
*/
public Serializable removeAttribute(String key) {
return (Serializable)attributes.remove(key);
}
/**
* @see org.apache.mailet.Mail#removeAllAttributes()
+ * @since 2.2.0
*/
public void removeAllAttributes() {
attributes.clear();
}
/**
* @see org.apache.mailet.Mail#getAttributeNames()
+ * @since 2.2.0
*/
public Iterator getAttributeNames() {
return attributes.keySet().iterator();
}
/**
* @see org.apache.mailet.Mail#hasAttributes()
+ * @since 2.2.0
*/
public boolean hasAttributes() {
return !attributes.isEmpty();
No revision
No revision
1.30.4.8 +8 -5
james-server/src/java/org/apache/james/mailrepository/JDBCMailRepository.java
Index: JDBCMailRepository.java
===================================================================
RCS file:
/home/cvs/james-server/src/java/org/apache/james/mailrepository/JDBCMailRepository.java,v
retrieving revision 1.30.4.7
retrieving revision 1.30.4.8
diff -u -r1.30.4.7 -r1.30.4.8
--- JDBCMailRepository.java 15 Jul 2003 10:12:45 -0000 1.30.4.7
+++ JDBCMailRepository.java 17 Jul 2003 13:26:12 -0000 1.30.4.8
@@ -774,10 +774,13 @@
if (rsMessageAttr.next()) {
try {
byte[] serialized_attr = rsMessageAttr.getBytes(1);
- ByteArrayInputStream bais = new ByteArrayInputStream
(serialized_attr);
- ObjectInputStream ois = new ObjectInputStream (bais);
- attributes = (HashMap)ois.readObject();
- ois.close();
+ // this check is for better backwards compatibility
+ if (serialized_attr != null) {
+ ByteArrayInputStream bais = new
ByteArrayInputStream(serialized_attr);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ attributes = (HashMap)ois.readObject();
+ ois.close();
+ }
} catch (IOException ioe) {
if (getLogger().isDebugEnabled()) {
StringBuffer debugBuffer =
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]