Cache datatypes in dlgTable, so they don't have to be reloaded by dlgColumn, which...
authordpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Tue, 7 Jul 2009 13:27:01 +0000 (13:27 +0000)
committerdpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Tue, 7 Jul 2009 13:27:01 +0000 (13:27 +0000)
git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@7965 a7884b65-44f6-0310-8a51-81a127f17b15

CHANGELOG
pgadmin/dlg/dlgProperty.cpp
pgadmin/dlg/dlgTable.cpp
pgadmin/include/dlg/dlgProperty.h
pgadmin/include/dlg/dlgTable.h

index 348f75665986a3a8b84f9a1ed83da42421983712..93a7894915be25f633e23cc43c23ec5382b7f29d 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -36,6 +36,9 @@ Changes
 \r
 Date       Dev Ver     Change details\r
 ---------- --- ------  --------------\r
+2009-07-07 DP  1.12.0  Cache datatypes in dlgTable, so they don't have to be\r
+                       reloaded by dlgColumn, which may be used multiple times\r
+                       when creating a table [Sachin Srivastava].\r
 2009-07-01 DP  1.12.0  Use the STC instead of a rich text control in the edit\r
                        grid to prevent issues with control characters creeping\r
                        in on Windows [Sachin Srivastava].\r
index 7c05cd63edb5878d10af4ee4587e2044150797c9..87740b3b3790d61299f2bedba0d36e3c7dd25703 100644 (file)
@@ -70,6 +70,26 @@ public:
 };
 
 
+void dataType::SetOid(OID id)
+{
+    oid = id;
+}
+
+void dataType::SetTypename(wxString name)
+{
+    typeName = name;
+}
+
+OID dataType::GetOid()
+{
+   return oid;
+}
+
+wxString dataType::GetTypename()
+{
+   return typeName;
+}
+
 #define CTRLID_CHKSQLTEXTFIELD 1000
 
 
@@ -192,6 +212,10 @@ void dlgProperty::SetDatabase(pgDatabase *db)
         connection=db->GetConnection();
 }
 
+void dlgProperty::SetDatatypeCache(dataTypeCache cache)
+{
+   dtCache = cache;
+}
     
 void dlgProperty::EnableOK(bool enable)
 {
@@ -1189,20 +1213,39 @@ void dlgTypeProperty::FillDatatype(ctlComboBox *cb, bool withDomains)
     FillDatatype(cb, 0, withDomains);
 }
 
-
 void dlgTypeProperty::FillDatatype(ctlComboBox *cb, ctlComboBox *cb2, bool withDomains)
 {
-    DatatypeReader tr(database, withDomains);
-    while (tr.HasMore())
+     
+    if (dtCache.IsEmpty())
     {
-        pgDatatype dt=tr.GetDatatype();
+        // A column dialog is directly called, no datatype caching is done.
+        // Fetching datatypes from server. 
+        DatatypeReader tr(database, withDomains);
+        while (tr.HasMore())
+        {
+            pgDatatype dt=tr.GetDatatype();
 
-        AddType(wxT("?"), tr.GetOid(), dt.FullName());
-        cb->Append(dt.FullName());
-        if (cb2)
-            cb2->Append(dt.FullName());
-        tr.MoveNext();
+            AddType(wxT("?"), tr.GetOid(), dt.FullName());
+            cb->Append(dt.FullName());
+            if (cb2)
+                cb2->Append(dt.FullName());
+            tr.MoveNext();
+        }
     }
+    else
+    { 
+        // A column dialog is called from a table dialog where we have already cached the datatypes.  
+        // Using cached datatypes.
+        size_t i;
+        for (i = 0; i < dtCache.GetCount(); i++)
+        {
+            AddType(wxT("?"), dtCache.Item(i)->GetOid(), dtCache.Item(i)->GetTypename()); 
+            cb->Append(dtCache.Item(i)->GetTypename());
+            if (cb2)
+                cb2->Append(dtCache.Item(i)->GetTypename());
+        }
+    }
+
 }
 
 
index 85ed49b0d7850ac30f332515a9933b2327209075..ed2c4ed763bb3c1da9fed034ee8d806cf33c9b79 100644 (file)
@@ -31,7 +31,7 @@
 #include "schema/pgCheck.h"
 #include "schema/pgForeignKey.h"
 #include "schema/pgIndexConstraint.h"
-
+#include "schema/pgDatatype.h"
 
 
 #define stHasOids       CTRL_STATIC("stHasOids")
@@ -185,6 +185,13 @@ dlgTable::dlgTable(pgaFactory *f, frmMain *frame, pgTable *node, pgSchema *sch)
     lstConstraints->CreateColumns(0, _("Constraint name"), _("Definition"), 90);
 }
 
+dlgTable::~dlgTable()
+{
+    //Clear the cached datatypes
+    size_t i;
+    for (i = 0; i < dtCache.GetCount(); i++)
+        delete dtCache.Item(i);
+}
 
 pgObject *dlgTable::GetObject()
 {
@@ -199,6 +206,7 @@ int dlgTable::Go(bool modal)
     AddGroups();
     AddUsers(cbOwner);
     PrepareTablespace(cbTablespace);
+    PopulateDatatypeCache();
 
     hasPK=false;
 
@@ -1743,12 +1751,30 @@ void dlgTable::OnChangeCol(wxCommandEvent &ev)
     CheckChange();
 }
 
+// Cache datatypes to avoid multiple calls to server when adding multiple columns to a table. 
+void dlgTable::PopulateDatatypeCache()
+{
+    DatatypeReader tr(database, true);
+    while (tr.HasMore())
+    {
+        pgDatatype dt=tr.GetDatatype();
+
+        dataType *dType = new dataType();
+        dType->SetOid(tr.GetOid());
+        dType->SetTypename(dt.FullName());
+        dtCache.Add(dType);
+
+        tr.MoveNext();
+    }
+}
+
 
 void dlgTable::OnAddCol(wxCommandEvent &ev)
 {
     dlgColumn col(&columnFactory, mainForm, NULL, table);
     col.CenterOnParent();
     col.SetDatabase(database);
+    col.SetDatatypeCache(dtCache);   
     if (col.Go(true) != wxID_CANCEL)
     {
         long pos = lstColumns->AppendItem(columnFactory.GetIconId(), col.GetName(), col.GetDefinition());
index e6d96d908a64b74b75d2ffca65b4d1551b46fb40..0565128bf81228f271c1dbc3c910eadac41d724f 100644 (file)
@@ -15,6 +15,7 @@
 
 
 #include <wx/notebook.h>
+#include <wx/dynarray.h>
 #include "schema/pgObject.h"
 #include "db/pgConn.h"
 #include "ctl/ctlSecurityPanel.h"
@@ -29,6 +30,23 @@ class pgaFactory;
 #define lstColumns      CTRL_LISTVIEW("lstColumns")
 #define cbColumns       CTRL_COMBOBOX("cbColumns")
 
+class dataType
+{
+public:
+    void SetTypename(wxString name);
+    wxString GetTypename();
+    void SetOid(OID id);
+    OID GetOid();
+
+private:
+    wxString typeName;
+    OID      oid;
+       
+};
+
+WX_DEFINE_ARRAY(dataType *, dataTypeCache);
+
 class dlgProperty : public DialogWithHelp
 {
 public:
@@ -51,6 +69,7 @@ public:
     virtual wxString GetHelpPage(bool forCreate) const { return wxEmptyString; }
     void SetConnection(pgConn *conn) { connection=conn; }
     void SetDatabase(pgDatabase *db);
+    void SetDatatypeCache(dataTypeCache cache);
     virtual int Go(bool modal=false);
     virtual void CheckChange() =0;
 
@@ -120,6 +139,7 @@ protected:
     bool readOnly;
     bool processing;
     pgaFactory *factory;
+    dataTypeCache dtCache;
 
 private:
     bool tryUpdate(wxTreeItemId collectionItem);
index 2a785e8fa590a5e93a7dc477b17a04d8a480a76d..fe7bd03be245c149569b074cf147df111615f4db 100644 (file)
@@ -29,10 +29,12 @@ public:
     wxString GetSql();
     pgObject *CreateObject(pgCollection *collection);
     pgObject *GetObject();
+    ~dlgTable();
 
 private:
     pgSchema *schema;
     pgTable *table;
+    dataTypeCache dtCache;
 
     void OnOK(wxCommandEvent &ev);
     void OnChangeTable(wxCommandEvent &ev);
@@ -58,6 +60,7 @@ private:
     void FillConstraint();
     void FillAutoVacuumParameters(wxString& setString, wxString& resetStr,
                                  const wxString& parameter, const wxString& val);
+    void PopulateDatatypeCache();
     wxString GetItemConstraintType(ctlListView *list, long pos);
     bool hasPK;