Exemplo n.º 1
0
void o_database_close(struct o_database * db)
{
	try
	{
		if (db->referrers != 0)
		{
			int count = o_list_size(db->referrers);
			while (count > 0)
				*((struct o_database **) o_list_get(db->referrers, --count)) = 0;
			o_list_free(db->referrers);
			db->referrers = 0;
		}
		if (db->storage != 0)
			o_storage_close(db->storage);
		if (db->context != 0)
		{
			o_operation_context_release(db->context);
		}
	}
	catch(struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
}
void *o_native_write_thread(void * par)
{
	struct o_native_socket * cur_sock = 0;
	struct o_native_socket * sock_listen = 0;
	try
	{

		sock_listen = o_native_socket_listen("127.0.0.1", 2000);
		cur_sock = o_native_socket_accept(sock_listen);
	}
	catch(struct o_exception, ex)
	{
		printf("fail listen:%s", o_exception_message(ex));
		o_exception_free(ex);
		fflush(stdout);
		return 0;
	}
	end_try;

	int val;
	int size = sizeof(int);
	o_native_socket_recv(cur_sock, &val, &size, 0);
	o_native_thread_current_sleep(10);
	o_native_socket_send(cur_sock, &val, size);
	o_native_socket_close(cur_sock);
	o_native_socket_close(sock_listen);
	o_native_thread_current_exit();
	return 0;
}
Exemplo n.º 3
0
void test_o_exceptions_nested()
{
	try
	{
		int check = 0;
		try
		{
			internal_safe_exception();
			check = 1;
			internal_exception();
			fail("Error this code must not be executed after exception throw");
		}
		catch(struct o_exception ,ex)
		{
			if (check == 0)
				fail("Exception scaled up before");
			assert_true(strcmp(o_exception_message(ex), EXCEPTION_MESSAGE) == 0, "Exception message not match");
			assert_true(o_exception_code(ex) == 20, "Exception error code not match");
			o_exception_free(ex);
		}
		end_try;
	}
	catch(struct o_exception ,ex)
	{
		o_exception_free(ex);
		fail("Error on catch invoke");
	}
	end_try;
}
Exemplo n.º 4
0
void test_o_connection_local_data_transfer()
{
	try
	{

		struct o_native_thread * th = o_native_thread_new("server", test_o_connection_private_listen_thread);
		o_native_thread_start(th);

		o_native_thread_current_sleep(400);

		struct o_connection * client_con = o_connection_remote_new(HOST_TEST, PORT_TEST);
		struct o_connection_remote * client = (struct o_connection_remote *) client_con;

		o_connection_remote_write_int(client, 10);
		int val = o_connection_remote_read_int(client);
		assert_true(val == 10, "error transfer int");

		o_connection_remote_write_byte(client, 10);
		char val_c = o_connection_remote_read_byte(client);
		assert_true(val_c == 10, "error transfer byte");

		o_connection_remote_write_short(client, 10);
		short val_s = o_connection_remote_read_short(client);
		assert_true(val_s == 10, "error transfer short");

		o_connection_remote_write_long64(client, 10);
		long long val_64 = o_connection_remote_read_long64(client);
		assert_true(val_64 == 10, "error transfer long 64");

		unsigned char to_send[15] =
		{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
		o_connection_remote_write_bytes(client, to_send, 15);

		int number;
		unsigned char *bytes = o_connection_remote_read_bytes(client, &number);
		assert_true(number == 15, "error transfer size of byte array");
		int i;
		for (i = 0; i < 15; ++i)
			assert_true(bytes[i] == to_send[i], "error transfer content of byte array");
		o_free(bytes);

		char * string = "test string";
		o_connection_remote_write_string(client, string);
		char * string_ret = o_connection_remote_read_string(client);
		assert_true(strcmp(string, string_ret) == 0, "error transfer string");
		o_free(string_ret);

		o_connection_free(client_con);
	}
	catch (struct o_exception, e)
	{
		char buf[512];
		sprintf(buf, "Error Message %s", o_exception_message(e));
		fail(buf);
	}
	end_try;
}
Exemplo n.º 5
0
void o_database_open(struct o_database * db, char * username, char * password)
{
	try
	{
		db->storage = o_engine_get_storage(db->connection_url, username, password);
		db->context = o_database_operation_context(db->storage);
	}
	catch(struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
}
Exemplo n.º 6
0
struct o_record * o_database_load(struct o_database * db, struct o_record_id * rid)
{
	struct o_record * rec = 0;
	try
	{
		rec = o_operation_context_load(db->context, rid);
	}
	catch( struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
	return rec;
}
Exemplo n.º 7
0
void internal_safe_exception()
{
	try
	{
		internal_exception();
		fail("Error this code must not be executed after exception throw");
	}
	catch(struct o_exception ,ex)
	{
		assert_true(strcmp(o_exception_message(ex), EXCEPTION_MESSAGE) == 0, "Exception message not match");
		assert_true(o_exception_code(ex) == 20, "Exception error code not match");
		o_exception_free(ex);
	}
	end_try;
}
Exemplo n.º 8
0
void o_database_rollback(struct o_database * db)
{
	o_database_context_database_init(db);
	try
	{
		o_operation_context_rollback(db->context);
		db->context = o_operation_context_release(db->context);
	}
	catch( struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
	o_database_context_database_init(0);
}
Exemplo n.º 9
0
void o_database_begin_transaction(struct o_database * db)
{
	o_database_context_database_init(db);
	try
	{
		struct o_transaction * new_trans = o_transaction_new(db->context);
		db->context = o_transaction_to_operation_context(new_trans);
	}
	catch( struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
	o_database_context_database_init(0);
}
Exemplo n.º 10
0
void test_o_exception_throw()
{
	try
	{
		struct o_exception *ex = o_exception_new(EXCEPTION_MESSAGE, 20);
		throw(ex);
		fail("Error this code must not be executed after exception throw");
	}
	catch(struct o_exception , ex)
	{
		assert_true(strcmp(o_exception_message(ex), EXCEPTION_MESSAGE) == 0, "Exception message not match");
		assert_true(o_exception_code(ex) == 20, "Exception error code not match");
		o_exception_free(ex);
	}

}
Exemplo n.º 11
0
int o_database_save_cluster(struct o_database * db, struct o_record * record, char * cluster_name, struct o_record_id ** rid)
{
	int result = 0;
	o_database_context_database_init(db);
	try
	{
		result = o_operation_context_save(db->context, record, cluster_name, rid);
	}
	catch( struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
	o_database_context_database_init(0);
	return result;
}
Exemplo n.º 12
0
int o_database_delete(struct o_database * db, struct o_record * record)
{
	int result = 0;
	o_database_context_database_init(db);
	try
	{
		result = o_operation_context_delete(db->context, record);
	}
	catch( struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
	o_database_context_database_init(0);
	return result;
}
Exemplo n.º 13
0
void *test_o_connection_private_listen_thread(void * par)
{
	try
	{
		struct o_database_socket * socket = o_database_socket_listen(HOST_TEST, PORT_TEST);
		struct o_connection * server_conn = o_connection_remote_new_accept(socket);

		struct o_connection_remote * server = (struct o_connection_remote *) server_conn;

		int val = o_connection_remote_read_int(server);
		o_connection_remote_write_int(server, val);

		char val_c = o_connection_remote_read_byte(server);
		o_connection_remote_write_byte(server, val_c);

		short val_s = o_connection_remote_read_short(server);
		o_connection_remote_write_short(server, val_s);

		long long val_64 = o_connection_remote_read_long64(server);
		o_connection_remote_write_long64(server, val_64);

		int number;
		unsigned char *bytes = o_connection_remote_read_bytes(server, &number);
		o_connection_remote_write_bytes(server, (unsigned char *)bytes, number);
		o_free(bytes);

		char * string = o_connection_remote_read_string(server);
		o_connection_remote_write_string(server, string);
		o_free(string);

		o_connection_free(server_conn);
		o_database_socket_close(socket);
		o_native_thread_current_exit();
	}
	catch (struct o_exception, e)
	{
		char buf[512];
		printf(buf, "Thread fail unsupported -> Error Message: %s", o_exception_message(e));
		fflush(stdout);
	}
	end_try;

	return par;
}
Exemplo n.º 14
0
struct o_record * o_database_metadata(struct o_database * db)
{
	o_database_context_database_init(db);
	struct o_record * metadata = 0;
	try
	{
		struct o_record_id * rid = o_storage_get_metadata_rid(db->storage);
		metadata = o_database_load(db, rid);
		o_record_id_release(rid);
	}
	catch( struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
	o_database_context_database_init(0);
	return metadata;
}
Exemplo n.º 15
0
struct o_list_record * o_database_query(struct o_database * db, struct o_query * query)
{
	o_database_context_database_init(db);
	try
	{
		struct o_db_internal_result_handler handler;
		handler.list = o_list_record_new();
		if (o_database_query_internal(db, query, 0, o_query_context_listener, &handler))
		{
			return handler.list;
		}
	}
	catch( struct o_exception, ex)
	{
		DB_ERROR_NOTIFY(db, o_exception_code(ex), o_exception_message(ex));
		o_exception_free(ex);
	}
	end_try;
	o_database_context_database_init(0);
	return 0;
}