📄 ndbdictionary.cpp
字号:
/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <NdbDictionary.hpp>#include "NdbDictionaryImpl.hpp"#include <NdbOut.hpp>/***************************************************************** * Column facade */NdbDictionary::Column::Column(const char * name) : m_impl(* new NdbColumnImpl(* this)){ setName(name);}NdbDictionary::Column::Column(const NdbDictionary::Column & org) : m_impl(* new NdbColumnImpl(* this)){ m_impl = org.m_impl;}NdbDictionary::Column::Column(NdbColumnImpl& impl) : m_impl(impl){}NdbDictionary::Column::~Column(){ NdbColumnImpl * tmp = &m_impl; if(this != tmp){ delete tmp; }}NdbDictionary::Column&NdbDictionary::Column::operator=(const NdbDictionary::Column& column){ m_impl = column.m_impl; return *this;}void NdbDictionary::Column::setName(const char * name){ m_impl.m_name.assign(name);}const char* NdbDictionary::Column::getName() const { return m_impl.m_name.c_str();}voidNdbDictionary::Column::setType(Type t){ m_impl.init(t);}NdbDictionary::Column::Type NdbDictionary::Column::getType() const { return m_impl.m_type;}void NdbDictionary::Column::setPrecision(int val){ m_impl.m_precision = val;}int NdbDictionary::Column::getPrecision() const { return m_impl.m_precision;}void NdbDictionary::Column::setScale(int val){ m_impl.m_scale = val;}int NdbDictionary::Column::getScale() const{ return m_impl.m_scale;}voidNdbDictionary::Column::setLength(int length){ m_impl.m_length = length;}int NdbDictionary::Column::getLength() const{ return m_impl.m_length;}voidNdbDictionary::Column::setInlineSize(int size){ m_impl.m_precision = size;}voidNdbDictionary::Column::setCharset(CHARSET_INFO* cs){ m_impl.m_cs = cs;}CHARSET_INFO*NdbDictionary::Column::getCharset() const{ return m_impl.m_cs;}intNdbDictionary::Column::getInlineSize() const{ return m_impl.m_precision;}voidNdbDictionary::Column::setPartSize(int size){ m_impl.m_scale = size;}intNdbDictionary::Column::getPartSize() const{ return m_impl.m_scale;}voidNdbDictionary::Column::setStripeSize(int size){ m_impl.m_length = size;}intNdbDictionary::Column::getStripeSize() const{ return m_impl.m_length;}int NdbDictionary::Column::getSize() const{ return m_impl.m_attrSize;}void NdbDictionary::Column::setNullable(bool val){ m_impl.m_nullable = val;}bool NdbDictionary::Column::getNullable() const { return m_impl.m_nullable;}void NdbDictionary::Column::setPrimaryKey(bool val){ m_impl.m_pk = val;}bool NdbDictionary::Column::getPrimaryKey() const { return m_impl.m_pk;}void NdbDictionary::Column::setPartitionKey(bool val){ m_impl.m_distributionKey = val;}bool NdbDictionary::Column::getPartitionKey() const{ return m_impl.m_distributionKey;}const NdbDictionary::Table * NdbDictionary::Column::getBlobTable() const { NdbTableImpl * t = m_impl.m_blobTable; if (t) return t->m_facade; return 0;}void NdbDictionary::Column::setAutoIncrement(bool val){ m_impl.m_autoIncrement = val;}bool NdbDictionary::Column::getAutoIncrement() const { return m_impl.m_autoIncrement;}voidNdbDictionary::Column::setAutoIncrementInitialValue(Uint64 val){ m_impl.m_autoIncrementInitialValue = val;}voidNdbDictionary::Column::setDefaultValue(const char* defaultValue){ m_impl.m_defaultValue.assign(defaultValue);}const char*NdbDictionary::Column::getDefaultValue() const{ return m_impl.m_defaultValue.c_str();}intNdbDictionary::Column::getColumnNo() const { return m_impl.m_attrId;}boolNdbDictionary::Column::equal(const NdbDictionary::Column & col) const { return m_impl.equal(col.m_impl);}intNdbDictionary::Column::getSizeInBytes() const { return m_impl.m_attrSize * m_impl.m_arraySize;}/***************************************************************** * Table facade */NdbDictionary::Table::Table(const char * name) : m_impl(* new NdbTableImpl(* this)) { setName(name);}NdbDictionary::Table::Table(const NdbDictionary::Table & org) : NdbDictionary::Object(), m_impl(* new NdbTableImpl(* this)){ m_impl.assign(org.m_impl);}NdbDictionary::Table::Table(NdbTableImpl & impl) : m_impl(impl){}NdbDictionary::Table::~Table(){ NdbTableImpl * tmp = &m_impl; if(this != tmp){ delete tmp; }}NdbDictionary::Table&NdbDictionary::Table::operator=(const NdbDictionary::Table& table){ m_impl.assign(table.m_impl); m_impl.m_facade = this; return *this;}void NdbDictionary::Table::setName(const char * name){ m_impl.setName(name);}const char * NdbDictionary::Table::getName() const { return m_impl.getName();}intNdbDictionary::Table::getTableId() const { return m_impl.m_tableId;}void NdbDictionary::Table::addColumn(const Column & c){ NdbColumnImpl* col = new NdbColumnImpl; (* col) = NdbColumnImpl::getImpl(c); m_impl.m_columns.push_back(col); if(c.getPrimaryKey()){ m_impl.m_noOfKeys++; } if (col->getBlobType()) { m_impl.m_noOfBlobs++; } m_impl.buildColumnHash();}const NdbDictionary::Column*NdbDictionary::Table::getColumn(const char * name) const { return m_impl.getColumn(name);}const NdbDictionary::Column* NdbDictionary::Table::getColumn(const int attrId) const { return m_impl.getColumn(attrId);}NdbDictionary::Column*NdbDictionary::Table::getColumn(const char * name) { return m_impl.getColumn(name);}NdbDictionary::Column* NdbDictionary::Table::getColumn(const int attrId){ return m_impl.getColumn(attrId);}voidNdbDictionary::Table::setLogging(bool val){ m_impl.m_logging = val;}bool NdbDictionary::Table::getLogging() const { return m_impl.m_logging;}voidNdbDictionary::Table::setFragmentType(FragmentType ft){ m_impl.m_fragmentType = ft;}NdbDictionary::Object::FragmentType NdbDictionary::Table::getFragmentType() const { return m_impl.m_fragmentType;}void NdbDictionary::Table::setKValue(int kValue){ m_impl.m_kvalue = kValue;}intNdbDictionary::Table::getKValue() const { return m_impl.m_kvalue;}void NdbDictionary::Table::setMinLoadFactor(int lf){ m_impl.m_minLoadFactor = lf;}int NdbDictionary::Table::getMinLoadFactor() const { return m_impl.m_minLoadFactor;}void NdbDictionary::Table::setMaxLoadFactor(int lf){ m_impl.m_maxLoadFactor = lf; }int NdbDictionary::Table::getMaxLoadFactor() const { return m_impl.m_maxLoadFactor;}intNdbDictionary::Table::getNoOfColumns() const { return m_impl.m_columns.size();}intNdbDictionary::Table::getNoOfPrimaryKeys() const { return m_impl.m_noOfKeys;}const char*NdbDictionary::Table::getPrimaryKey(int no) const { int count = 0; for (unsigned i = 0; i < m_impl.m_columns.size(); i++) { if (m_impl.m_columns[i]->m_pk) { if (count++ == no) return m_impl.m_columns[i]->m_name.c_str(); } } return 0;}const void* NdbDictionary::Table::getFrmData() const { return m_impl.m_frm.get_data();}Uint32NdbDictionary::Table::getFrmLength() const { return m_impl.m_frm.length();}voidNdbDictionary::Table::setFrm(const void* data, Uint32 len){ m_impl.m_frm.assign(data, len);}NdbDictionary::Object::StatusNdbDictionary::Table::getObjectStatus() const { return m_impl.m_status;}int NdbDictionary::Table::getObjectVersion() const { return m_impl.m_version;}boolNdbDictionary::Table::equal(const NdbDictionary::Table & col) const { return m_impl.equal(col.m_impl);}intNdbDictionary::Table::getRowSizeInBytes() const { int sz = 0; for(int i = 0; i<getNoOfColumns(); i++){ const NdbDictionary::Column * c = getColumn(i); sz += (c->getSizeInBytes()+ 3) / 4; } return sz * 4;}intNdbDictionary::Table::getReplicaCount() const { return m_impl.m_replicaCount;}intNdbDictionary::Table::createTableInDb(Ndb* pNdb, bool equalOk) const { const NdbDictionary::Table * pTab = pNdb->getDictionary()->getTable(getName()); if(pTab != 0 && equal(* pTab)) return 0; if(pTab != 0 && !equal(* pTab)) return -1; return pNdb->getDictionary()->createTable(* this);}/***************************************************************** * Index facade */NdbDictionary::Index::Index(const char * name) : m_impl(* new NdbIndexImpl(* this)){ setName(name);}NdbDictionary::Index::Index(NdbIndexImpl & impl) : m_impl(impl) {}NdbDictionary::Index::~Index(){ NdbIndexImpl * tmp = &m_impl; if(this != tmp){ delete tmp; }}void NdbDictionary::Index::setName(const char * name){ m_impl.setName(name);}const char * NdbDictionary::Index::getName() const { return m_impl.getName();}void NdbDictionary::Index::setTable(const char * table){ m_impl.setTable(table);}const char * NdbDictionary::Index::getTable() const { return m_impl.getTable();}unsignedNdbDictionary::Index::getNoOfColumns() const { return m_impl.m_columns.size();}intNdbDictionary::Index::getNoOfIndexColumns() const { return m_impl.m_columns.size();}const NdbDictionary::Column *NdbDictionary::Index::getColumn(unsigned no) const { if(no < m_impl.m_columns.size()) return m_impl.m_columns[no]; return NULL;}const char *NdbDictionary::Index::getIndexColumn(int no) const { const NdbDictionary::Column* col = getColumn(no); if (col) return col->getName(); else return NULL;}voidNdbDictionary::Index::addColumn(const Column & c){ NdbColumnImpl* col = new NdbColumnImpl; (* col) = NdbColumnImpl::getImpl(c); m_impl.m_columns.push_back(col);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -