// 在使用该函数之前最好先判断数据库中movieList这个表是否为空 public List<UriInstance> queryFromUserID(int userID) { DatabaseHelper dbHelper = new DatabaseHelper(context, "CAMO_db1"); SQLiteDatabase db = dbHelper.getWritableDatabase(); Cursor cursor = db.query( "playList", new String[] {"userID", "uri", "classType", "name", "mediaType"}, "userID=?", new String[] {Integer.toString(userID)}, null, null, null); // UriInstance item = new UriInstance(); String uri = null; String classType = null; String name = null; String mediaType = null; List<UriInstance> list = new ArrayList<UriInstance>(); while (cursor.moveToNext()) { uri = cursor.getString(cursor.getColumnIndex("uri")); classType = cursor.getString(cursor.getColumnIndex("classType")); name = cursor.getString(cursor.getColumnIndex("name")); mediaType = cursor.getString(cursor.getColumnIndex("mediaType")); RdfFactory factory = RdfFactory.getInstance(); UriInstance item = factory.createInstance(uri, mediaType, classType, name); list.add(item); } dbHelper.close(); return list; }
public static List<UriInstance> viewFavoredArtist(User user, UriInstance mediaInst) { List<UriInstance> artists = new ArrayList<UriInstance>(); Object[] paramValues = {user.getId(), mediaInst.getUri()}; String naiveAritsts = WebService.getInstance() .runFunction(ServerParam.INTERESET_GP_URL, "getFavoredArtist", paramValues); if (naiveAritsts.equals(ServerParam.NETWORK_ERROR1)) return artists; if (naiveAritsts.length() == 0) return artists; List<String> naiveAritstList = SetSerialization.deserialize2(naiveAritsts); for (String naiveArtist : naiveAritstList) { List<String> naiveTermList = SetSerialization.deserialize1(naiveArtist); if (naiveTermList.size() == 3) { UriInstance inst = RdfFactory.getInstance() .createInstance( naiveTermList.get(0), mediaInst.getMediaType(), naiveTermList.get(2), SetSerialization.instNameNomalize(naiveTermList.get(1))); artists.add(inst); } } return artists; }