~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/uuid_function/uuid_function.cc

This patch completes the first step in the splitting of
the XA resource manager API from the storage engine API,
as outlined in the specification here:

http://drizzle.org/wiki/XaStorageEngine

* Splits plugin::StorageEngine into a base StorageEngine
  class and two derived classes, TransactionalStorageEngine
  and XaStorageEngine.  XaStorageEngine derives from
  TransactionalStorageEngine and creates the XA Resource
  Manager API for storage engines.

  - The methods moved from StorageEngine to TransactionalStorageEngine
    include releaseTemporaryLatches(), startConsistentSnapshot(), 
    commit(), rollback(), setSavepoint(), releaseSavepoint(),
    rollbackToSavepoint() and hasTwoPhaseCommit()
  - The methods moved from StorageEngine to XaStorageEngine
    include recover(), commitXid(), rollbackXid(), and prepare()

* Places all static "EngineVector"s into their proper
  namespaces (typedefs belong in header files, not implementation files)
  and places all static methods corresponding
  to either only transactional engines or only XA engines
  into their respective files in /drizzled/plugin/

* Modifies the InnoDB "handler" files to extend plugin::XaStorageEngine
  and not plugin::StorageEngine

The next step, as outlined in the wiki spec page above, is to isolate
the XA Resource Manager API into its own plugin class and modify
plugin::XaStorageEngine to implement plugin::XaResourceManager via
composition.  This is necessary to enable building plugins which can
participate in an XA transaction *without having to have that plugin
implement the entire storage engine API*

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
 
 *  Copyright (C) 2010 Stewart Smith
6
 
 *
7
 
 *  This program is free software; you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation; version 2 of the License.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
 
23
 
#include <drizzled/charset_info.h>
24
 
#include <drizzled/function/str/strfunc.h>
25
 
#include <drizzled/item/func.h>
26
 
#include <drizzled/plugin/function.h>
27
 
 
28
 
#include <uuid/uuid.h>
29
 
 
30
 
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
31
 
 
32
 
namespace plugin {
33
 
namespace uuid {
34
 
 
35
 
class Generate: public drizzled::Item_str_func
36
 
{
37
 
public:
38
 
  Generate(): drizzled::Item_str_func() {}
39
 
  void fix_length_and_dec()
40
 
  {
41
 
    collation.set(drizzled::system_charset_info);
42
 
    /*
43
 
       NOTE! uuid() should be changed to use 'ascii'
44
 
       charset when hex(), format(), md5(), etc, and implicit
45
 
       number-to-string conversion will use 'ascii'
46
 
    */
47
 
    max_length= UUID_LENGTH * drizzled::system_charset_info->mbmaxlen;
48
 
  }
49
 
  const char *func_name() const{ return "uuid"; }
50
 
  drizzled::String *val_str(drizzled::String *);
51
 
};
52
 
 
53
 
drizzled::String *Generate::val_str(drizzled::String *str)
54
 
{
55
 
  uuid_t uu;
56
 
  char *uuid_string;
57
 
 
58
 
  /* 36 characters for uuid string +1 for NULL */
59
 
  str->realloc(UUID_LENGTH+1);
60
 
  str->length(UUID_LENGTH);
61
 
  str->set_charset(drizzled::system_charset_info);
62
 
  uuid_string= (char *) str->ptr();
63
 
  uuid_generate(uu);
64
 
  uuid_unparse(uu, uuid_string);
65
 
 
66
 
  return str;
67
 
}
68
 
 
69
 
} // uuid
70
 
} // plugin
71
 
 
72
 
static int initialize(drizzled::module::Context &context)
73
 
{
74
 
  context.add(new drizzled::plugin::Create_function<plugin::uuid::Generate>("uuid"));
75
 
 
76
 
  return 0;
77
 
}
78
 
 
79
 
DRIZZLE_DECLARE_PLUGIN
80
 
{
81
 
  DRIZZLE_VERSION_ID,
82
 
  "uuid",
83
 
  "1.1",
84
 
  "Stewart Smith, Brian Aker",
85
 
  "UUID() function using libuuid",
86
 
  drizzled::PLUGIN_LICENSE_GPL,
87
 
  initialize, /* Plugin Init */
88
 
  NULL,   /* depends */
89
 
  NULL    /* config options */
90
 
}
91
 
DRIZZLE_DECLARE_PLUGIN_END;