当前位置: 首页>>代码示例>>Java>>正文


Java BaseUtility类代码示例

本文整理汇总了Java中org.litepal.util.BaseUtility的典型用法代码示例。如果您正苦于以下问题:Java BaseUtility类的具体用法?Java BaseUtility怎么用?Java BaseUtility使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BaseUtility类属于org.litepal.util包,在下文中一共展示了BaseUtility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onDeleteAll

import org.litepal.util.BaseUtility; //导入依赖的package包/类
@SuppressWarnings("unchecked")
int onDeleteAll(Class<?> modelClass, String... conditions) {
	BaseUtility.checkConditionsCorrect(conditions);
       if (conditions != null && conditions.length > 0) {
           conditions[0] = DBUtility.convertWhereClauseToColumnName(conditions[0]);
       }
       List<Field> supportedGenericFields = getSupportedGenericFields(modelClass.getName());
       if (!supportedGenericFields.isEmpty()) {
           List<DataSupport> list = (List<DataSupport>) DataSupport.select("id").where(conditions).find(modelClass);
           if (list.size() > 0) {
               long[] ids = new long[list.size()];
               for (int i = 0; i < ids.length; i++) {
                   DataSupport dataSupport = list.get(i);
                   ids[i] = dataSupport.getBaseObjId();
               }
               deleteGenericData(modelClass, supportedGenericFields, ids);
           }
       }
	analyzeAssociations(modelClass);
	int rowsAffected = deleteAllCascade(modelClass, conditions);
	rowsAffected += mDatabase.delete(getTableName(modelClass), getWhereClause(conditions),
			getWhereArgs(conditions));
	getForeignKeyTableToDelete().clear();
	return rowsAffected;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:DeleteHandler.java

示例2: analyzeAssociations

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Analyze the associations of modelClass and store the associated tables.
 * The associated tables might be used when deleting referenced data of a
 * specified row.
 * 
 * @param modelClass
 *            To get associations of this class.
 */
private void analyzeAssociations(Class<?> modelClass) {
	Collection<AssociationsInfo> associationInfos = getAssociationInfo(modelClass
			.getName());
	for (AssociationsInfo associationInfo : associationInfos) {
		String associatedTableName = DBUtility
				.getTableNameByClassName(associationInfo
						.getAssociatedClassName());
		if (associationInfo.getAssociationType() == Const.Model.MANY_TO_ONE
				|| associationInfo.getAssociationType() == Const.Model.ONE_TO_ONE) {
			String classHoldsForeignKey = associationInfo
					.getClassHoldsForeignKey();
			if (!modelClass.getName().equals(classHoldsForeignKey)) {
				getForeignKeyTableToDelete().add(associatedTableName);
			}
		} else if (associationInfo.getAssociationType() == Const.Model.MANY_TO_MANY) {
			String joinTableName = DBUtility.getIntermediateTableName(
					getTableName(modelClass), associatedTableName);
			joinTableName = BaseUtility.changeCase(joinTableName);
			getForeignKeyTableToDelete().add(joinTableName);
		}
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:DeleteHandler.java

示例3: deleteAllCascade

import org.litepal.util.BaseUtility; //导入依赖的package包/类
private int deleteAllCascade(Class<?> modelClass, String... conditions) {
	int rowsAffected = 0;
	for (String associatedTableName : getForeignKeyTableToDelete()) {
		String tableName = getTableName(modelClass);
		String fkName = getForeignKeyColumnName(tableName);
		StringBuilder whereClause = new StringBuilder();
		whereClause.append(fkName).append(" in (select id from ");
		whereClause.append(tableName);
		if (conditions != null && conditions.length > 0) {
			whereClause.append(" where ").append(buildConditionString(conditions));
		}
		whereClause.append(")");
		rowsAffected += mDatabase.delete(associatedTableName,
				BaseUtility.changeCase(whereClause.toString()), null);
	}
	return rowsAffected;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:DeleteHandler.java

示例4: makeGetterMethodName

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Generate the getter method name by field, following the Android Studio rule.
 * 
 * @param field
 *            The field to generate getter method from.
 * @return The generated getter method name.
 */
private String makeGetterMethodName(Field field) {
	String getterMethodPrefix;
	String fieldName = field.getName();
	if (isPrimitiveBooleanType(field)) {
		if (fieldName.matches("^is[A-Z]{1}.*$")) {
			fieldName = fieldName.substring(2);
		}
		getterMethodPrefix = "is";
	} else {
		getterMethodPrefix = "get";
	}
	if (fieldName.matches("^[a-z]{1}[A-Z]{1}.*")) {
		return getterMethodPrefix + fieldName;
	} else {
		return getterMethodPrefix + BaseUtility.capitalize(fieldName);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:DataHandler.java

示例5: genGetColumnMethod

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Generates the getType method for cursor based on field. There're couple of
 * unusual conditions. If field type is boolean, generate getInt method. If
 * field type is char, generate getString method. If field type is Date, generate
    * getLong method. If filed type is Integer, generate getInt method. If field type
    * is bytes, generate getBlob method.
 * 
 * @param fieldType
 *            To generate getType method for cursor.
 * @return The getType method for cursor.
 */
private String genGetColumnMethod(Class<?> fieldType) {
	String typeName;
	if (fieldType.isPrimitive()) {
		typeName = BaseUtility.capitalize(fieldType.getName());
       } else {
           typeName = fieldType.getSimpleName();
       }
	String methodName = "get" + typeName;
	if ("getBoolean".equals(methodName)) {
		methodName = "getInt";
	} else if ("getChar".equals(methodName) || "getCharacter".equals(methodName)) {
		methodName = "getString";
	} else if ("getDate".equals(methodName)) {
		methodName = "getLong";
	} else if ("getInteger".equals(methodName)) {
		methodName = "getInt";
	} else if ("getbyte[]".equalsIgnoreCase(methodName)) {
           methodName = "getBlob";
       }
	return methodName;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:DataHandler.java

示例6: findBySQL

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Runs the provided SQL and returns a Cursor over the result set. You may
 * include ? in where clause in the query, which will be replaced by the
 * second to the last parameters, such as:
 * 
 * <pre>
 * Cursor cursor = DataSupport.findBySQL(&quot;select * from person where name=? and age=?&quot;, &quot;Tom&quot;, &quot;14&quot;);
 * </pre>
 * 
 * @param sql
 *            First parameter is the SQL clause to apply. Second to the last
 *            parameters will replace the place holders.
 * @return A Cursor object, which is positioned before the first entry. Note
 *         that Cursors are not synchronized, see the documentation for more
 *         details.
 */
public static synchronized Cursor findBySQL(String... sql) {
	BaseUtility.checkConditionsCorrect(sql);
	if (sql == null) {
		return null;
	}
	if (sql.length <= 0) {
		return null;
	}
	String[] selectionArgs;
	if (sql.length == 1) {
		selectionArgs = null;
	} else {
		selectionArgs = new String[sql.length - 1];
		System.arraycopy(sql, 1, selectionArgs, 0, sql.length - 1);
	}
	return Connector.getDatabase().rawQuery(sql[0], selectionArgs);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:DataSupport.java

示例7: giveTableSchemaACopy

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Once there's new table created. The table name will be saved into
 * table_schema as a copy. Each table name will be saved only once.
 * 
 * @param tableName
 *            The table name.
 * @param tableType
 *            0 means normal table, 1 means intermediate join table.
 * @param db
 *            Instance of SQLiteDatabase.
 */
protected void giveTableSchemaACopy(String tableName, int tableType, SQLiteDatabase db) {
	StringBuilder sql = new StringBuilder("select * from ");
	sql.append(Const.TableSchema.TABLE_NAME);
	LogUtil.d(TAG, "giveTableSchemaACopy SQL is >> " + sql);
	Cursor cursor = null;
	try {
		cursor = db.rawQuery(sql.toString(), null);
		if (isNeedtoGiveACopy(cursor, tableName)) {
			ContentValues values = new ContentValues();
			values.put(Const.TableSchema.COLUMN_NAME, BaseUtility.changeCase(tableName));
			values.put(Const.TableSchema.COLUMN_TYPE, tableType);
			db.insert(Const.TableSchema.TABLE_NAME, null, values);
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		if (cursor != null) {
			cursor.close();
		}
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:AssociationCreator.java

示例8: buildConnection

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Build a connection to the database. This progress will analysis the
 * litepal.xml file, and will check if the fields in LitePalAttr are valid,
 * and it will open a SQLiteOpenHelper to decide to create tables or update
 * tables or doing nothing depends on the version attributes.
 * 
 * After all the stuffs above are finished. This method will return a
 * LitePalHelper object.Notes this method could throw a lot of exceptions.
 * 
 * @return LitePalHelper object.
 * 
 * @throws org.litepal.exceptions.InvalidAttributesException
 */
private static LitePalOpenHelper buildConnection() {
	LitePalAttr litePalAttr = LitePalAttr.getInstance();
	litePalAttr.checkSelfValid();
	if (mLitePalHelper == null) {
		String dbName = litePalAttr.getDbName();
		if ("external".equalsIgnoreCase(litePalAttr.getStorage())) {
			dbName = LitePalApplication.getContext().getExternalFilesDir("") + "/databases/" + dbName;
		} else if (!"internal".equalsIgnoreCase(litePalAttr.getStorage()) && !TextUtils.isEmpty(litePalAttr.getStorage())) {
               // internal or empty means internal storage, neither or them means sdcard storage
               String dbPath = Environment.getExternalStorageDirectory().getPath() + "/" + litePalAttr.getStorage();
               dbPath = dbPath.replace("//", "/");
               if (BaseUtility.isClassAndMethodExist("android.support.v4.content.ContextCompat", "checkSelfPermission") &&
                       ContextCompat.checkSelfPermission(LitePalApplication.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                   throw new DatabaseGenerateException(String.format(DatabaseGenerateException.EXTERNAL_STORAGE_PERMISSION_DENIED, dbPath));
               }
               File path = new File(dbPath);
               if (!path.exists()) {
                   path.mkdirs();
               }
               dbName = dbPath + "/" + dbName;
           }
		mLitePalHelper = new LitePalOpenHelper(dbName, litePalAttr.getVersion());
	}
	return mLitePalHelper;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:Connector.java

示例9: execute

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Use the parameter SQLiteDatabase to execute the passing SQLs. Subclasses
 * can add their own logic when do the executing job by overriding this
 * method.
 * 
 * @param sqls
 *            SQLs that want to execute.
 * @param db
 *            instance of SQLiteDatabase
 * 
 * @throws org.litepal.exceptions.DatabaseGenerateException
 */
protected void execute(List<String> sqls, SQLiteDatabase db) {
	String throwSQL = "";
	try {
		if (sqls != null && !sqls.isEmpty()) {
			for (String sql : sqls) {
                   if (!TextUtils.isEmpty(sql)) {
                       throwSQL = BaseUtility.changeCase(sql);
                       db.execSQL(throwSQL);
                   }
			}
		}
	} catch (SQLException e) {
		throw new DatabaseGenerateException(DatabaseGenerateException.SQL_ERROR + throwSQL);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:Generator.java

示例10: recursiveSupportedFields

import org.litepal.util.BaseUtility; //导入依赖的package包/类
private void recursiveSupportedFields(Class<?> clazz, List<Field> supportedFields) {
    if (clazz == DataSupport.class || clazz == Object.class) {
        return;
    }
    Field[] fields = clazz.getDeclaredFields();
    if (fields != null && fields.length > 0) {
        for (Field field : fields) {
            Column annotation = field.getAnnotation(Column.class);
            if (annotation != null && annotation.ignore()) {
                continue;
            }
            int modifiers = field.getModifiers();
            if (!Modifier.isStatic(modifiers)) {
                Class<?> fieldTypeClass = field.getType();
                String fieldType = fieldTypeClass.getName();
                if (BaseUtility.isFieldTypeSupported(fieldType)) {
                    supportedFields.add(field);
                }
            }
        }
    }
    recursiveSupportedFields(clazz.getSuperclass(), supportedFields);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:LitePalBase.java

示例11: recursiveSupportedGenericFields

import org.litepal.util.BaseUtility; //导入依赖的package包/类
private void recursiveSupportedGenericFields(Class<?> clazz, List<Field> supportedGenericFields) {
    if (clazz == DataSupport.class || clazz == Object.class) {
        return;
    }
    Field[] fields = clazz.getDeclaredFields();
    if (fields != null && fields.length > 0) {
        for (Field field : fields) {
            Column annotation = field.getAnnotation(Column.class);
            if (annotation != null && annotation.ignore()) {
                continue;
            }
            int modifiers = field.getModifiers();
            if (!Modifier.isStatic(modifiers) && isCollection(field.getType())) {
                String genericTypeName = getGenericTypeName(field);
                if (BaseUtility.isGenericTypeSupported(genericTypeName)) {
                    supportedGenericFields.add(field);
                }
            }
        }
    }
    recursiveSupportedGenericFields(clazz.getSuperclass(), supportedGenericFields);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:LitePalBase.java

示例12: analyzeModelStructure

import org.litepal.util.BaseUtility; //导入依赖的package包/类
private void analyzeModelStructure() {
	Class<?> dynamicClass = null;
	try {
		dynamicClass = Class.forName(mClassName);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	Field[] fields = dynamicClass.getDeclaredFields();
	for (Field field : fields) {
		int modifiers = field.getModifiers();
		if (Modifier.isPrivate(modifiers) && !Modifier.isStatic(modifiers)) {
			Class<?> fieldTypeClass = field.getType();
			String fieldType = fieldTypeClass.getName();
			if (BaseUtility.isFieldTypeSupported(fieldType)) {
				mList.add(field);
			}
		}
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:ModelStructureActivity.java

示例13: isFKInsertCorrect

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * 
 * @param table1
 *            Table without foreign key.
 * @param table2
 *            Table with foreign key.
 * @param table1Id
 *            id of table1.
 * @param table2Id
 *            id of table2.
 * @return success or failed.
 */
protected boolean isFKInsertCorrect(String table1, String table2, long table1Id, long table2Id) {
	SQLiteDatabase db = Connector.getDatabase();
	Cursor cursor = null;
	try {
		cursor = db.query(table2, null, "id = ?", new String[] { String.valueOf(table2Id) },
				null, null, null);
		cursor.moveToFirst();
		long fkId = cursor.getLong(cursor.getColumnIndexOrThrow(BaseUtility.changeCase(table1
				+ "_id")));
		return fkId == table1Id;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	} finally {
		cursor.close();
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:LitePalTestCase.java

示例14: mathQuery

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Handles the math query of the given table.
 * 
 * @param tableName
 *            Which table to query from.
 * @param columns
 *            A list of which columns to return. Passing null will return
 *            all columns, which is discouraged to prevent reading data from
 *            storage that isn't going to be used.
 * @param conditions
 *            A filter declaring which rows to return, formatted as an SQL
 *            WHERE clause. Passing null will return all rows.
 * @param type
 *            The type of the based on column.
 * @return The result calculating by SQL.
 */
@SuppressWarnings("unchecked")
protected <T> T mathQuery(String tableName, String[] columns, String[] conditions, Class<T> type) {
	BaseUtility.checkConditionsCorrect(conditions);
	Cursor cursor = null;
	T result = null;
	try {
		cursor = mDatabase.query(tableName, columns, getWhereClause(conditions),
				getWhereArgs(conditions), null, null, null);
		if (cursor.moveToFirst()) {
			Class<?> cursorClass = cursor.getClass();
			Method method = cursorClass.getMethod(genGetColumnMethod(type), int.class);
			result = (T) method.invoke(cursor, 0);
		}
	} catch (Exception e) {
		throw new DataSupportException(e.getMessage());
	} finally {
		if (cursor != null) {
			cursor.close();
		}
	}
	return result;
}
 
开发者ID:ownwell,项目名称:zztinews,代码行数:39,代码来源:DataHandler.java

示例15: makeGetterMethodName

import org.litepal.util.BaseUtility; //导入依赖的package包/类
/**
 * Generate the getter method name by field, following the eclipse rule.
 * 
 * @param field
 *            The field to generate getter method from.
 * @return The generated getter method name.
 */
private String makeGetterMethodName(Field field) {
	String getterMethodPrefix;
	String fieldName = field.getName();
	if (isPrimitiveBooleanType(field)) {
		if (fieldName.matches("^is[A-Z]{1}.*$")) {
			fieldName = fieldName.substring(2);
		}
		getterMethodPrefix = "is";
	} else {
		getterMethodPrefix = "get";
	}
	if (fieldName.matches("^[a-z]{1}[A-Z]{1}.*")) {
		return getterMethodPrefix + fieldName;
	} else {
		return getterMethodPrefix + BaseUtility.capitalize(fieldName);
	}
}
 
开发者ID:ownwell,项目名称:zztinews,代码行数:25,代码来源:DataHandler.java


注:本文中的org.litepal.util.BaseUtility类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。