Forum OpenACS Q&A: Notes package inline functions

Collapse
Posted by Nick Carroll on
G'day,

Could someone please explain what the inline_0 and inline_1
functions do in the notes-create.sql file of the Notes package.
Firstly the inline_0 function is created, then followed by a select,
and then the function is dropped.  I don't understand what is being
done here.  Is it a way of initialising an object?  The code that I
am referring to is as follows...

create function inline_0 ()
returns integer as '
begin
    PERFORM acs_object_type__create_type (
        ''note''          -- object_type
        ''Note''          -- pretty_name
        etc ...
    );
    return 0;
end;' language 'plpgsql';

select inline_0 ();

drop function inline_0 ();

Cheers,
Nick.

Collapse
Posted by Jun Yamog on
Hi Nick,

I believe inline_0 is a temp function.  If you will look at the code in it its not possible to run it on psql.  Situation such as you need to select a value into a var and use this var on another operation or have a if and then clause.  So inorder for you to perform things that can only be done in a function you create a temp function.  I have done this for some of my create and even drop scripts although I did not use inline_0.  Maybe its a name convention.  Not sure though.

Maybe someone with more experience can further elaborate on this or contradict my explanation.

Collapse
Posted by Nick Carroll on
Could it be that the Notes package is a singleton application(singleton property set to true in notes.info)?  That you cannot create more than one instance of the Notes object... which is why the function is immdediately dropped after it is used once?
Collapse
Posted by Jun Yamog on
Hi Nick,

I am pretty sure singleton does not have anything to do with that.  I assume you are currently learning OpenACS I do advise you to go on and study further.  This inline_0 never stopped me in developing OpenACS sites although it is great to know why name it inline_0.

Collapse
Posted by Nick Carroll on
Hi Jun,

Yes I am new to OpenACS.  I am still trying to get my head around the object system.  I am currently working on a clickstream package for OpenACS 4.5.  I know about Richard Li's clickstream module, but I think that it is a bit dated now.  Firstly it was written for the aD architecture, and secondly it has no concept of objects.  I am starting to understand the concept of OACS objects, and I believe they could be used for easily customising or extending  a data warehouse through a web interface.  Well that is the intended outcome of my project.

Anyway back to the inline function... so using the function and then dropping it is just a way of notifying the acs object system about the Notes object type.  I am assuming dropping the function is a way of preventing it from being used again, so that multiple objects of type Notes are not registered with the acs objects system.

And what does the singleton flag mean in the Notes.info file?  Could someone please provide examples of when this property will be used.

Cheers,
Nick.

Collapse
Posted by Jun Yamog on
Hi Nick,

You can follow this thread or search about singleton on the bboards.

https://openacs.org/bboard/q-and-a-fetch-msg.tcl?msg_id=0004Nd&topic_id=12&topic=OpenACS%204%2e0%20Design

You may also want to read about the package manager at http://yourhost/doc

Collapse
Posted by Don Baccus on
It's not a singleton package.  The datamodel is only loaded once per packages no matter how many instances of it you mount on your site.  The different instances keep themselves straight through use of their associated package_id.

The inline_0 etch functions you find in the PostgreSQL data model files are generally used to create objects or other data when the package is first installed.  They are only run once.  In this case the object type "note" is being added to the system.

We use dummy functions because PostgreSQL doesn't implement inline PL/pgSQL blocks, unlike PL/SQL.  If you look at the Oracle equivalent you'll see that the equivalent code is being executed directly in an inline BEGIN END block in the datamodel create file.