class CreateConstant extends SchemaStatement {

    private String constantName;
    private Expression expression;
    private boolean ifNotExists;

    public CreateConstant(ServerSession session, Schema schema) {
        super(session, schema);
    }

    @Override
    public int getType() {
        return SQLStatement.CREATE_CONSTANT;
    }

    public void setConstantName(String constantName) {
        this.constantName = constantName;
    }

    public void setExpression(Expression expr) {
        this.expression = expr;
    }

    public void setIfNotExists(boolean ifNotExists) {
        this.ifNotExists = ifNotExists;
    }

    @Override
    public int update() {<FILL_FUNCTION_BODY>}
}

        session.getUser().checkAdmin();
        DbObjectLock lock = schema.tryExclusiveLock(DbObjectType.CONSTANT, session);
        if (lock == null)
            return -1;

        // 当成功获得排它锁后，不管以下代码是正常还是异常返回都不需要在这里手工释放锁，
        // 排它锁会在事务提交或回滚时自动被释放。
        if (schema.findConstant(session, constantName) != null) {
            if (ifNotExists) {
                return 0;
            }
            throw DbException.get(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName);
        }
        int id = getObjectId();
        expression = expression.optimize(session);
        Value value = expression.getValue(session);
        Constant constant = new Constant(schema, id, constantName, value);
        schema.add(session, constant, lock);
        return 0;
    
<methods>public void <init>(com.lealone.db.session.ServerSession, com.lealone.db.schema.Schema) <variables>protected final non-sealed com.lealone.db.schema.Schema schema