public function save(EntityInterface $entity)
 {
     $primaryKey = $this->getPrimaryKey();
     $data = $this->hydrator->extract($entity);
     if ($data[$primaryKey] != '' && $this->exists($data[$primaryKey])) {
         // update
         $this->db->update()->table('main_table', $this->getMainTable())->setAll($data)->where('main_table.' . $primaryKey . '=?', $data[$primaryKey])->run();
     } else {
         // insert
         $this->db->insert()->into($this->getMainTable())->addAll($data)->run();
         // last_insert id
         $data[$primaryKey] = $this->db->getLastInsertId();
         $this->hydrator->hydrate($data, $entity);
     }
     return true;
 }