Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
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);
	}

}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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;
}