Closed yuxingfafu closed 6 years ago
~ package com.jinrisheng.yinyuehui.model;
import android.os.Parcel; import android.os.Parcelable;
import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Id; import org.greenrobot.greendao.annotation.Property; import org.greenrobot.greendao.annotation.Unique; import org.greenrobot.greendao.annotation.Generated;
/**
Created by wcy on 2015/11/27. */ @Entity public class Music implements Parcelable {
@Property @Unique private String musicId; @Id(autoincrement=true) private Long id; @Property private String title; // 音乐标题 @Property private String artist; // 艺术家 @Property private String album; // 专辑 @Property private long duration; // 持续时间 @Property private String path; // 音乐路径 @Property private String coverPath; // 专辑封面路径 @Property private String fileName; // 文件名 @Property private long fileSize; // 文件大小 @Property private Integer isCollect ;// 是否收藏 1是0否 private boolean isClick; @Property private int musicType;//1 音乐 2 节目 @Property private String lrcPath; @Property private String time; @Property private int isVip;
public String getMusicId() { return musicId; }
public void setMusicId(String musicId) { this.musicId = musicId; }
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public String getArtist() { return artist; }
public void setArtist(String artist) { this.artist = artist; }
public String getAlbum() { return album; }
public void setAlbum(String album) { this.album = album; }
public long getDuration() { return duration; }
public void setDuration(long duration) { this.duration = duration; }
public String getPath() { return path; }
public void setPath(String path) { this.path = path; }
public String getCoverPath() { return coverPath; }
public void setCoverPath(String coverPath) { this.coverPath = coverPath; }
public String getFileName() { return fileName; }
public void setFileName(String fileName) { this.fileName = fileName; }
public long getFileSize() { return fileSize; }
public void setFileSize(long fileSize) { this.fileSize = fileSize; }
public Integer getIsCollect() { return isCollect; }
public void setIsCollect(Integer isCollect) { this.isCollect = isCollect; }
public boolean isClick() { return isClick; }
public void setClick(boolean click) { isClick = click; }
public int getMusicType() { return musicType; }
public void setMusicType(int musicType) { this.musicType = musicType; }
public String getLrcPath() { return lrcPath; }
public void setLrcPath(String lrcPath) { this.lrcPath = lrcPath; }
public String getTime() { return time; }
public void setTime(String time) { this.time = time; }
public int getIsVip() { return isVip; }
public void setIsVip(int isVip) { this.isVip = isVip; }
@Override public int describeContents() { return 0; }
@Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.musicId); dest.writeValue(this.id); dest.writeString(this.title); dest.writeString(this.artist); dest.writeString(this.album); dest.writeLong(this.duration); dest.writeString(this.path); dest.writeString(this.coverPath); dest.writeString(this.fileName); dest.writeLong(this.fileSize); dest.writeValue(this.isCollect); dest.writeByte(this.isClick ? (byte) 1 : (byte) 0); dest.writeInt(this.musicType); dest.writeString(this.lrcPath); dest.writeString(this.time); dest.writeInt(this.isVip); }
public boolean getIsClick() { return this.isClick; }
public void setIsClick(boolean isClick) { this.isClick = isClick; }
public Music() { }
protected Music(Parcel in) { this.musicId = in.readString(); this.id = (Long) in.readValue(Long.class.getClassLoader()); this.title = in.readString(); this.artist = in.readString(); this.album = in.readString(); this.duration = in.readLong(); this.path = in.readString(); this.coverPath = in.readString(); this.fileName = in.readString(); this.fileSize = in.readLong(); this.isCollect = (Integer) in.readValue(Integer.class.getClassLoader()); this.isClick = in.readByte() != 0; this.musicType = in.readInt(); this.lrcPath = in.readString(); this.time = in.readString(); this.isVip = in.readInt(); }
@Generated(hash = 141852340) public Music(String musicId, Long id, String title, String artist, String album, long duration, String path, String coverPath, String fileName, long fileSize, Integer isCollect, boolean isClick, int musicType, String lrcPath, String time, int isVip) { this.musicId = musicId; this.id = id; this.title = title; this.artist = artist; this.album = album; this.duration = duration; this.path = path; this.coverPath = coverPath; this.fileName = fileName; this.fileSize = fileSize; this.isCollect = isCollect; this.isClick = isClick; this.musicType = musicType; this.lrcPath = lrcPath; this.time = time; this.isVip = isVip; }
public static final Creator
@Override
public Music[] newArray(int size) {
return new Music[size];
}
}; }
添加了唯一键约束@unique导致的,把@unique去掉试试。
@yuweiguocn id如果设置成主键就是不能重复的。 把INSERT INTRO换成INSERT OR REPLACE INTO可以处理重复的问题。 @yuxingfafu
@atearsan 好的,感谢。
07-12 15:44:32.985 2846-2846/com.jinrisheng.yinyuehui E/MigrationHelper: 【Failed to restore data from temp table 】MUSIC_TEMP android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: MUSIC._id (code 1555) at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method) at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:732) at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754) at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64) at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1676) at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605) at org.greenrobot.a.d.f.a(StandardDatabase.java:37) at com.jinrisheng.yinyuehui.util.b.b.c(MigrationHelper.java:180)