⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trace.java

📁 用JAVA实现了,将DB装入内存,内存由DBMS控制,实现简单数据库的创建、数据表的创建、记录插入、查询以及表的删除。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        sb.append(mainErrorMessage.substring(lastIndex, escIndex));

        return new KdbException(sb.toString(), state, -code);
    }

    /**
     * Compose error message by inserting the strings in the add parameters
     * in placeholders within the error message. The message string contains
     * $$ markers for each context variable. Context variables are supplied in
     * the add parameters.
     *
     * @param code main error code
     * @param add  optional parameters
     * @return an <code>KdbException</code>
     */
    public static KdbException error(int code, final Object[] add) {
        return error(code, 0, add);
    }

    public static KdbException error(int code, int code2, String add) {
        return error(code, getMessage(code2) + ' ' + add);
    }

    public static KdbException error(int code, int code2) {
        return error(code, getMessage(code2));
    }

    /**
     * Method declaration
     *
     * @param code
     * @param add
     * @return
     */
    public static KdbException error(int code, Object add) {

// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)
        code = Math.abs(code);

        String s = getMessage(code);

        if (add != null) {
            s += ": " + add.toString();
        }

// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)
        return new KdbException(s.substring(6), s.substring(0, 5), -code);

        //return getError(s);
    }

    /**
     *     Return a new <code>KdbException</code> according to the result parameter.
     *
     * @param result    the <code>Result</code> associated with the exception
     *     @return a new <code>KdbException</code> according to the result parameter
     */
//    public static KdbException error(final Result result) {
//        return new KdbException(result);
//    }

    /**
     * Return a new <code>Result</code> of type error.
     *
     * @param result    the <code>Result</code> associated with the exception
     *     @return a new <code>KdbException</code> according to the result parameter
     */

// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)

    /**
     * Constructor for errors
     */
//    static Result toResult(KdbException e) {
//        return new Result(e.getMessage(), e.getSQLState(), e.getErrorCode());
//    }
    public static RuntimeException runtimeError(int code, Object add) {

        KdbException e = error(code, add);

        return new RuntimeException(e.getMessage());
    }

    /**
     * Returns the error message given the error code.<br/>
     * Note: this method must be used when throwing exception other
     * than <code>KdbException</code>.
     *
     * @param errorCode the error code associated to the error message
     * @return the error message associated with the error code
     * @see
     */
    public static String getMessage(final int errorCode) {
        return getMessage(errorCode, false, null);
    }

    /**
     * Returns the error message given the error code.<br/>
     * Note: this method must be used when throwing exception other
     * than <code>KdbException</code>.
     *
     * @param errorCode  the error code associated to the error message
     * @param substitute substitute the $$ tokens using data in the values
     * @param values     value(s) to use to replace the token(s)
     * @return the error message associated with the error code
     * @see
     */
    public static String getMessage(final int errorCode,
                                    final boolean substitute,
                                    final Object[] values) {

        if (errorCode < 0) {
            return "";
        } else {
            String key = String.valueOf(errorCode);

            if (errorCode < 10) {
                key = "00" + key;
            } else if (errorCode < 100) {
                key = "0" + key;
            }

            String mainErrorMessage = BundleHandler.getString(bundleHandle,
                    key);

            if (!substitute) {

//                return sDescription[errorCode];
                return mainErrorMessage;
            } else {

//                final String mainErrorMessage = sDescription[errorCode];
                final StringBuffer sb =
                        new StringBuffer(mainErrorMessage.length() + 32);
                int lastIndex = 0;
                int escIndex = mainErrorMessage.length();

                if (values != null) {

                    // removed test: i < add.length
                    // because if mainErrorMessage is equal to "blabla $$"
                    // then the statement escIndex = mainErrorMessage.length();
                    // is never reached!  ???
                    for (int i = 0; i < values.length; i++) {
                        escIndex = mainErrorMessage.indexOf(MESSAGE_TAG,
                                lastIndex);

                        if (escIndex == -1) {
                            break;
                        }

                        sb.append(mainErrorMessage.substring(lastIndex,
                                escIndex));
                        sb.append(values[i].toString());

                        lastIndex = escIndex + MESSAGE_TAG.length();
                    }
                }

                escIndex = mainErrorMessage.length();

                sb.append(mainErrorMessage.substring(lastIndex, escIndex));

                return sb.toString();
            }
        }
    }

    /**
     * Method declaration
     *
     * @param code
     * @return
     */
    public static KdbException error(int code) {
        return error(code, null);
    }

    /**
     * Throws exception if condition is false
     *
     * @param condition
     * @param code
     * @throws KdbException
     */
    public static void check(boolean condition,
                             int code) throws KdbException {
        check(condition, code, null, null, null, null);
    }

    /**
     * Throws exception if condition is false
     *
     * @param condition
     * @param code
     * @param add
     * @throws KdbException
     */
    public static void check(boolean condition, int code,
                             Object add) throws KdbException {

        if (!condition) {
            throw error(code, add);
        }
    }

    /**
     * Method declaration
     *
     * @param code
     * @param add
     * @throws KdbException
     */
    static void throwerror(int code, Object add) throws KdbException {
        throw error(code, add);
    }

    /**
     * Used to print messages to System.out
     *
     * @param message message to print
     */
    public static void printSystemOut(String message) {

        if (TRACESYSTEMOUT) {
            System.out.println(message);
        }
    }

    /**
     * Used to print messages to System.out
     *
     * @param message1 message to print
     * @param message2 message to print
     */
    public static void printSystemOut(String message1, long message2) {

        if (TRACESYSTEMOUT) {
            System.out.print(message1);
            System.out.println(message2);
        }
    }

    /**
     * Returns the stack trace for doAssert()
     */
    private static String getStackTrace() {

        try {
            Exception e = new Exception();

            throw e;
        } catch (Exception e) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            PrintWriter pw = new PrintWriter(os, true);

            e.printStackTrace(pw);

            return os.toString();
        }
    }

    /**
     * Throws exception if condition is false
     *
     * @param condition
     * @param code
     * @param add1
     * @param add2
     * @throws KdbException
     */
    static void check(boolean condition, int code, String add1,
                      String add2) throws KdbException {
        check(condition, code, add1, add2, null, null);
    }

    /**
     * Throws exception if condition is false
     *
     * @param condition
     * @param code
     * @param add1
     * @param add2
     * @param add3
     * @throws KdbException
     */
    static void check(boolean condition, int code, String add1, String add2,
                      String add3) throws KdbException {
        check(condition, code, add1, add2, add3, null);
    }

    /**
     * Throws exception if condition is false
     *
     * @param condition
     * @param code
     * @param add1
     * @param add2
     * @param add3
     * @param add4
     * @throws KdbException
     */
    static void check(boolean condition, int code, String add1, String add2,
                      String add3, String add4) throws KdbException {

        if (!condition) {
            String add = "";

            if (add1 != null) {
                add += add1;
            }

            if (add2 != null) {
                add += add2;
            }

            if (add3 != null) {
                add += add3;
            }

            if (add4 != null) {
                add += add4;
            }

            throw error(code, add.length() > 0 ? add
                    : null);
        }
    }

    /**
     * Throws exception if assertion fails
     *
     * @param condition
     * @throws KdbException
     */
    public static void doAssert(boolean condition) throws KdbException {
        doAssert(condition, null);
    }

    /**
     * Throws exception if assertion fails
     *
     * @param condition
     * @param error
     * @throws KdbException
     */
    public static void doAssert(boolean condition,
                                String error) throws KdbException {

        if (!condition) {
            if (error == null) {
                error = "";
            }

            error += getStackTrace();

            throw error(ASSERT_FAILED, error);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -