Skip to content

Commit

Permalink
Refactor codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sinyu890807 committed May 28, 2014
1 parent 399b8ba commit c8735ca
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions library/src/org/litepal/crud/DataSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class DataSupport {
*
* @return A ClusterQuery instance.
*/
public static ClusterQuery select(String... columns) {
public static synchronized ClusterQuery select(String... columns) {
ClusterQuery cQuery = new ClusterQuery();
cQuery.mColumns = columns;
return cQuery;
Expand All @@ -121,7 +121,7 @@ public static ClusterQuery select(String... columns) {
* WHERE clause. Passing null will return all rows.
* @return A ClusterQuery instance.
*/
public static ClusterQuery where(String... conditions) {
public static synchronized ClusterQuery where(String... conditions) {
ClusterQuery cQuery = new ClusterQuery();
cQuery.mConditions = conditions;
return cQuery;
Expand All @@ -143,7 +143,7 @@ public static ClusterQuery where(String... conditions) {
* unordered.
* @return A ClusterQuery instance.
*/
public static ClusterQuery order(String column) {
public static synchronized ClusterQuery order(String column) {
ClusterQuery cQuery = new ClusterQuery();
cQuery.mOrderBy = column;
return cQuery;
Expand All @@ -163,7 +163,7 @@ public static ClusterQuery order(String column) {
* LIMIT clause.
* @return A ClusterQuery instance.
*/
public static ClusterQuery limit(int value) {
public static synchronized ClusterQuery limit(int value) {
ClusterQuery cQuery = new ClusterQuery();
cQuery.mLimit = String.valueOf(value);
return cQuery;
Expand All @@ -183,12 +183,21 @@ public static ClusterQuery limit(int value) {
* The offset amount of rows returned by the query.
* @return A ClusterQuery instance.
*/
public static ClusterQuery offset(int value) {
public static synchronized ClusterQuery offset(int value) {
ClusterQuery cQuery = new ClusterQuery();
cQuery.mOffset = String.valueOf(value);
return cQuery;
}

public static synchronized <T> int count(Class<T> modelClass) {
return count(BaseUtility.changeCase(modelClass.getSimpleName()));
}

public static synchronized <T> int count(String tableName) {
ClusterQuery cQuery = new ClusterQuery();
return cQuery.count(tableName);
}

/**
* Finds the record by a specific id.
*
Expand Down Expand Up @@ -430,8 +439,7 @@ public static synchronized int delete(Class<?> modelClass, long id) {
* @return The number of rows affected.
*/
public static synchronized int deleteAll(Class<?> modelClass, String... conditions) {
DeleteHandler deleteHandler = new DeleteHandler(Connector.getDatabase());
return deleteHandler.onDeleteAll(modelClass, conditions);
return deleteAll(BaseUtility.changeCase(modelClass.getSimpleName()), conditions);
}

/**
Expand Down Expand Up @@ -498,8 +506,7 @@ public static synchronized int update(Class<?> modelClass, ContentValues values,
*/
public static synchronized int updateAll(Class<?> modelClass, ContentValues values,
String... conditions) {
UpdateHandler updateHandler = new UpdateHandler(Connector.getDatabase());
return updateHandler.onUpdateAll(modelClass, values, conditions);
return updateAll(BaseUtility.changeCase(modelClass.getSimpleName()), values, conditions);
}

/**
Expand Down

0 comments on commit c8735ca

Please sign in to comment.