d
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.sl.house_property.db;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@DatabaseTable(tableName = "tab_comment")
|
||||
public class CommentBeanData extends DbBean implements Serializable {
|
||||
@DatabaseField(id = true,columnName = "Id")
|
||||
private String id;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
@DatabaseField(columnName = "comment")
|
||||
private String comment;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@DatabaseField(columnName = "type")
|
||||
private String type;//1.评论话术 2.私信话术 3.直播话术 4.回访话术 5.首关话术
|
||||
}
|
||||
4
app/src/main/java/com/sl/house_property/db/DbBean.java
Normal file
4
app/src/main/java/com/sl/house_property/db/DbBean.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.sl.house_property.db;
|
||||
|
||||
public class DbBean {
|
||||
}
|
||||
120
app/src/main/java/com/sl/house_property/db/dao/CommentDao.java
Normal file
120
app/src/main/java/com/sl/house_property/db/dao/CommentDao.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package com.sl.house_property.db.dao;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.SQLException;
|
||||
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.sl.house_property.db.CommentBeanData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommentDao {
|
||||
private static Dao<CommentBeanData, Integer> userAccountDao;
|
||||
|
||||
public CommentDao(Context mContext) {
|
||||
DataBaseHelper dataBaseHelper = DataBaseHelper.getInstance(mContext);
|
||||
try {
|
||||
try {
|
||||
userAccountDao = dataBaseHelper.getDao(CommentBeanData.class);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public long addInsert(CommentBeanData userData) {
|
||||
int id = 0;
|
||||
try {
|
||||
try {
|
||||
id = userAccountDao.create(userData);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public List<CommentBeanData> queryByCustom(String columnName, String columnValue) {
|
||||
List<CommentBeanData> ormTables = new ArrayList<>();
|
||||
try {
|
||||
ormTables = userAccountDao.queryBuilder().where().eq(columnName, columnValue).query();
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return ormTables;
|
||||
}
|
||||
|
||||
public List<CommentBeanData> queryByCustomtwo(String columnName, String columnValue) {
|
||||
List<CommentBeanData> ormTables = new ArrayList<>();
|
||||
try {
|
||||
// ormTables = userAccountDao.queryBuilder().where().eq(columnName, columnValue).query();
|
||||
ormTables= userAccountDao.queryBuilder().where().like("phone", "%"+columnValue+"%").or().like("name","%"+columnValue+"%").query();
|
||||
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return ormTables;
|
||||
}
|
||||
|
||||
public boolean updateData(CommentBeanData userData) {
|
||||
|
||||
try {
|
||||
int result = userAccountDao.update(userData);
|
||||
if (result != -1) {
|
||||
return true;
|
||||
|
||||
}
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<CommentBeanData> queryInByCustom(String columnName, String columnValues){
|
||||
List<CommentBeanData> ormTables = new ArrayList<>();
|
||||
try {
|
||||
List<String> strings = Arrays.asList(columnValues.split(","));
|
||||
|
||||
ormTables = userAccountDao.queryBuilder().where().in(columnName,strings ).query();
|
||||
}catch (java.sql.SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ormTables;
|
||||
}
|
||||
|
||||
public ArrayList<CommentBeanData> queryAll() {
|
||||
ArrayList<CommentBeanData> userAccountList = new ArrayList<>();
|
||||
try {
|
||||
userAccountList = (ArrayList<CommentBeanData>) userAccountDao.queryForAll();
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return userAccountList;
|
||||
}
|
||||
|
||||
public long delete(List<CommentBeanData> DATA){
|
||||
int id = 0;
|
||||
try {
|
||||
try {
|
||||
id = userAccountDao.delete(DATA);
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.sl.house_property.db.dao;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import com.sl.house_property.db.CommentBeanData;
|
||||
|
||||
public class DataBaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private static final String TABLE_NAME = "sqlite-test.db";
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private static final int DBVERSION = 1;
|
||||
|
||||
private static Context mContext;
|
||||
/**
|
||||
* 单例
|
||||
*/
|
||||
private static DataBaseHelper mInstance;
|
||||
private static DataBaseHelper dataBaseHelper;
|
||||
|
||||
|
||||
private DataBaseHelper(Context context) {
|
||||
super(context, TABLE_NAME, null, DBVERSION);
|
||||
}
|
||||
|
||||
public synchronized static DataBaseHelper getInstance(Context mContext) {
|
||||
if (dataBaseHelper == null) {
|
||||
dataBaseHelper = new DataBaseHelper(mContext);
|
||||
}
|
||||
return dataBaseHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
public static void initOrmLite(Context context) {
|
||||
mContext = context;
|
||||
getIntence();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据库表
|
||||
*
|
||||
* @param database
|
||||
* @param connectionSource
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database,
|
||||
ConnectionSource connectionSource) {
|
||||
try {
|
||||
|
||||
TableUtils.createTable(connectionSource, CommentBeanData.class);
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (java.sql.SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级数据库
|
||||
*
|
||||
* @param database
|
||||
* @param connectionSource
|
||||
* @param oldVersion
|
||||
* @param newVersion
|
||||
*/
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database,
|
||||
ConnectionSource connectionSource, int oldVersion, int newVersion) {
|
||||
try {
|
||||
|
||||
|
||||
onCreate(database, connectionSource);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 单例获取该Helper
|
||||
*
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public static synchronized DataBaseHelper getIntence() {
|
||||
|
||||
if (null == mInstance) {
|
||||
synchronized (DataBaseHelper.class) {
|
||||
if (null == mInstance) {
|
||||
mInstance = new DataBaseHelper(mContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据对象
|
||||
*
|
||||
* @param classz 对应的表实体的字节码对象
|
||||
* @return Dao<T, ID> :T:表实体对象类型.ID:对应的表实体中被指定为id字段的属性类型
|
||||
* @throws SQLException
|
||||
*/
|
||||
@Override
|
||||
public Dao getDao(Class classz) throws SQLException, java.sql.SQLException {
|
||||
return super.getDao(classz);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user