LegacySrv

executeSQL

Description:

MethodReturn valuesDescription

executeSQL(String sql)

List<List<String>>

Executes SQL script.

SELECT NBS_UUID, NBS_AUTHOR, NBS_NAME, NBS_NOTES FROM OKM_NODE_BASE LIMIT 10;

The parameter named sql only allows a single SQL script.

This action can only be done by users with administrator grants.

Example:

package com.openkm;

import java.util.List;

import com.openkm.db.service.LegacySrv;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            LegacySrv legacySrv = ContextWrapper.getContext().getBean(LegacySrv.class);
            List<List<String>> results = legacySrv.executeSQL("SELECT NBS_UUID, NBS_AUTHOR, NBS_NAME, NBS_NOTES FROM OKM_NODE_BASE LIMIT 10;");
            for (List<String> row : results) {
                System.out.println("uuid: " + row.get(0));
                System.out.println("Author: " + row.get(1));
                System.out.println("Name: " + row.get(2));
                System.out.println("Notes: " + row.get(3));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

executeHQL

Description:

MethodReturn valuesDescription

executeHQL(String hql)

List<Object>

Executes HQL script.

SELECT uuid, name from NodeBase where name = 'okm:root';

The parameter named hql only allows a single HQL script.

This action can only be done by users with administrator grants.

Example:

package com.openkm;

import java.util.List;

import com.openkm.db.service.LegacySrv;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            LegacySrv legacySrv = ContextWrapper.getContext().getBean(LegacySrv.class);
            List<Object> results = legacySrv.executeHQL("SELECT * from NodeBase nb where nb.name = 'okm:root';");
            for (Object obj : results) {
                if (obj instanceof Object[]) {
                    Object[] ao = (Object[]) obj;

                    for (Object o : ao) {
                        System.out.println(String.valueOf(o));
                    }
                } else {
                    System.out.println(String.valueOf(obj));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

Table of contents [ Hide Show ]