Use your own database table from frontend ( GWT )
Methods
Section titled “Methods”The class OKMDatabaseMetadataService has the interface definition to access metadata services.
| Method | return | Description |
|---|---|---|
| executeValueQuery(String table, String filter, String order) | List<Map<String,String>> | Executes a selected query. |
| updateValue(Map<String,String> map) | String | Executes an updated query. |
| createValue(Map<String,String> map) | String | Executes and creates a query. |
| executeMultiValueQuery(List |
List<List<Map<String, String>>> | Executes a query that returns a results with several metadata tables. |
| getNextSequenceValue(String table, String column) | double | Gets the next value of a sequence. |
| deleteValue(Map<String, String> map) | void | Executes and deletes a query. |
Sample
Section titled “Sample”Register database metadata table definition
Section titled “Register database metadata table definition”Go to Administration > Tools > Database query and execute the 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');Java classes
Section titled “Java classes”File 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; }}File 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) { } }); }}Advanced
Section titled “Advanced”Also can be done joins between tables for it should be used method 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) { }});