Skip to content
Permalink
Browse files

Orm模块的API增强

  • Loading branch information
JackWHLiu committed May 30, 2019
1 parent 4605a67 commit 281cb1b50221270024eec28b456fcef9213c0f19
@@ -43,8 +43,8 @@ ext {
min_sdk : 11,
target_sdk : 26,
build_tools_version : "27.0.3",
release_version_code : 219,
release_version_name : "4.2.3"
release_version_code : 220,
release_version_name : "4.2.4"
]
}

@@ -23,7 +23,7 @@
*
* @return The primary key value.
*/
PrimaryKeyValue getPrimaryKeyValue();
PrimaryKeyEntity getPrimaryKey();

/**
* @return If true, it will drop table first and recreate the table when the table is
@@ -0,0 +1,25 @@
package com.lwh.jackknife.orm;

public class PrimaryKeyEntity {

private String name;
private String value;

public PrimaryKeyEntity(String primaryKeyName, Number primaryKeyValue) {
this.name = primaryKeyName;
this.value = String.valueOf(primaryKeyValue);
}

public PrimaryKeyEntity(String primaryKeyName, String primaryKeyValue) {
this.name = primaryKeyName;
this.value = primaryKeyValue;
}

public String getName() {
return name;
}

public String getValue() {
return value;
}
}

This file was deleted.

@@ -36,6 +36,8 @@

boolean delete(WhereBuilder builder);

boolean delete(T bean);

boolean deleteAll();

boolean deleteSafety(WhereBuilder builder, SQLiteDatabase db);
@@ -44,6 +46,8 @@

boolean update(WhereBuilder builder, T newBean);

boolean update(T bean);

boolean updateAll(T newBean);

boolean updateSafety(WhereBuilder builder, T newBean, SQLiteDatabase db);
@@ -20,8 +20,10 @@
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.lwh.jackknife.orm.Condition;
import com.lwh.jackknife.orm.Orm;
import com.lwh.jackknife.orm.OrmTable;
import com.lwh.jackknife.orm.PrimaryKeyEntity;
import com.lwh.jackknife.orm.TableManager;
import com.lwh.jackknife.orm.builder.QueryBuilder;
import com.lwh.jackknife.orm.builder.WhereBuilder;
@@ -186,6 +188,14 @@ public boolean delete(WhereBuilder builder) {
return deleteSafety(builder, mDatabase);
}

@Override
public boolean delete(T bean) {
PrimaryKeyEntity primaryKey = bean.getPrimaryKey();
String name = primaryKey.getName();
String value = primaryKey.getValue();
return deleteSafety(WhereBuilder.create(new Condition(name+"=?", new String[]{value})), mDatabase);
}

@Override
public boolean deleteAll() {
return deleteAllSafety(mDatabase);
@@ -210,6 +220,15 @@ public boolean update(WhereBuilder builder, final T newBean) {
return updateSafety(builder, newBean, mDatabase);
}

@Override
public boolean update(T bean) {
PrimaryKeyEntity primaryKey = bean.getPrimaryKey();
String name = primaryKey.getName();
String value = primaryKey.getValue();
return updateSafety(WhereBuilder.create(new Condition(name+"=?", new String[]{value})),
bean, mDatabase);
}

@Override
public boolean updateAll(T newBean) {
return updateAllSafety(newBean, mDatabase);

0 comments on commit 281cb1b

Please sign in to comment.
You can’t perform that action at this time.