Skip to content

Commit

Permalink
Removed old support for primary keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonask committed Oct 6, 2015
1 parent f747018 commit 19650c8
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 529 deletions.
6 changes: 0 additions & 6 deletions src/realm/exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ const char* LogicError::what() const noexcept
return "Detached accessor";
case no_search_index:
return "Column has no search index";
case no_primary_key:
return "Table has no primary key";
case is_primary_key:
return "Column is the primary key of the table";
case has_primary_key:
return "Primary key already added";
case unique_constraint_violation:
return "Unique constraint violation";
case column_not_nullable:
Expand Down
11 changes: 0 additions & 11 deletions src/realm/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,6 @@ class LogicError: public std::exception {
// Indicates that an involved column lacks a search index.
no_search_index,

// Indicates that an involved table lacks a primary key.
no_primary_key,

// Indicates that an attempt was made to add a primary key to a table that
// already had a primary key.
has_primary_key,

/// Indicates that a modification to a column was attempted that cannot
/// be done because the column is the primary key of the table.
is_primary_key,

/// Indicates that a modification was attempted that would have produced a
/// duplicate primary value.
unique_constraint_violation,
Expand Down
55 changes: 0 additions & 55 deletions src/realm/impl/transact_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ enum Instruction {
instr_RenameColumn = 27, // Rename column in selected descriptor
instr_AddSearchIndex = 28, // Add a search index to a column
instr_RemoveSearchIndex = 29, // Remove a search index from a column
instr_AddPrimaryKey = 30, // Add a primary key to a table
instr_RemovePrimaryKey = 31, // Remove primary key from a table
instr_SetLinkType = 32, // Strong/weak
instr_SelectLinkList = 33,
instr_LinkListSet = 34, // Assign to link list entry
Expand Down Expand Up @@ -160,8 +158,6 @@ class NullInstructionObserver {
bool rename_column(std::size_t, StringData) { return true; }
bool add_search_index(std::size_t) { return true; }
bool remove_search_index(std::size_t) { return true; }
bool add_primary_key(std::size_t) { return true; }
bool remove_primary_key() { return true; }
bool set_link_type(std::size_t, LinkType) { return true; }

// Must have linklist selected:
Expand Down Expand Up @@ -220,8 +216,6 @@ class TransactLogEncoder {
bool rename_column(std::size_t col_ndx, StringData new_name);
bool add_search_index(std::size_t col_ndx);
bool remove_search_index(std::size_t col_ndx);
bool add_primary_key(std::size_t col_ndx);
bool remove_primary_key();
bool set_link_type(std::size_t col_ndx, LinkType);

// Must have linklist selected:
Expand Down Expand Up @@ -324,8 +318,6 @@ class TransactLogConvenientEncoder {

void add_search_index(const Table*, std::size_t col_ndx);
void remove_search_index(const Table*, std::size_t col_ndx);
void add_primary_key(const Table*, std::size_t col_ndx);
void remove_primary_key(const Table*);
void set_link_type(const Table*, std::size_t col_ndx, LinkType);
void clear_table(const Table*);
void optimize_table(const Table*);
Expand Down Expand Up @@ -1112,32 +1104,6 @@ inline void TransactLogConvenientEncoder::remove_search_index(const Table* t, st
}


inline bool TransactLogEncoder::add_primary_key(std::size_t col_ndx)
{
simple_cmd(instr_AddPrimaryKey, util::tuple(col_ndx)); // Throws
return true;
}

inline void TransactLogConvenientEncoder::add_primary_key(const Table* t, std::size_t col_ndx)
{
select_table(t); // Throws
m_encoder.add_primary_key(col_ndx); // Throws
}


inline bool TransactLogEncoder::remove_primary_key()
{
simple_cmd(instr_RemovePrimaryKey, util::tuple()); // Throws
return true;
}

inline void TransactLogConvenientEncoder::remove_primary_key(const Table* t)
{
select_table(t); // Throws
m_encoder.remove_primary_key(); // Throws
}


inline bool TransactLogEncoder::set_link_type(std::size_t col_ndx, LinkType link_type)
{
simple_cmd(instr_SetLinkType, util::tuple(col_ndx, int(link_type))); // Throws
Expand Down Expand Up @@ -1563,17 +1529,6 @@ void TransactLogParser::parse_one(InstructionHandler& handler)
parser_error();
return;
}
case instr_AddPrimaryKey: {
std::size_t col_ndx = read_int<std::size_t>(); // Throws
if (!handler.add_primary_key(col_ndx)) // Throws
parser_error();
return;
}
case instr_RemovePrimaryKey: {
if (!handler.remove_primary_key()) // Throws
parser_error();
return;
}
case instr_SetLinkType: {
std::size_t col_ndx = read_int<std::size_t>(); // Throws
int link_type = read_int<int>(); // Throws
Expand Down Expand Up @@ -2046,16 +2001,6 @@ class TransactReverser {
return true; // No-op
}

bool add_primary_key(size_t)
{
return true; // No-op
}

bool remove_primary_key()
{
return true; // No-op
}

bool set_link_type(size_t, LinkType)
{
return true; // No-op
Expand Down
34 changes: 0 additions & 34 deletions src/realm/replication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,40 +329,6 @@ class Replication::TransactLogApplier {
return false;
}

bool add_primary_key(size_t col_ndx)
{
if (REALM_LIKELY(m_table)) {
if (REALM_LIKELY(!m_table->has_shared_type())) {
if (REALM_LIKELY(col_ndx < m_table->get_column_count())) {
#ifdef REALM_DEBUG
if (m_log)
*m_log << "table->add_primary_key("<<col_ndx<<")\n";
#endif
// Fails if there are duplicate values, but given valid
// transaction logs, there never will be.
bool success = m_table->try_add_primary_key(col_ndx); // Throws
return success;
}
}
}
return false;
}

bool remove_primary_key()
{
if (REALM_LIKELY(m_table)) {
if (REALM_LIKELY(!m_table->has_shared_type())) {
#ifdef REALM_DEBUG
if (m_log)
*m_log << "table->remove_primary_key()\n";
#endif
m_table->remove_primary_key(); // Throws
return true;
}
}
return false;
}

bool set_link_type(size_t col_ndx, LinkType link_type)
{
if (REALM_LIKELY(m_table)) {
Expand Down
Loading

0 comments on commit 19650c8

Please sign in to comment.