Example #1
0
// Returns GLOBAL_PERSISTOR. If GLOBAL_PERSISTOR is nil, a new persistor is created, set as GLOBAL_PERSISTOR and returned
func getPriceRulePersistorForType(persistorType string) *persistence.Persistor {
	url := configuration.MONGO_URL
	collection := configuration.MONGO_COLLECTION_PRICERULES
	switch persistorType {
	case TypePriceRules:
		collection = configuration.MONGO_COLLECTION_PRICERULES

	case TypePriceRulesVouchers:
		collection = configuration.MONGO_COLLECTION_PRICERULES_VOUCHERS

	case TypePriceRulesGroups:
		collection = configuration.MONGO_COLLECTION_PRICERULES_GROUPS

	default:
		panic("type " + persistorType + " does not exist")
	}

	if globalPriceRulePersistors[persistorType] == nil {
		p, err := persistence.NewPersistor(url, collection)
		if err != nil || p == nil {
			panic(errors.New("failed to create mongoDB order persistor: " + err.Error()))
		}
		if len(globalPriceRulePersistors) == 0 {
			globalPriceRulePersistors = make(map[string]*persistence.Persistor)
		}
		globalPriceRulePersistors[persistorType] = p
		return globalPriceRulePersistors[persistorType]
	}

	if url == globalPriceRulePersistors[persistorType].GetURL() && collection == globalPriceRulePersistors[persistorType].GetCollectionName() {
		return globalPriceRulePersistors[persistorType]
	}

	p, err := persistence.NewPersistor(url, collection)
	if err != nil || p == nil {
		panic(err)
	}
	globalPriceRulePersistors[persistorType] = p
	return globalPriceRulePersistors[persistorType]
}
Example #2
0
// Returns GLOBAL_PERSISTOR. If GLOBAL_PERSISTOR is nil, a new persistor is created, set as GLOBAL_PERSISTOR and returned
func GetCredentialsPersistor() *persistence.Persistor {
	url := configuration.MONGO_URL
	collection := configuration.MONGO_COLLECTION_CREDENTIALS
	if globalCredentialsPersistor == nil {
		p, err := persistence.NewPersistor(url, collection)
		if err != nil || p == nil {
			panic(errors.New("failed to create mongoDB order persistor: " + err.Error()))
		}
		globalCredentialsPersistor = p
		return globalCredentialsPersistor
	}

	if url == globalCredentialsPersistor.GetURL() && collection == globalCredentialsPersistor.GetCollectionName() {
		return globalCredentialsPersistor
	}

	p, err := persistence.NewPersistor(url, collection)
	if err != nil || p == nil {
		panic(err)
	}
	globalCredentialsPersistor = p
	return globalCredentialsPersistor
}
Example #3
0
// NewPersistor constructor
func NewPersistor(mongoURL string, collectionName string) (p *persistence.Persistor, err error) {
	return persistence.NewPersistor(mongoURL, collectionName)
}