郭大神的 litepal 不敢恭维,占用 id 问题 ~~~
myApplication
package com.baoy.demo.demolitepal;
import org.litepal.LitePalApplication;
import android.content.Context;
//com.baoy.demo.demolitepal.MyApplication
public class MyApplication extends LitePalApplication {
private static Context mContext;
@Override
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
}
public static Context getmContext() {
return mContext;
}
public static void setmContext( Context mContext ) {
MyApplication.mContext = mContext;
}
}
package com.baoy.demo.demolitepal.entity;
import java.io.Serializable;
import java.util.Date;
import android.database.Cursor;
//com.baoy.demo.demolitepal.entity.UserEntity
public class UserEntity extends BaseDBEntity implements Serializable{
private long id;
private long sid;
private RelatsionEntity relatsionEntity;
private String nikeName;
private String realName;
private String password;
private String phone;
private String mail;
private Date lastUpdateTime;
private Date insertTime;
private String photo;
@Override
public long getId() {
return this.id ;
}
public UserEntity(){}
public UserEntity(long id ,long sid, String nikeName, String realName,
String password, String phone, String mail, Date lastUpdateTime,
Date insertTime, String photo) {
this.id = id;
this.sid = sid;
this.nikeName = nikeName;
this.realName = realName;
this.password = password;
this.phone = phone;
this.mail = mail;
this.lastUpdateTime = lastUpdateTime;
this.insertTime = insertTime;
this.photo = photo;
}
public UserEntity(long id, RelatsionEntity relatsionEntity,
String nikeName, String realName, String password, String phone,
String mail, Date lastUpdateTime, Date insertTime, String photo) {
this.id = id;
this.relatsionEntity = relatsionEntity;
this.nikeName = nikeName;
this.realName = realName;
this.password = password;
this.phone = phone;
this.mail = mail;
this.lastUpdateTime = lastUpdateTime;
this.insertTime = insertTime;
this.photo = photo;
}
@Override
public String toString() {
return "UserEntity [id=" + id + ",sid=" + sid + ", relatsionEntity=" + relatsionEntity
+ ", nikeName=" + nikeName + ", realName=" + realName
+ ", password=" + password + ", phone=" + phone + ", mail="
+ mail + ", lastUpdateTime=" + lastUpdateTime + ", insertTime="
+ insertTime + ", photo=" + photo + "]";
}
public RelatsionEntity getRelatsionEntity() {
return relatsionEntity;
}
public void setRelatsionEntity(RelatsionEntity relatsionEntity) {
this.relatsionEntity = relatsionEntity;
}
public String getNikeName() {
return nikeName;
}
public void setNikeName(String nikeName) {
this.nikeName = nikeName;
}
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public Date getLastUpdateTime() {
return lastUpdateTime;
}
public void setLastUpdateTime(Date lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
}
public Date getInsertTime() {
return insertTime;
}
public void setInsertTime(Date insertTime) {
this.insertTime = insertTime;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public void setId(long id) {
this.id = id;
}
public long getSid() {
return sid;
}
public void setSid(long sid) {
this.sid = sid;
}
}
package com.baoy.demo.demolitepal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import com.baoy.demo.demolitepal.entity.RelatsionEntity;
import com.baoy.demo.demolitepal.entity.UserEntity;
//https://github.com/LitePalFramework/LitePal
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
/*static UserEntity user1 =new UserEntity(1,1 ,"a","a","a","15011112222","a@163.com",new Date(),new Date(),"");
static UserEntity user2 =new UserEntity(2,2 ,"b","b","b","15011112223","b@163.com",new Date(),new Date(),"");
static UserEntity user3 =new UserEntity(3,3 ,"c","c","c","15011112224","c@163.com",new Date(),new Date(),"");
static RelatsionEntity re1 = new RelatsionEntity(1,"朋友",new ArrayList<UserEntity>(){{add(user1);add(user2);}});
static RelatsionEntity re2 = new RelatsionEntity(2,"同事",new ArrayList<UserEntity>(){{add(user3);}});*/
private void init() {
UserEntity user1 =new UserEntity(1,1 ,"a","a","a","15011112222","a@163.com",new Date(),new Date(),"");
UserEntity user2 =new UserEntity(2,2 ,"b","b","b","15011112223","b@163.com",new Date(),new Date(),"");
UserEntity user3 =new UserEntity(3,3 ,"c","c","c","15011112224","c@163.com",new Date(),new Date(),"");
user1.save();
user2.save();
user3.save();
/*re1.save();
re2.save();
RelatsionEntity re1 = RelatsionEntity.find(RelatsionEntity.class, 1,true);
System.out.println("RelatsionEntity : ==== " +re1.toString());
System.out.println("UserEntity list ==== " + re1.getUserListFromDB(re1.getId()));
UserEntity ue1 = UserEntity.find(UserEntity.class, 1,true);
System.out.println("UserEntity : ==== " + ue1.toString());*/
UserEntity ue1 = UserEntity.findFirst(UserEntity.class);
Log.e("baoyou","UserEntity 1: ==== " + ue1.toString());
int deleteAll2 = UserEntity.deleteAll(UserEntity.class, "id>?", "1");
boolean save2 = user1.save();
UserEntity ue2 = UserEntity.findFirst(UserEntity.class);
Log.e("baoyou","UserEntity 2: ==== "+deleteAll2+"---"+save2 +"--" + ue2 );
int deleteAll3 = UserEntity.deleteAll(UserEntity.class, "id>?", "1");
boolean save3 = user1.save();
UserEntity ue3 = UserEntity.findFirst(UserEntity.class);
Log.e("baoyou","UserEntity 3: ==== "+deleteAll3+"---"+save3 +"--" + ue3);
}
}
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!