001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.connector.store.jpa.model.basic; 025 026 import java.util.Collection; 027 import java.util.HashSet; 028 import javax.persistence.Column; 029 import javax.persistence.Entity; 030 import javax.persistence.FetchType; 031 import javax.persistence.Id; 032 import javax.persistence.JoinColumn; 033 import javax.persistence.JoinTable; 034 import javax.persistence.Lob; 035 import javax.persistence.NamedQueries; 036 import javax.persistence.NamedQuery; 037 import javax.persistence.Table; 038 import org.jboss.dna.connector.store.jpa.util.Serializer; 039 040 /** 041 * Represents the packed properties of a single node. Node that the object has the node's identifier and the packed properties, 042 * but nothing else. The PropertiesEntity doesn't even have the name. This is because this class is used to read, modify, and save 043 * the properties of a node. Finding a node by its name or working with the children, however, requires working with the 044 * {@link ChildEntity node children}. 045 * 046 * @author Randall Hauch 047 */ 048 @Entity 049 @Table( name = "DNA_BASIC_NODEPROPS" ) 050 @NamedQueries( { 051 @NamedQuery( name = "PropertiesEntity.findByUuid", query = "select prop from PropertiesEntity as prop where prop.id.workspaceId = :workspaceId and prop.id.uuidString = :uuid" ), 052 @NamedQuery( name = "PropertiesEntity.deleteByUuid", query = "delete PropertiesEntity prop where prop.id.workspaceId = :workspaceId and prop.id.uuidString = :uuid" ), 053 @NamedQuery( name = "PropertiesEntity.findInWorkspace", query = "select prop from PropertiesEntity as prop where prop.id.workspaceId = :workspaceId" ), 054 @NamedQuery( name = "PropertiesEntity.withLargeValues", query = "select prop from PropertiesEntity as prop where prop.id.workspaceId = :workspaceId and size(prop.largeValues) > 0" )} ) 055 public class PropertiesEntity { 056 @Id 057 private NodeId id; 058 059 @Lob 060 @Column( name = "DATA", nullable = true, unique = false ) 061 private byte[] data; 062 063 @Column( name = "NUM_PROPS", nullable = false ) 064 private int propertyCount; 065 066 /** 067 * Flag specifying whether the binary data is stored in a compressed format. 068 */ 069 @Column( name = "COMPRESSED", nullable = true ) 070 private Boolean compressed; 071 072 /** 073 * Flag specifying whether this node should be included in referential integrity enforcement. 074 */ 075 @Column( name = "ENFORCEREFINTEG", nullable = false ) 076 private boolean referentialIntegrityEnforced = true; 077 078 @org.hibernate.annotations.CollectionOfElements( fetch = FetchType.LAZY ) 079 @JoinTable( name = "DNA_LARGEVALUE_USAGES", joinColumns = {@JoinColumn( name = "WORKSPACE_ID" ), 080 @JoinColumn( name = "NODE_UUID" )} ) 081 private Collection<LargeValueId> largeValues = new HashSet<LargeValueId>(); 082 083 public PropertiesEntity() { 084 } 085 086 public PropertiesEntity( NodeId id ) { 087 setId(id); 088 } 089 090 /** 091 * Get the node's identifier. 092 * 093 * @return the node's identifier 094 */ 095 public NodeId getId() { 096 return id; 097 } 098 099 /** 100 * Set the node's identifier. 101 * 102 * @param id the new identifier for the node 103 */ 104 public void setId( NodeId id ) { 105 this.id = id; 106 } 107 108 /** 109 * Get the data that represents the {@link Serializer packed} properties. 110 * 111 * @return the raw data representing the properties 112 */ 113 public byte[] getData() { 114 return data; 115 } 116 117 /** 118 * Set the data that represents the {@link Serializer packed} properties. 119 * 120 * @param data the raw data representing the properties 121 */ 122 public void setData( byte[] data ) { 123 this.data = data; 124 } 125 126 /** 127 * @return propertyCount 128 */ 129 public int getPropertyCount() { 130 return propertyCount; 131 } 132 133 /** 134 * @param propertyCount Sets propertyCount to the specified value. 135 */ 136 public void setPropertyCount( int propertyCount ) { 137 this.propertyCount = propertyCount; 138 } 139 140 /** 141 * @return compressed 142 */ 143 public boolean isCompressed() { 144 return compressed != null && compressed.booleanValue(); 145 } 146 147 /** 148 * @param compressed Sets compressed to the specified value. 149 */ 150 public void setCompressed( boolean compressed ) { 151 this.compressed = Boolean.valueOf(compressed); 152 } 153 154 /** 155 * @return largeValues 156 */ 157 public Collection<LargeValueId> getLargeValues() { 158 return largeValues; 159 } 160 161 /** 162 * @return referentialIntegrityEnforced 163 */ 164 public boolean isReferentialIntegrityEnforced() { 165 return referentialIntegrityEnforced; 166 } 167 168 /** 169 * @param referentialIntegrityEnforced Sets referentialIntegrityEnforced to the specified value. 170 */ 171 public void setReferentialIntegrityEnforced( boolean referentialIntegrityEnforced ) { 172 this.referentialIntegrityEnforced = referentialIntegrityEnforced; 173 } 174 175 /** 176 * {@inheritDoc} 177 * 178 * @see java.lang.Object#hashCode() 179 */ 180 @Override 181 public int hashCode() { 182 return getId().hashCode(); 183 } 184 185 /** 186 * {@inheritDoc} 187 * 188 * @see java.lang.Object#equals(java.lang.Object) 189 */ 190 @Override 191 public boolean equals( Object obj ) { 192 if (obj == this) return true; 193 if (obj instanceof PropertiesEntity) { 194 PropertiesEntity that = (PropertiesEntity)obj; 195 if (this.getId().equals(that.getId())) return true; 196 } 197 return false; 198 } 199 200 /** 201 * {@inheritDoc} 202 * 203 * @see java.lang.Object#toString() 204 */ 205 @Override 206 public String toString() { 207 return "Properties for " + this.id; 208 } 209 }