本要点介绍了如何在预提交时使用Eclipse格式化程序自动格式化Java代码.
资料来源:https://gist.github.com/ktoso/708972
码:
#!/bin/sh
#
# This hook will run the eclipse code formatter before any commit
# to make the source look as it's supposed to look like in the repo.
ECLIPSE_HOME=$HOME/eclipse
STYLE_FILE=$HOME/org.eclipse.jdt.core.prefs
echo "Running pre-commit hook: run-eclipse-formatter---------------------"
echo "Will run eclipse formatter, using: $STYLE_FILE"
echo "Listing folders to run formatter on… "
code_dirs=`find . -maxdepth 3 | grep 'src/'`
for dir in $code_dirs; do
echo $dir;
done;
echo "Launching eclipse code formatter… "
exec $ECLIPSE_HOME/eclipse …Run Code Online (Sandbox Code Playgroud) 我正在使用这个DataBaseHelper.class,我被困在onUpgrade()方法上.我不知道如何弄清楚数据库的版本号是什么.我可以将版本设置为1,我第一次发布它,当我发布更新时,我只需将版本设置为2 (myDataBase.setVersion(2);).但只要应用程序正在运行,它就只有2.下一次它将被启动它再次是1.同样的事情发生了private static int DATABASE_VERSION.我正在考虑将版本号存储在一个额外的表中,但在我看来,这似乎不是最佳实践.
那么如何确保版本号在升级后增加并且保留它(分配给private static int DATABASE_VERSION或的值myDataBase.getVersion();)?
DataBaseHelper类:
public class DataBaseHelper extends SQLiteOpenHelper {
//The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.mydatabase.db/databases/";
private static String DB_NAME = "database.sl3";
private SQLiteDatabase myDataBase;
private final Context myContext;
// Do you need this?
private static int DATABASE_VERSION = 2;
// or is this correct:
// private static int DATABASE_VERSION = myDataBase.getVersion();
/**
* Constructor
* Takes and …Run Code Online (Sandbox Code Playgroud)