Piotras' blog: Archive
2007-03-01 - 2007-03-31
midgard_config or how to create database tables
Posted on 2007-03-13 10:04:43 UTC.
Just two weeks ago I wrote about midgard_config and creating personal database. In that case I used SQLite provider and now I will try MySQL and PostgreSQL ones. If you used to switch between database types , I suggest to create few database types entries in configuration file.
Just like this:
Type=MySQL
#Type=SQLite
#Type=PostgreSQL
Comment , uncomment whenever you want. Yes, I know no one is so crazy to switch among database types every 5 minutes, but at least we have such possibility :)
I assume , you already created database and it's owner. So now it's high time to create basic tables and those ones needed for all Your MgdSchema classes.
Let's use personal "MyConfig" configuration file.
<?php
mgd_config_init("MyConfig");
$config = new midgard_config("MyConfig");
if($config->tablecreate) {
midgard_config::create_midgard_tables();
foreach($_MIDGARD['schema']['types'] as $classname => $data) {
midgard_config::create_class_table($classname);
}
}
?>
Run this script and enjoy spring morning in meantime.
The things which happen in background are sexy or jazzy. In Poland you may say "kaczi" which means "ducky". ( Because these two twins has 'duck' in their surname ) BTW, if you do not know how to recognize them , the hint is: one is president and another is prime minister.
midgard_config::create_midgard_tables
Creates tables used by Midgard itself.
- repligard
- sitegroup
- midgard_user
- imports default SG0 root with 'admin' username
midgard_config::create_class_table($classname)
Creates all tables and columns needed for class.
- If class is multilingual then language content table is also created.
- guid and sitegroup column is automagically created
- metadata columns are also automagically created
- All required indexes are also created for table.
Now, you are able to login to Midgard database. Stay tuned to learn more about "how can I login in to Midgard database?"
drinking too much kaffe
Posted on 2007-03-20 07:51:30 UTC.
I tried to write simple midgard-java jni based bindings , but unfortunatelly got few not interesting issues.
If you follow almost every JNI specifications and docs and examples, you should run command like:
javah -jni org_midgardproject_connection
Not expected output is:
Failed to open object 'org_midgardproject_connection'
I was wondering what is the case as it worked perfect few days ago with HelloWorld example. And problem seems to be in some package being overwritten or removed or updated. I made few java related packages reinstall when I wanted to compile latest java-gnome. No success, though :/
Solution here is simple:
javah -classpath . -jni org_midgardproject_connection
Next problem is more difficult. When I compiled my org_midgardproject_connecion , I tried to run my new java script:
java -Djava.library.path=`pwd` org_midgardproject_connection arg
And exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Open at org_midgardproject_connection.main(org_midgardproject_connection.java:38)
Solution here is to "tweak" header and source file , which is badly created by javah tool.
JNIEXPORT jboolean JNICALL Java_org_midgardproject_connection_Open(JNIEnv*, jobject, jstring);
There are no '1' after underscores. So function prototype should look like this:
JNIEXPORT jboolean JNICALL Java_org_1midgardproject_1connection_Open(JNIEnv*, jobject, jstring);
After this change everything seems to be working very nice.
Aha, just in case if you would like to write midgard-java bindings. Compile it like this:
gcj -shared `pkg-config --libs --cflags midgard` org_midgardproject_connection.c -o libmidgard-java.so
So now, java code looks like this:
class org_midgardproject_connection
{
public native boolean Open(String name);
private static native boolean SetSitegroup(String guid);
private static native String GetSitegroup();
public static void main(String[] args) {
new org_midgardproject_connection().Open(args[0]); }
static {
System.loadLibrary("midgard-java");
}
}
And simple JNI C code:
JNIEXPORT jboolean JNICALL
Java_org_1midgardproject_1connection_Open
(
JNIEnv *env,
jobject _object,
jstring _name
)
{
g_type_init();
MidgardConnection *mgd = midgard_connection_new();
gchar *name = (gchar*) (*env)->GetStringUTFChars(env, _name, NULL);
gboolean rv;
rv = midgard_connection_open(mgd, name, NULL);
(*env)->ReleaseStringUTFChars(env, _name, name);
return (jboolean) rv;
}
I tried java script being logged in as custom user, and midgard-core tried to open configuration file from /etc. So I got "Permission denied".
Looks like it is working :)