If you think the Android project sqlite-provider listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package novoda.rest.database;
//www.java2s.compublicfinalclass SQLiteUtil {
privatestaticfinalshort DELETE = 0;
privatestaticfinalshort INSERT = 1;
privatestaticfinalshort UPDATE = 2;
private SQLiteUtil() {
// Util Class
}
publicstatic String[] getTriggers(final String parentTable, final String parentPKName,
final String childTable, final String parentFKName) {
returnnew String[] {
getUpdateTrigger(parentTable, parentPKName, childTable, parentFKName),
//getInsertTrigger(parentTable, parentPKName, childTable, parentFKName),
getDeleteTrigger(parentTable, parentPKName, childTable, parentFKName)
};
}
publicstatic String getUpdateTrigger(final String parentTable, final String parentPKName,
final String childTable, final String parentFKName) {
return SQLiteUtil.getTrigger(UPDATE, parentTable, parentPKName, childTable, parentFKName);
}
publicstatic String getInsertTrigger(final String parentTable, final String parentPKName,
final String childTable, final String parentFKName) {
return SQLiteUtil.getTrigger(INSERT, parentTable, parentPKName, childTable, parentFKName);
}
publicstatic String getDeleteTrigger(final String parentTable, final String parentPKName,
final String childTable, final String parentFKName) {
return SQLiteUtil.getTrigger(DELETE, parentTable, parentPKName, childTable, parentFKName);
}
privatestatic String getTrigger(finalshort type, final String parentTable,
final String parentPKName, final String childTable, final String parentFKName) {
StringBuffer buf = new StringBuffer();
String typeString = null;
buf.append("CREATE TRIGGER ");
switch (type) {
case DELETE:
typeString = "DELETE";
break;
case INSERT:
typeString = "INSERT";
break;
case UPDATE:
typeString = "UPDATE";
break;
default:
thrownew IllegalStateException("type must be valid");
}
buf.append(typeString.toLowerCase()).append("_").append(parentTable);
buf.append(" BEFORE ").append(typeString).append(" ON ").append(parentTable).append(
" FOR EACH ROW BEGIN ").append("DELETE").append(" from ").append(childTable)
.append(" WHERE ").append(parentFKName).append(" = OLD.").append(parentPKName)
.append("; END;");
return buf.toString();
}
}