Skip to content

Commit

Permalink
For #85 - added 'Picture' entity with LOB, added fields to the 'Devic…
Browse files Browse the repository at this point in the history
…e' class
  • Loading branch information
vitalidze committed May 20, 2015
1 parent 7d36beb commit bd71bfa
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/main/java/org/traccar/web/shared/model/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,42 @@ public void setIconType(DeviceIconType iconType) {
this.iconType = iconType;
}

@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(name = "devices_fkey_def_icon_id"))
private Picture defaultIcon;

public Picture getDefaultIcon() {
return defaultIcon;
}

public void setDefaultIcon(Picture defaultIcon) {
this.defaultIcon = defaultIcon;
}

@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(name = "devices_fkey_sel_icon_id"))
private Picture selectedIcon;

public Picture getSelectedIcon() {
return selectedIcon;
}

public void setSelectedIcon(Picture selectedIcon) {
this.selectedIcon = selectedIcon;
}

@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(name = "devices_fkey_off_icon_id"))
private Picture offlineIcon;

public Picture getOfflineIcon() {
return offlineIcon;
}

public void setOfflineIcon(Picture offlineIcon) {
this.offlineIcon = offlineIcon;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public boolean equals(Object o) {

if (!getSettings().equals(that.getSettings())) return false;
return getType() == that.getType();

}

@Override
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/org/traccar/web/shared/model/Picture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2015 Vitaly Litvak ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.traccar.web.shared.model;

import com.google.gwt.user.client.rpc.GwtTransient;
import com.google.gwt.user.client.rpc.IsSerializable;

import javax.persistence.*;

@Entity
@Table(name = "pictures")
public class Picture implements IsSerializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false, unique = true)
private long id;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

@Enumerated(EnumType.STRING)
private PictureType type;

public PictureType getType() {
return type;
}

public void setType(PictureType type) {
this.type = type;
}

@Lob
@Basic(fetch = FetchType.LAZY)
@Column(length = 1024 * 1024) // max 1 MB
@GwtTransient
private byte[] data;

public byte[] getData() {
return data;
}

public void setData(byte[] data) {
this.data = data;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Picture)) return false;

Picture that = (Picture) o;
return that.getId() == getId();
}

@Override
public int hashCode() {
return (int)(getId() ^ (getId() >>> 32));
}
}
26 changes: 26 additions & 0 deletions src/main/java/org/traccar/web/shared/model/PictureType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2015 Vitaly Litvak ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.traccar.web.shared.model;

public enum PictureType {
MARKER(20 * 1024), DEVICE_PHOTO(300 * 1024);

final int maxLength;

PictureType(int maxLength) {
this.maxLength = maxLength;
}
}

0 comments on commit bd71bfa

Please sign in to comment.