Ir al contenido
Otras versiones

Cargando…

LegacyDAO

Esta página aún no está disponible en tu idioma.

Manage the execution of queries in database. For example, the execution of queries in SQL or HQL.

Description:

Method Return values Description
executeSQL(final Reader rd) void Load specific database import.
  • rd: Reader for the content

Example:

package com.openkm;
import java.io.InputStream;
import java.io.StringReader;
import org.apache.commons.io.IOUtils;
import com.openkm.core.Config;
import com.openkm.dao.LegacyDAO;
import com.openkm.util.ConfigUtils;
import com.openkm.util.DatabaseDialectAdapter;
public class Test {
public static void main(String[] args) {
try {
InputStream is = ConfigUtils.getResourceAsStream("test.sql");
String adapted = DatabaseDialectAdapter.dialectAdapter(is, Config.HIBERNATE_DIALECT);
LegacyDAO.executeSQL(new StringReader(adapted));
IOUtils.closeQuietly(is);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
executeSQL(final String query, Object… params) List<List> Execute SQL query.
  • query: The query for execute

Example:

package com.openkm;
import java.util.List;
import com.openkm.bean.form.Option;
import com.openkm.dao.LegacyDAO;
public class Test {
public static void main(String[] args) {
try {
String query = "select DMT_VIRTUAL_COLUMN, DMT_REAL_COLUMN from OKM_DB_METADATA_TYPE";
for (List<String> row : LegacyDAO.executeSQL(query, null)) {
Option option = new Option();
option.setValue(row.get(0));
option.setLabel(row.get(1));
System.out.println("First value :" + row.get(0) + " Second value: " + row.get(1) + " ...");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
executeHQL(final String query) List Execute HQL query.
  • query: The text of the query to execut

Example:

package com.openkm;
import java.util.List;
import com.openkm.dao.LegacyDAO;
public class Test {
public static void main(String[] args) {
try {
String query = "select dmt.virtualColumn, dmt.realColumn from DatabaseMetadataType dmt";
List<object> list = LegacyDAO.executeHQL(query);
for (Object obj : list) {
Object[] dt = (Object[]) obj;
System.out.println(
"First value :" + String.valueOf(dt[0]) + " Second value: " + String.valueOf(dt[1]) + " ...");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}