libf 5 місяців тому
батько
коміт
80074b20f6
4 змінених файлів з 85 додано та 59 видалено
  1. 1 1
      importer/importer.go
  2. 38 29
      importer/odbcimporter.go
  3. 46 0
      odbc/cfg.go
  4. 0 29
      odbc/odbclient.go

+ 1 - 1
importer/importer.go

@@ -126,7 +126,7 @@ func (importer *Importer) Import() (totalfilescount, totalrecordscount int64, to
 	}
 	cgistatus := NewCGIStatus()
 	reload := mcfg.GetString("reload")
-	if false && reload == "" {
+	if odbc.DevPhase&odbc.DP_PROCESSCONTINUE != 0 && reload == "" {
 		e = cgistatus.Load()
 		if e != nil {
 			err = e

+ 38 - 29
importer/odbcimporter.go

@@ -39,10 +39,13 @@ type ODBCImporter struct {
 }
 
 func NewODBCImporter() *ODBCImporter {
-	return &ODBCImporter{
-		client:     odbc.ODBC(),
+	odbci := &ODBCImporter{
 		classinfos: cmap.New[string, *classinfo](),
 	}
+	if odbc.DevPhase&(odbc.DP_CREATECLASS|odbc.DP_INSERTDATA) != 0 {
+		odbci.client = odbc.ODBC()
+	}
+	return odbci
 }
 
 // 根据数据修正类定义
@@ -112,9 +115,11 @@ func (odbci *ODBCImporter) InsertData(classname string, data map[string]any) (er
 
 		values = append(values, v)
 	}
-	_, err = odbci.client.Query(ci.insertmql, values...).Do()
-	if err != nil {
-		return
+	if odbci.client != nil {
+		_, err = odbci.client.Query(ci.insertmql, values...).Do()
+		if err != nil {
+			return
+		}
 	}
 	atomic.AddInt64(&ci.insertcount, 1)
 	ci.mutex.Lock()
@@ -154,27 +159,29 @@ func (odbci *ODBCImporter) alldone() {
 }
 
 func (odbci *ODBCImporter) reload() error {
-	_, e := odbci.client.Query(`delete from "/cgitest/x10/x1001" with version`).Do()
-	_ = e
-	_, e = odbci.client.Query(`delete from "/cgitest/x10/x1002" with version`).Do()
-	_ = e
-	_, e = odbci.client.Query(`delete from "/cgitest/x10/x1003" with version`).Do()
-	_ = e
-	_, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1001"`).Do()
-	if e != nil {
-		return e
-	}
-	_, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1002"`).Do()
-	if e != nil {
-		return e
-	}
-	_, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1003"`).Do()
-	if e != nil {
-		return e
-	}
-	_, e = odbci.client.Query(`drop class if exists "/cgitest/x10"`).Do()
-	if e != nil {
-		return e
+	if odbci.client != nil {
+		_, e := odbci.client.Query(`delete from "/cgitest/x10/x1001" with version`).Do()
+		_ = e
+		_, e = odbci.client.Query(`delete from "/cgitest/x10/x1002" with version`).Do()
+		_ = e
+		_, e = odbci.client.Query(`delete from "/cgitest/x10/x1003" with version`).Do()
+		_ = e
+		_, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1001"`).Do()
+		if e != nil {
+			return e
+		}
+		_, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1002"`).Do()
+		if e != nil {
+			return e
+		}
+		_, e = odbci.client.Query(`drop class if exists "/cgitest/x10/x1003"`).Do()
+		if e != nil {
+			return e
+		}
+		_, e = odbci.client.Query(`drop class if exists "/cgitest/x10"`).Do()
+		if e != nil {
+			return e
+		}
 	}
 	return nil
 }
@@ -206,9 +213,11 @@ func (odbci *ODBCImporter) createClass(nickname, classname string, fieldinfoslis
 			mql += ", keys(" + strings.Join(keyfields, ",") + ")"
 		}
 		mql += `)with namespace="cgitest" and key=manu and nickname='` + nickname + `'`
-		_, err = odbci.client.Query(mql).Do()
-		if err != nil {
-			return
+		if odbci.client != nil {
+			_, err = odbci.client.Query(mql).Do()
+			if err != nil {
+				return
+			}
 		}
 		var insertmql string
 		if len(fieldslist) > 0 {

+ 46 - 0
odbc/cfg.go

@@ -0,0 +1,46 @@
+package odbc
+
+import (
+	"fmt"
+	"path/filepath"
+
+	ucfg "git.wecise.com/wecise/util/cfg"
+	ulog "git.wecise.com/wecise/util/logger"
+)
+
+var DefaultAppName = "cgimport"
+var Config = ucfg.MConfig(&ucfg.CfgOption{
+	Name: "m:default",
+	Type: ucfg.INI_TEXT,
+	Values: []string{`
+[log]
+level=debug
+dir=` + filepath.Join("/", "opt", "matrix", "var", "logs") + `
+file=` + DefaultAppName + ".log" + `
+console=true
+color=true
+consolelevel=info
+format=yyyy-MM-dd HH:mm:ss.SSSSSS [pid] [level] module/file:line msg
+eol=\n
+size=10MB
+count=100
+scroll=1d
+expire=14d
+`}},
+	ucfg.GetIniFileCfgOption(filepath.Join(fmt.Sprint(DefaultAppName, ".conf"))),
+	ucfg.CFGOPTION_ENVS,
+	ucfg.CFGOPTION_ARGS)
+
+var Logger = ulog.New().WithConfig(Config, "log")
+var LogFile = Logger.FileOutPath()
+var LogDebug = Logger.FileOutLevel() <= ulog.DEBUG
+
+const (
+	DP_READFILE = 1 << iota
+	DP_PROCESSCONTINUE
+	DP_PARSESTRUCT
+	DP_CREATECLASS
+	DP_INSERTDATA
+)
+
+var DevPhase = DP_READFILE | DP_PARSESTRUCT

+ 0 - 29
odbc/odbclient.go

@@ -3,42 +3,13 @@ package odbc
 import (
 	"fmt"
 	"os"
-	"path/filepath"
 	"strings"
 
 	odb "git.wecise.com/wecise/odb-go/odb"
 	ucfg "git.wecise.com/wecise/util/cfg"
-	ulog "git.wecise.com/wecise/util/logger"
 	"github.com/scylladb/go-set/strset"
 )
 
-var DefaultAppName = "cgimport"
-var Config = ucfg.MConfig(&ucfg.CfgOption{
-	Name: "m:default",
-	Type: ucfg.INI_TEXT,
-	Values: []string{`
-[log]
-level=debug
-dir=` + filepath.Join("/", "opt", "matrix", "var", "logs") + `
-file=` + DefaultAppName + ".log" + `
-console=true
-color=true
-consolelevel=info
-format=yyyy-MM-dd HH:mm:ss.SSSSSS [pid] [level] module/file:line msg
-eol=\n
-size=10MB
-count=100
-scroll=1d
-expire=14d
-`}},
-	ucfg.GetIniFileCfgOption(filepath.Join(fmt.Sprint(DefaultAppName, ".conf"))),
-	ucfg.CFGOPTION_ENVS,
-	ucfg.CFGOPTION_ARGS)
-
-var Logger = ulog.New().WithConfig(Config, "log")
-var LogFile = Logger.FileOutPath()
-var LogDebug = Logger.FileOutLevel() <= ulog.DEBUG
-
 var ODBClient odb.Client
 var ODBError error
 var Debug bool