Search in sources :

Example 1 with ViewMeta

use of com.actiontech.dble.meta.ViewMeta in project dble by actiontech.

the class UViewChildResponse method notifyProcess.

@Override
public void notifyProcess(UKvBean configValue) throws Exception {
    LOGGER.debug("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
    if (configValue.getKey().split("/").length != UcorePathUtil.getViewChangePath().split("/").length + 1) {
        // only with the type u.../d.../clu.../view/update(delete)/schema.table
        return;
    }
    String schema = configValue.getKey().split("/")[5].split(Repository.SCHEMA_VIEW_SPLIT)[0];
    String viewName = configValue.getKey().split(Repository.SCHEMA_VIEW_SPLIT)[1];
    if ("".equals(configValue.getValue())) {
        // the value of key is empty,just doing nothing
        return;
    }
    String serverId = configValue.getValue().split(Repository.SCHEMA_VIEW_SPLIT)[0];
    String optionType = configValue.getValue().split(Repository.SCHEMA_VIEW_SPLIT)[1];
    String myId = UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
    if (myId.equals(serverId) || configValue.getChangeType() == UKvBean.DELETE) {
        // self node do noting
        return;
    } else {
        try {
            if (Repository.DELETE.equals(optionType)) {
                LOGGER.debug("delete view " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
                if (!DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().containsKey(viewName)) {
                    return;
                }
                DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().remove(viewName);
                ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, UcorePathUtil.SUCCESS);
            } else if (Repository.UPDATE.equals(optionType)) {
                LOGGER.debug("update view " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
                String stmt = ClusterUcoreSender.getKey(UcorePathUtil.getViewPath() + SEPARATOR + schema + Repository.SCHEMA_VIEW_SPLIT + viewName).getValue();
                if (DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().get(viewName) != null && stmt.equals(DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().get(viewName).getCreateSql())) {
                    return;
                }
                ViewMeta vm = new ViewMeta(stmt, schema, DbleServer.getInstance().getTmManager());
                ErrorPacket error = vm.initAndSet(true);
                Map<String, Map<String, String>> viewCreateSqlMap = DbleServer.getInstance().getTmManager().getRepository().getViewCreateSqlMap();
                Map<String, String> schemaMap = viewCreateSqlMap.get(schema);
                schemaMap.put(viewName, stmt);
                LOGGER.debug("update view result == " + error);
                if (error != null) {
                    ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, new String(error.getMessage()));
                    return;
                }
                ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, UcorePathUtil.SUCCESS);
            }
        } catch (Exception e) {
            ClusterUcoreSender.sendDataToUcore(configValue.getKey() + "/" + myId, e.toString());
        }
    }
}
Also used : ViewMeta(com.actiontech.dble.meta.ViewMeta) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) Map(java.util.Map)

Example 2 with ViewMeta

use of com.actiontech.dble.meta.ViewMeta in project dble by actiontech.

the class ShowCreateView method sendOutTheViewInfo.

public static void sendOutTheViewInfo(ServerConnection c, String schema, String viewName) throws Exception {
    // check if the view or schema is not exists
    if (schema == null || "".equals(schema)) {
        throw new Exception(" No database selected");
    }
    SchemaMeta schemaMeta = DbleServer.getInstance().getTmManager().getCatalogs().get(schema);
    if (schemaMeta == null) {
        throw new Exception("Table '" + schema + "." + viewName + "' doesn't exist");
    }
    ViewMeta view = schemaMeta.getViewMetas().get(viewName);
    if (view == null) {
        throw new Exception("Table '" + schema + "." + viewName + "' doesn't exist");
    }
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = EOF.write(buffer, c, true);
    // write rows
    byte packetId = EOF.getPacketId();
    RowDataPacket row = getRow(view, c.getCharset().getResults(), c.getCharset().getCollation());
    row.setPacketId(++packetId);
    buffer = row.write(buffer, c, true);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : ViewMeta(com.actiontech.dble.meta.ViewMeta) SchemaMeta(com.actiontech.dble.meta.SchemaMeta) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 3 with ViewMeta

use of com.actiontech.dble.meta.ViewMeta in project dble by actiontech.

the class CreateViewHandler method handle.

public static void handle(String stmt, ServerConnection c, boolean isReplace) {
    // create a new object of the view
    ViewMeta vm = new ViewMeta(stmt, c.getSchema(), DbleServer.getInstance().getTmManager());
    ErrorPacket error = vm.initAndSet(isReplace);
    if (error != null) {
        // if any error occurs when parse sql into view object
        c.writeErrMessage(error.getErrNo(), new String(error.getMessage()));
        return;
    }
    // or just save the create sql into file
    saveCreateSqlToReposoitory(stmt, vm.getViewName(), c.getSchema());
    // if the create success with no error send back OK
    c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
}
Also used : ViewMeta(com.actiontech.dble.meta.ViewMeta) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Aggregations

ViewMeta (com.actiontech.dble.meta.ViewMeta)3 ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)2 SchemaMeta (com.actiontech.dble.meta.SchemaMeta)1 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1