/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.seam.wiki.core.preferences;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.jboss.seam.wiki.core.model.User;
import org.jboss.seam.wiki.preferences.PreferenceValue;
import org.jboss.seam.wiki.preferences.metamodel.PreferenceEntity;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.text.SimpleDateFormat;
@TypeDefs({
@TypeDef(name="preference_value_usertype", typeClass = PreferenceValueUserType.class)
})
@Entity
@Table(name = "PREFERENCE")
/*
TODO: This implementation of Comparable MIGHT not be consistent with equals()!
*/
public class WikiPreferenceValue implements PreferenceValue, Serializable, Comparable {
@Id
@GeneratedValue(generator = "wikiSequenceGenerator")
@Column(name = "PREF_ID")
private Long id;
@Version
@Column(name = "OBJ_VERSION", nullable = false)
private int version = 0;
@Column(name = "ENTITY_NAME", nullable = false)
private String entityName;
@Column(name = "PROPERTY_NAME", nullable = false)
private String propertyName;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "USER_ID", nullable = true, updatable = false)
@org.hibernate.annotations.ForeignKey(name = "FK_PREFERENCE_USER_ID")
private User user;
@org.hibernate.annotations.Type(type = "preference_value_usertype")
@org.hibernate.annotations.Columns(
columns = {
@Column( name="LONG_VALUE"),
@Column( name="DOUBLE_VALUE"),
@Column( name="TIMESTAMP_VALUE"),
@Column( name="BOOLEAN_VALUE"),
@Column( name="STRING_VALUE", length = 1023)
}
)
private Object value;
@Transient
private boolean instance = false;
public WikiPreferenceValue() {}
public WikiPreferenceValue(PreferenceEntity.Property property) {
this.entityName = property.getOwningEntityName();
this.propertyName = property.getFieldName();
this.property = property;
}
public WikiPreferenceValue(PreferenceEntity.Property property, String value) {
this.entityName = property.getOwningEntityName();
this.propertyName = property.getFieldName();
this.property = property;
this.instance = true;
if (property.getFieldType().equals(String.class)) {
this.value = value;
} else if (property.getFieldType().equals(Long.class)) {
try {
this.value = Long.valueOf(value);
} catch (Exception ex) {}
} else if (property.getFieldType().equals(Double.class)) {
try {
this.value = Double.valueOf(value);
} catch (Exception ex) {}
} else if (property.getFieldType().equals(Date.class)) {
try {
this.value = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value);
} catch (Exception ex) {}
} else if (property. getFieldType().equals(Boolean.class)) {
try {
this.value = Boolean.valueOf(value);
} catch (Exception ex) {}
}
}
public Long getId() {
return id;
}
public int getVersion() {
return version;
}
public String getEntityName() {
return entityName;
}
public void setEntityName(String entityName) {
this.entityName = entityName;
}
public String getPropertyName() {
return propertyName;
}
public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
if (this.value == null && value != null)
setDirty(true);
else if (this.value != null && value == null)
setDirty(true);
else if (this.value != null && !(this.value.equals(value)))
setDirty(true);
this.value = value;
}
public boolean isSystem() {
return user == null && !instance;
}
public boolean isUser() {
return user != null && !instance;
}
public boolean isInstance() {
return user == null && instance;
}
@Transient
private boolean dirty;
public boolean isDirty() { return dirty; }
public void setDirty(boolean dirty) { this.dirty = dirty; }
@Transient
PreferenceEntity.Property property;
public void setPreferenceProperty(PreferenceEntity.Property property) { this.property = property; }
public PreferenceEntity.Property getPreferenceProperty() { return property; }
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WikiPreferenceValue that = (WikiPreferenceValue) o;
if (!entityName.equals(that.entityName)) return false;
if (!propertyName.equals(that.propertyName)) return false;
return true;
}
public int hashCode() {
int result;
result = entityName.hashCode();
result = 31 * result + propertyName.hashCode();
return result;
}
public int compareTo(Object o) {
return getPreferenceProperty().compareTo(((PreferenceValue)o).getPreferenceProperty());
}
public String toString() {
return "WikiPreferenceValue for '" + getEntityName() + "." + getPropertyName() + "'";
}
}
分享到:
相关推荐
preferences-helper SharePreferences is very popular with any project and all most all project has SharePreferences for saving data. This library will help you faster in configuration and use ...
compile 'com.github.seanzor:shared-preferences-helper:1.1.0' } Usage Define the preferences keys in a resource file: pref_number_of_runs And use them: // As in most cases, create a default shared ...
python库。 资源全名:django-dynamic-preferences-1.2.tar.gz
python库。 资源全名:Preferences-0.08.tar.gz
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
AndroidMaterialPreferences.zip,提供各种“材料设计”样式的首选项。提供各种“材料设计”样式的首选项
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
logback-redis-appender.zip,主要用于将logback日志传递到logstash through
Windows-->preferences-->java-->Insetallel JREs 右侧 单击ADD standard VM-->Next -->Directory-->Finash 点选 新增jre环境-->点击OK 2. 更换背景颜色 个人感觉白色比较刺激眼睛 可选择性更换 Windows-->...
下载NDK组件com.android.ide.eclipse.ndk_23.0.2.1259578.jar。将文件“com.android.ide.eclipse.ndk_23.0.2.1259578.jar”复制到sdk自带的eclipse/plugins目录下
1、window---preferences---Java---Editor---Contenet Assist 接着在右下角“Auto activation triggers for Java:”这句话右边文本框值改成 ".abc",点击“OK” 2、File---Export---General---preferences “To ...
下载repositories { maven { url " https://jitpack.io " }}dependencies { implementation ' com.github.tfcporciuncula.flow-preferences:flow-preferences:1.4.0 '}看起来如何从常规的SharedPreferences开始: ...