static int do_update_set(const symboldb_options &opt, database &db, char **argv) { database::package_set_id set = db.lookup_package_set(opt.set_name.c_str()); if (set == database::package_set_id()) { fprintf(stderr, "error: package set \"%s\" does not exist\n", opt.set_name.c_str()); return 1; } typedef std::vector<database::package_id> pset; pset ids; { package_set_consolidator<database::package_id> psc; if (!load_rpms(opt, db, argv, psc)) { return 1; } ids = psc.values(); } db.txn_begin(); { database::advisory_lock lock (db.lock(database::PACKAGE_SET_LOCK_TAG, set.value())); if (db.update_package_set(set, ids)) { finalize_package_set(opt, db, set); } } db.txn_commit(); return 0; }
static int do_create_set(const symboldb_options &opt, database &db, char **argv) { if (db.lookup_package_set(opt.set_name.c_str()) != database::package_set_id()) { fprintf(stderr, "error: package set \"%s\" already exists\n", opt.set_name.c_str()); return 1; } typedef std::vector<database::package_id> pset; pset ids; { package_set_consolidator<database::package_id> psc; if (!load_rpms(opt, db, argv, psc)) { return 1; } ids = psc.values(); } db.txn_begin(); database::package_set_id set = db.create_package_set(opt.set_name.c_str()); if (db.update_package_set(set, ids)) { finalize_package_set(opt, db, set); } db.txn_commit(); return 0; }
static void test_java_class(database &db, pgconn_handle &conn) { std::vector<unsigned char> buffer; read_file("test/data/JavaClass.class", buffer); java_class jc(&buffer); db.txn_begin_no_sync(); db.add_java_class(/* fake */ database::contents_id(1), jc); db.txn_commit(); pgresult_handle res; res.execBinary (conn, "SELECT class_id, name, super_class, access_flags" " FROM symboldb.java_class" " JOIN symboldb.java_class_contents USING (class_id)" " WHERE contents_id = 1"); CHECK(res.ntuples() == 1); int classid, access_flags; std::string name, super_class; pg_response(res, 0, classid, name, super_class, access_flags); COMPARE_STRING(name, "com/redhat/symboldb/test/JavaClass"); COMPARE_STRING(super_class, "java/lang/Thread"); CHECK(access_flags == 1 + 16 + 32); pg_query_binary (conn, res, "SELECT name FROM symboldb.java_interface" " WHERE class_id = $1 ORDER BY name", classid); CHECK(res.ntuples() == 2); COMPARE_STRING(res.getvalue(0, 0), "java/lang/AutoCloseable"); COMPARE_STRING(res.getvalue(1, 0), "java/lang/Runnable"); pg_query (conn, res, "SELECT name FROM symboldb.java_class_reference" " WHERE class_id = $1 ORDER BY name", classid); { const char *expected[] = { "java/lang/AutoCloseable", "java/lang/Byte", "java/lang/Double", "java/lang/Exception", "java/lang/Float", "java/lang/Integer", "java/lang/Long", "java/lang/Runnable", "java/lang/Short", "java/lang/StackOverflowError", "java/lang/StringBuilder", "java/lang/Thread", NULL }; unsigned end = res.ntuples(); for (unsigned i = 0; i <= end; ++i) { if (i == end) { CHECK(expected[i] == NULL); } else if (expected[i] == NULL) { CHECK(false); break; } else { COMPARE_STRING(res.getvalue(i, 0), expected[i]); } } } res.exec (conn, "SELECT jc.name FROM symboldb.java_class jc" " JOIN symboldb.java_class_contents USING (class_id)" " JOIN symboldb.file f USING (contents_id)" " JOIN symboldb.package p USING (package_id)" " WHERE symboldb.nevra(p) = 'objectweb-asm4-0:4.1-2.fc18.noarch'" " AND f.name = '/usr/share/java/objectweb-asm4/asm.jar'" " ORDER BY jc.name"); { const char *expected[] = { "org/objectweb/asm/AnnotationVisitor", "org/objectweb/asm/AnnotationWriter", "org/objectweb/asm/Attribute", "org/objectweb/asm/ByteVector", "org/objectweb/asm/ClassReader", "org/objectweb/asm/ClassVisitor", "org/objectweb/asm/ClassWriter", "org/objectweb/asm/Context", "org/objectweb/asm/Edge", "org/objectweb/asm/FieldVisitor", "org/objectweb/asm/FieldWriter", "org/objectweb/asm/Frame", "org/objectweb/asm/Handle", "org/objectweb/asm/Handler", "org/objectweb/asm/Item", "org/objectweb/asm/Label", "org/objectweb/asm/MethodVisitor", "org/objectweb/asm/MethodWriter", "org/objectweb/asm/Opcodes", "org/objectweb/asm/Type", "org/objectweb/asm/signature/SignatureReader", "org/objectweb/asm/signature/SignatureVisitor", "org/objectweb/asm/signature/SignatureWriter", NULL }; unsigned end = res.ntuples(); CHECK(end > 0); for (unsigned i = 0; i <= end; ++i) { if (i == end) { CHECK(expected[i] == NULL); } else if (expected[i] == NULL) { CHECK(false); break; } else { COMPARE_STRING(res.getvalue(i, 0), expected[i]); } } } db.txn_begin(); db.add_java_error(database::contents_id(1), "error message", "/path"); db.add_java_error(database::contents_id(2), "error message", ""); db.txn_rollback(); }