001/**************************************************************** 002 * Licensed to the Apache Software Foundation (ASF) under one * 003 * or more contributor license agreements. See the NOTICE file * 004 * distributed with this work for additional information * 005 * regarding copyright ownership. The ASF licenses this file * 006 * to you under the Apache License, Version 2.0 (the * 007 * "License"); you may not use this file except in compliance * 008 * with the License. You may obtain a copy of the License at * 009 * * 010 * http://www.apache.org/licenses/LICENSE-2.0 * 011 * * 012 * Unless required by applicable law or agreed to in writing, * 013 * software distributed under the License is distributed on an * 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 015 * KIND, either express or implied. See the License for the * 016 * specific language governing permissions and limitations * 017 * under the License. * 018 ****************************************************************/ 019package org.apache.james.mailbox.jpa.mail.model; 020 021import javax.persistence.Basic; 022import javax.persistence.Column; 023import javax.persistence.Entity; 024import javax.persistence.GeneratedValue; 025import javax.persistence.Id; 026import javax.persistence.Table; 027 028import org.apache.james.mailbox.store.mail.model.Property; 029import org.apache.openjpa.persistence.jdbc.Index; 030 031@Entity(name = "Property") 032@Table(name = "JAMES_MAIL_PROPERTY") 033public class JPAProperty implements Property { 034 035 /** The system unique key */ 036 @Id 037 @GeneratedValue 038 @Column(name = "PROPERTY_ID", nullable = true) 039 // TODO The columnNames are not interpreted, see OPENJPA-223 to fix 040 // MAILBOX-186 041 @Index(name = "INDEX_PROPERTY_MSG_ID", columnNames = { "MAILBOX_ID", "MAIL_UID" }) 042 private long id; 043 044 /** Order within the list of properties */ 045 @Basic(optional = false) 046 @Column(name = "PROPERTY_LINE_NUMBER", nullable = false) 047 @Index(name = "INDEX_PROPERTY_LINE_NUMBER") 048 private int line; 049 050 /** Local part of the name of this property */ 051 @Basic(optional = false) 052 @Column(name = "PROPERTY_LOCAL_NAME", nullable = false, length = 500) 053 private String localName; 054 055 /** Namespace part of the name of this property */ 056 @Basic(optional = false) 057 @Column(name = "PROPERTY_NAME_SPACE", nullable = false, length = 500) 058 private String namespace; 059 060 /** Value of this property */ 061 @Basic(optional = false) 062 @Column(name = "PROPERTY_VALUE", nullable = false, length = 1024) 063 private String value; 064 065 /** 066 * @deprecated enhancement only 067 */ 068 @Deprecated 069 public JPAProperty() { 070 } 071 072 /** 073 * Constructs a property. 074 * 075 * @param localName 076 * not null 077 * @param namespace 078 * not null 079 * @param value 080 * not null 081 */ 082 public JPAProperty(String namespace, String localName, String value, int order) { 083 super(); 084 this.localName = localName; 085 this.namespace = namespace; 086 this.value = value; 087 this.line = order; 088 } 089 090 /** 091 * Constructs a property cloned from the given. 092 * 093 * @param property 094 * not null 095 */ 096 public JPAProperty(Property property, int order) { 097 this(property.getNamespace(), property.getLocalName(), property.getValue(), order); 098 } 099 100 /** 101 * Create a copy of the give JPAProperty 102 * 103 * @param property 104 */ 105 public JPAProperty(JPAProperty property) { 106 this(property.getNamespace(), property.getLocalName(), property.getValue(), property.getOrder()); 107 } 108 109 /** 110 * Gets the order of this property. 111 * 112 * @return order of this property 113 */ 114 public int getOrder() { 115 return line; 116 } 117 118 /** 119 * Gets the local part of the name of the property. 120 * 121 * @return not null 122 */ 123 public String getLocalName() { 124 return localName; 125 } 126 127 /** 128 * Gets the namespace for the name. 129 * 130 * @return not null 131 */ 132 public String getNamespace() { 133 return namespace; 134 } 135 136 /** 137 * Gets the value for this property. 138 * 139 * @return not null 140 */ 141 public String getValue() { 142 return value; 143 } 144 145 @Override 146 public int hashCode() { 147 final int PRIME = 31; 148 int result = 1; 149 result = PRIME * result + (int) (id ^ (id >>> 32)); 150 return result; 151 } 152 153 @Override 154 public boolean equals(Object obj) { 155 if (this == obj) 156 return true; 157 if (obj == null) 158 return false; 159 if (getClass() != obj.getClass()) 160 return false; 161 final JPAProperty other = (JPAProperty) obj; 162 if (id != other.id) 163 return false; 164 return true; 165 } 166 167 /** 168 * Constructs a <code>String</code> with all attributes in name = value 169 * format. 170 * 171 * @return a <code>String</code> representation of this object. 172 */ 173 public String toString() { 174 final String result = "JPAProperty ( " + "id = " + this.id + " " + "localName = " + this.localName + " " 175 + "namespace = " + this.namespace + " " + "value = " + this.value + " )"; 176 177 return result; 178 } 179 180}