Usar su propia tabla de base de datos desde el frontend ( GWT )
Métodos
Sección titulada «Métodos»La clase OKMDatabaseMetadataService contiene la definición de la interfaz para acceder a los servicios de metadatos.
| Método | Retorno | Descripción |
|---|---|---|
| executeValueQuery(String table, String filter, String order) | List<Map<String,String>> | Ejecuta una consulta de selección. |
| updateValue(Map<String,String> map) | String | Ejecuta una consulta de actualización. |
| createValue(Map<String,String> map) | String | Ejecuta una consulta de creación. |
| executeMultiValueQuery(List |
List<List<Map<String, String>>> | Ejecuta una consulta que devuelve resultados de varias tablas de metadatos. |
| getNextSequenceValue(String table, String column) | double | Obtiene el siguiente valor de una secuencia. |
| deleteValue(Map<String, String> map) | void | Ejecuta una consulta de borrado. |
Ejemplo
Sección titulada «Ejemplo»Registrar la definición de la tabla de metadatos de la base de datos
Sección titulada «Registrar la definición de la tabla de metadatos de la base de datos»Vaya a Administration > Tools > Database query y ejecute el SQL:
INSERT INTO OKM_DB_METADATA_TYPE (DMT_TABLE, DMT_REAL_COLUMN, DMT_TYPE, DMT_VIRTUAL_COLUMN) VALUES ('security', 'col00', 'text', 'uuid_id');INSERT INTO OKM_DB_METADATA_TYPE (DMT_TABLE, DMT_REAL_COLUMN, DMT_TYPE, DMT_VIRTUAL_COLUMN) VALUES ('security', 'col01', 'text', 'type');INSERT INTO OKM_DB_METADATA_TYPE (DMT_TABLE, DMT_REAL_COLUMN, DMT_TYPE, DMT_VIRTUAL_COLUMN) VALUES ('security', 'col02', 'text', 'name');Clases Java
Sección titulada «Clases Java»Fichero GWTExtendedSecurity.java:
public class GWTExtendedSecurity extends DatabaseMetadataCommon implements IsSerializable { public static final String TYPE_USER = "user"; public static final String TYPE_ROLE = "role";
// Metadata Virtual Name mapping public static final String MV_TABLE_NAME = "security"; public static final String MV_COLUMN_NAME_UUID = "uuid_id"; public static final String MV_COLUMN_NAME_TYPE = "type"; public static final String MV_COLUMN_NAME_NAME = "name";
private String uuid; private String type; private String name;
@Override public void loadFromMap(Map<String, String> map) { super.loadFromMap(map);
if (map.containsKey(MV_COLUMN_NAME_UUID)) { setUuid(map.get(MV_COLUMN_NAME_UUID)); }
if (map.containsKey(MV_COLUMN_NAME_TYPE)) { setType(map.get(MV_COLUMN_NAME_TYPE)); }
if (map.containsKey(MV_COLUMN_NAME_NAME)) { setName(map.get(MV_COLUMN_NAME_NAME)); } }
@Override public Map<String, String> restoreToMap() { Map<String,String> map = super.restoreToMap();
if (uuid != null) { map.put(MV_COLUMN_NAME_UUID, getUuid()); }
if (type != null) { map.put(MV_COLUMN_NAME_TYPE, getType()); }
if (name != null) { map.put(MV_COLUMN_NAME_NAME, getName()); }
return map; }
public String getUuid() { return uuid; }
public void setUuid(String uuid) { this.uuid = uuid; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }}Fichero Example.java:
public class Example { private final OKMDatabaseMetadataServiceAsync metadataService = (OKMDatabaseMetadataServiceAsync) GWT.create(OKMDatabaseMetadataService.class);
public test() { // get sequence metadataService.getNextSequenceValue("table_name", "col_name" , new AsyncCallback<Double>() { @Override public void onSuccess(Double result) { int value = result.intValue(); }
@Override public void onFailure(Throwable caught) { } });
// create value final GWTExtendedSecurity security = new GWTExtendedSecurity(); security.setUuid("some uuid"); security.setName("some name"); security.setType(GWTExtendedSecurity.TYPE_ROLE); security.setRealTable(GWTExtendedSecurity.MV_TABLE_NAME); metadataService.createValue(security.restoreToMap(), new AsyncCallback<Double>() { @Override public void onSuccess(Double result) { // created }
@Override public void onFailure(Throwable caught) { } });
// Execute query String filter = "$" + GWTExtendedSecurity.MV_COLUMN_NAME_UUID + "='some uuid'"; metadataService.executeValueQuery(GWTExtendedSecurity.MV_TABLE_NAME, filter, "", new AsyncCallback<List<Map<String,String>>>() { @Override public void onSuccess(List<Map<String, String>> result) { if (result.size() > 0) { GWTExtendedSecurity security = new GWTExtendedSecurity(); secutiry.loadFromMap(result.get(0)); } }
@Override public void onFailure(Throwable caught) { GeneralComunicator.showError("executeValueQuery", caught); } });
// Update value security.setName("some name changed"); metadataService.updateValue(security.restoreToMap(), new AsyncCallback<Object>() { @Override public void onSuccess(Object result) { }
@Override public void onFailure(Throwable caught) { } });
// Delete value metadataService.deleteValue(security.restoreToMap(), new AsyncCallback<Object>() { @Override public void onSuccess(Object result) { }
@Override public void onFailure(Throwable caught) { } }); }}Avanzado
Sección titulada «Avanzado»También pueden hacerse uniones (joins) entre tablas; para ello debe utilizarse el método executeMultiValueQuery:
List<String> tables = new ArrayList<String>();tables.add(GWTCountry.MV_TABLE_NAME);tables.add(GWTState.MV_TABLE_NAME);
String query = "from DatabaseMetadataValue dmv1, DatabaseMetadataValue dmv2 ";query += "where dmv1.table='" + GWTCountry.MV_TABLE_NAME + "' ";query += "and dmv2.table='" + GWTState.MV_TABLE_NAME + "' ";query += "and dmv1.$" + GWTCountry.MV_COLUMN_COUNTRY_NAME + "='SPAIN' ";query += "and dmv1.$" + GWTCountry.MV_COLUMN_COUNTRY_NAME + "=" + "dmv2.$" + GWTState.MV_COLUMN_COUNTRY_NAME;
metadataService.executeMultiValueQuery(tables, query, new AsyncCallback<List<List<Map<String,String>>>>() { @Override public void onSuccess(List<List<Map<String, String>>> result) { if (!result.isEmpty()) { List<Map<String, String>> dmvRow = result.get(0);
if (!dmvRow.isEmpty() && dmvRow.size() == 2) { GWTState state = new GWTState(); state.loadFromMap(dmvRow.get(1)); } } }
@Override public void onFailure(Throwable caught) { }});