public void AggiungiSequenza(PersisterMapper <Sequenza> sequenza) { string nomeFile = _base + sequenza.Element.Nome + "_" + Documento.getInstance().ModelloRiferimento.ToString() + ".seq"; if (sequenza.ID >= 0 && sequenza.ID < _sequenze.Count) { _sequenze.RemoveAt(sequenza.ID); _sequenze.Insert(sequenza.ID, sequenza.Element); } else { if (!Overwrite(nomeFile)) { return; } _sequenze.Add(sequenza.Element); } using (BinaryWriter bw = new BinaryWriter(new FileStream(nomeFile, FileMode.Create))) { PersisterFactory.GetPersister(PersisterFactory.SEQUENZA).Save(sequenza.Element, bw); } LibreriaChange?.Invoke(this, EventArgs.Empty); }
public void AggiungiProgrGiornaliera(PersisterMapper <ProgrammazioneGiornaliera> progrGiornaliera) { string nomeFile = _base + progrGiornaliera.Element.Nome + "_" + Documento.getInstance().ModelloRiferimento.ToString() + ".prg"; if (progrGiornaliera.ID >= 0 && progrGiornaliera.ID < _progrGiornaliere.Count) { _progrGiornaliere.RemoveAt(progrGiornaliera.ID); _progrGiornaliere.Insert(progrGiornaliera.ID, progrGiornaliera.Element); } else { if (!Overwrite(nomeFile)) { return; } _progrGiornaliere.Add(progrGiornaliera.Element); } using (BinaryWriter bw = new BinaryWriter(new FileStream(nomeFile, FileMode.Create))) { PersisterFactory.GetPersister(progrGiornaliera.Element.GetType()).Save(progrGiornaliera.Element, bw); } LibreriaChange?.Invoke(this, EventArgs.Empty); }
static void Main(string[] args) { EventPersister ep = PersisterFactory.CreatePersister(); //ep.Connect("USER", "_SYSTEM", "SYS"); ep.Connect("localhost", 1972, "USER", "_SYSTEM", "SYS"); Object returnvalue = ep.CallClassMethod("%SYSTEM.Version", "GetVersion"); Console.Write("ReturnValue = " + returnvalue.ToString()); ep.Close(); }
public void AggiungiElemento(PersisterMapper <Elemento> elemento) { string nomeFile = _base + elemento.Element.Nome + "_" + Documento.getInstance().ModelloRiferimento.ToString() + ".elem"; if (elemento.ID < 0 && !Overwrite(nomeFile)) { return; } InsideAggiungiElemento(elemento); using (BinaryWriter bw = new BinaryWriter(new FileStream(nomeFile, FileMode.Create))) { PersisterFactory.GetPersister(elemento.Element.GetType()).Save(elemento.Element, bw); } }
static void Main(String[] args) { // If you are using a remote instance, update IP and password here String user = "******"; String password = "******"; String IP = "localhost"; int port = 51773; try { // Connect to database using EventPersister, which is based on IRISDataSource // For more details on EventPersister, visit // https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=BNETXEP_xep EventPersister xepPersister = PersisterFactory.CreatePersister(); xepPersister.Connect(IP, port, "User", user, password); Console.WriteLine("Connected to InterSystems IRIS"); xepPersister.DeleteExtent("Demo.Airport"); // Remove old test data xepPersister.ImportSchemaFull("Demo.Airport"); // Import flat schema // Create XEP Event for object access Event xepEvent = xepPersister.GetEvent("Demo.Airport"); // Create IRIS Native object IRISADOConnection connection = (IRISADOConnection)xepPersister.GetAdoNetConnection(); IRIS irisNative = IRIS.CreateIRIS(connection); Console.WriteLine("Generating airport table..."); // Populate 5 airport objects and save to the database using XEP populateAirports(xepEvent); // Get all airports using ADO.NET getAirports(connection); // Store natively - Uncomment the following line for task 3 // StoreAirfare(irisNative); Console.ReadLine(); // Close everything xepEvent.Close(); xepPersister.Close(); } catch (Exception e) { Console.WriteLine("Error creating airport listing: " + e); } }
static void Main(string[] args) { JsonObject jso = new JsonObject(); jso.Add("Grade", 1); jso.Add("Class", 2); jso.Add("Name", "クライアントさん"); JsonObject otherJO1 = new JsonObject(); otherJO1.Add("Subject", "数学"); otherJO1.Add("Score", 64); JsonObject otherJO2 = new JsonObject(); otherJO2.Add("Subject", "理科"); otherJO2.Add("Score", 70); JsonObject otherJO3 = new JsonObject(); otherJO3.Add("Subject", "英語"); otherJO3.Add("Score", 80); // Json array JsonArray ja = new JsonArray(); ja.Add(otherJO1); ja.Add(otherJO2); ja.Add(otherJO3); jso.Add("Results", ja); Console.WriteLine(jso.ToString()); EventPersister ep = PersisterFactory.CreatePersister(); ep.Connect("USER", "_SYSTEM", "SYS"); //ep.Connect("localhost",1972,"USER", "_SYSTEM", "SYS"); Object returnvalue = ep.CallClassMethod("REST.JSON", "SendJSON", jso.ToString()); ep.Close(); }
static void Main(string[] args) { String ip = "localhost"; int port = 51773; String username = "******"; String password = "******"; String Namespace = "USER"; String className = "myApp.StockInfo"; try { // Connect to database using EventPersister EventPersister xepPersister = PersisterFactory.CreatePersister(); xepPersister.Connect(ip, port, Namespace, username, password); Console.WriteLine("Connected to InterSystems IRIS."); xepPersister.DeleteExtent(className); // remove old test data xepPersister.ImportSchema(className); // import flat schema // Create Event Event xepEvent = xepPersister.GetEvent(className); IRISADOConnection connection = (IRISADOConnection) xepPersister.GetAdoNetConnection(); IRIS native = IRIS.CreateIRIS(connection); // Task 2 // Uncomment the line below to run task 2 // Task2(connection); // Task 3 // Uncomment the line below to run task 3 // Task3(connection, xepEvent); // Task 4 // Comment out Task 2, Task 3 and uncomment the line below to run task 4 // Task4(connection, native, xepEvent); xepEvent.Close(); xepPersister.Close(); } catch (Exception e) { Console.WriteLine("Interactive prompt failed:\n" + e); } }
private void ReadSingle(string fileName) { using (BinaryReader br = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read))) { IPersister persister = PersisterFactory.GetPersister(br.ReadString()); object result = persister.Retrieve(br); if (null != result as Sequenza) { _sequenze.Add((Sequenza)result); } else if (null != result as ProgrammazioneGiornaliera) { _progrGiornaliere.Add((ProgrammazioneGiornaliera)result); } else { InsideAggiungiElemento(new PersisterMapper <Elemento>((Elemento)result)); } } }
public SessionFactoryImpl(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) { Init(); log.Info("building session factory"); properties = new Dictionary <string, string>(cfg.Properties); interceptor = cfg.Interceptor; this.settings = settings; sqlFunctionRegistry = new SQLFunctionRegistry(settings.Dialect, cfg.SqlFunctions); eventListeners = listeners; filters = new Dictionary <string, FilterDefinition>(cfg.FilterDefinitions); if (log.IsDebugEnabled) { log.Debug("Session factory constructed with filter configurations : " + CollectionPrinter.ToString(filters)); } if (log.IsDebugEnabled) { log.Debug("instantiating session factory with properties: " + CollectionPrinter.ToString(properties)); } try { if (settings.IsKeywordsImportEnabled) { SchemaMetadataUpdater.Update(this); } if (settings.IsAutoQuoteEnabled) { SchemaMetadataUpdater.QuoteTableAndColumns(cfg); } } catch (NotSupportedException) { // Ignore if the Dialect does not provide DataBaseSchema } #region Caches settings.CacheProvider.Start(properties); #endregion #region Generators identifierGenerators = new Dictionary <string, IIdentifierGenerator>(); foreach (PersistentClass model in cfg.ClassMappings) { if (!model.IsInherited) { IIdentifierGenerator generator = model.Identifier.CreateIdentifierGenerator(settings.Dialect, settings.DefaultCatalogName, settings.DefaultSchemaName, (RootClass)model); identifierGenerators[model.EntityName] = generator; } } #endregion #region Persisters Dictionary <string, ICacheConcurrencyStrategy> caches = new Dictionary <string, ICacheConcurrencyStrategy>(); entityPersisters = new Dictionary <string, IEntityPersister>(); implementorToEntityName = new Dictionary <System.Type, string>(); Dictionary <string, IClassMetadata> classMeta = new Dictionary <string, IClassMetadata>(); foreach (PersistentClass model in cfg.ClassMappings) { model.PrepareTemporaryTables(mapping, settings.Dialect); string cacheRegion = model.RootClazz.CacheRegionName; ICacheConcurrencyStrategy cache; if (!caches.TryGetValue(cacheRegion, out cache)) { cache = CacheFactory.CreateCache(model.CacheConcurrencyStrategy, cacheRegion, model.IsMutable, settings, properties); if (cache != null) { caches.Add(cacheRegion, cache); allCacheRegions.Add(cache.RegionName, cache.Cache); } } IEntityPersister cp = PersisterFactory.CreateClassPersister(model, cache, this, mapping); entityPersisters[model.EntityName] = cp; classMeta[model.EntityName] = cp.ClassMetadata; if (model.HasPocoRepresentation) { implementorToEntityName[model.MappedClass] = model.EntityName; } } classMetadata = new UnmodifiableDictionary <string, IClassMetadata>(classMeta); Dictionary <string, ISet <string> > tmpEntityToCollectionRoleMap = new Dictionary <string, ISet <string> >(); collectionPersisters = new Dictionary <string, ICollectionPersister>(); foreach (Mapping.Collection model in cfg.CollectionMappings) { ICacheConcurrencyStrategy cache = CacheFactory.CreateCache(model.CacheConcurrencyStrategy, model.CacheRegionName, model.Owner.IsMutable, settings, properties); if (cache != null) { allCacheRegions[cache.RegionName] = cache.Cache; } ICollectionPersister persister = PersisterFactory.CreateCollectionPersister(cfg, model, cache, this); collectionPersisters[model.Role] = persister; IType indexType = persister.IndexType; if (indexType != null && indexType.IsAssociationType && !indexType.IsAnyType) { string entityName = ((IAssociationType)indexType).GetAssociatedEntityName(this); ISet <string> roles; if (!tmpEntityToCollectionRoleMap.TryGetValue(entityName, out roles)) { roles = new HashSet <string>(); tmpEntityToCollectionRoleMap[entityName] = roles; } roles.Add(persister.Role); } IType elementType = persister.ElementType; if (elementType.IsAssociationType && !elementType.IsAnyType) { string entityName = ((IAssociationType)elementType).GetAssociatedEntityName(this); ISet <string> roles; if (!tmpEntityToCollectionRoleMap.TryGetValue(entityName, out roles)) { roles = new HashSet <string>(); tmpEntityToCollectionRoleMap[entityName] = roles; } roles.Add(persister.Role); } } Dictionary <string, ICollectionMetadata> tmpcollectionMetadata = new Dictionary <string, ICollectionMetadata>(collectionPersisters.Count); foreach (KeyValuePair <string, ICollectionPersister> collectionPersister in collectionPersisters) { tmpcollectionMetadata.Add(collectionPersister.Key, collectionPersister.Value.CollectionMetadata); } collectionMetadata = new UnmodifiableDictionary <string, ICollectionMetadata>(tmpcollectionMetadata); collectionRolesByEntityParticipant = new UnmodifiableDictionary <string, ISet <string> >(tmpEntityToCollectionRoleMap); #endregion #region Named Queries namedQueries = new Dictionary <string, NamedQueryDefinition>(cfg.NamedQueries); namedSqlQueries = new Dictionary <string, NamedSQLQueryDefinition>(cfg.NamedSQLQueries); sqlResultSetMappings = new Dictionary <string, ResultSetMappingDefinition>(cfg.SqlResultSetMappings); #endregion imports = new Dictionary <string, string>(cfg.Imports); #region after *all* persisters and named queries are registered foreach (IEntityPersister persister in entityPersisters.Values) { persister.PostInstantiate(); } foreach (ICollectionPersister persister in collectionPersisters.Values) { persister.PostInstantiate(); } #endregion #region Serialization info name = settings.SessionFactoryName; try { uuid = (string)UuidGenerator.Generate(null, null); } catch (Exception) { throw new AssertionFailure("Could not generate UUID"); } SessionFactoryObjectFactory.AddInstance(uuid, name, this, properties); #endregion log.Debug("Instantiated session factory"); #region Schema management if (settings.IsAutoCreateSchema) { new SchemaExport(cfg).Create(false, true); } if (settings.IsAutoUpdateSchema) { new SchemaUpdate(cfg).Execute(false, true); } if (settings.IsAutoValidateSchema) { new SchemaValidator(cfg, settings).Validate(); } if (settings.IsAutoDropSchema) { schemaExport = new SchemaExport(cfg); } #endregion #region Obtaining TransactionManager // not ported yet #endregion currentSessionContext = BuildCurrentSessionContext(); if (settings.IsQueryCacheEnabled) { updateTimestampsCache = new UpdateTimestampsCache(settings, properties); queryCache = settings.QueryCacheFactory.GetQueryCache(null, updateTimestampsCache, settings, properties); queryCaches = new ThreadSafeDictionary <string, IQueryCache>(new Dictionary <string, IQueryCache>()); } else { updateTimestampsCache = null; queryCache = null; queryCaches = null; } #region Checking for named queries if (settings.IsNamedQueryStartupCheckingEnabled) { IDictionary <string, HibernateException> errors = CheckNamedQueries(); if (errors.Count > 0) { StringBuilder failingQueries = new StringBuilder("Errors in named queries: "); foreach (KeyValuePair <string, HibernateException> pair in errors) { failingQueries.Append('{').Append(pair.Key).Append('}'); log.Error("Error in named query: " + pair.Key, pair.Value); } throw new HibernateException(failingQueries.ToString()); } } #endregion Statistics.IsStatisticsEnabled = settings.IsStatisticsEnabled; // EntityNotFoundDelegate IEntityNotFoundDelegate enfd = cfg.EntityNotFoundDelegate; if (enfd == null) { enfd = new DefaultEntityNotFoundDelegate(); } entityNotFoundDelegate = enfd; }
/// <summary> /// /// </summary> /// <param name="cfg"></param> /// <param name="settings"></param> public SessionFactoryImpl(Configuration cfg, Settings settings) { log.Info("building session factory"); this.properties = cfg.Properties; this.interceptor = cfg.Interceptor; this.settings = settings; if (log.IsDebugEnabled) { log.Debug("instantiating session factory with properties: " + CollectionPrinter.ToString(properties)); } // Persisters: classPersisters = new Hashtable(); classPersistersByName = new Hashtable(); IDictionary classMeta = new Hashtable(); foreach (PersistentClass model in cfg.ClassMappings) { IClassPersister cp = PersisterFactory.CreateClassPersister(model, this); classPersisters[model.MappedClass] = cp; // Adds the "Namespace.ClassName" (FullClassname) as a lookup to get to the Persiter. // Most of the internals of NHibernate use this method to get to the Persister since // Model.Name is used in so many places. It would be nice to fix it up to be Model.TypeName // instead of just FullClassname classPersistersByName[model.Name] = cp; // Add in the AssemblyQualifiedName (includes version) as a lookup to get to the Persister. // In HQL the Imports are used to get from the Classname to the Persister. The // Imports provide the ability to jump from the Classname to the AssemblyQualifiedName. classPersistersByName[model.MappedClass.AssemblyQualifiedName] = cp; classMeta[model.MappedClass] = cp.ClassMetadata; } classMetadata = new Hashtable(classMeta); collectionPersisters = new Hashtable(); foreach (Mapping.Collection map in cfg.CollectionMappings) { collectionPersisters[map.Role] = PersisterFactory .CreateCollectionPersister(map, this) .CollectionMetadata; } collectionMetadata = new Hashtable(collectionPersisters); // after *all* persisters are registered foreach (IClassPersister persister in classPersisters.Values) { // TODO: H2.1 doesn't pass this to PostInstantiate persister.PostInstantiate(this); } //TODO: // For databinding: //templates = XMLDatabinder.GetOutputStyleSheetTemplates( properties ); // serialization info name = settings.SessionFactoryName; try { uuid = ( string )UuidGenerator.Generate(null, null); } catch (Exception) { throw new AssertionFailure("could not generate UUID"); } SessionFactoryObjectFactory.AddInstance(uuid, name, this, properties); // Named queries: // TODO: precompile and cache named queries namedQueries = new Hashtable(cfg.NamedQueries); namedSqlQueries = new Hashtable(cfg.NamedSQLQueries.Count); foreach (DictionaryEntry de in cfg.NamedSQLQueries) { NamedSQLQuery nsq = ( NamedSQLQuery )de.Value; namedSqlQueries[de.Key] = new InternalNamedSQLQuery(nsq.QueryString, nsq.ReturnAliases, nsq.ReturnClasses, nsq.SynchronizedTables); } imports = new Hashtable(cfg.Imports); log.Debug("Instantiated session factory"); if (settings.IsAutoCreateSchema) { new SchemaExport(cfg).Create(false, true); } /* * if ( settings.IsAutoUpdateSchema ) * { * new SchemaUpdate( cfg ).Execute( false, true ); * } */ if (settings.IsAutoDropSchema) { schemaExport = new SchemaExport(cfg); } // Obtaining TransactionManager - not ported from H2.1 if (settings.IsQueryCacheEnabled) { updateTimestampsCache = new UpdateTimestampsCache(settings.CacheProvider, properties); queryCache = settings.QueryCacheFactory .GetQueryCache(null, settings.CacheProvider, updateTimestampsCache, properties); queryCaches = Hashtable.Synchronized(new Hashtable()); } else { updateTimestampsCache = null; queryCache = null; queryCaches = null; } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Trade[] sampleArray = null; // Initialize dictionary to store connection details from config.txt IDictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary = generateConfig("..\\..\\..\\config.txt"); // Retrieve connection information from configuration file string ip = dictionary["ip"]; int port = Convert.ToInt32(dictionary["port"]); string Namespace = dictionary["namespace"]; string username = dictionary["username"]; string password = dictionary["password"]; String className = "myApp.Trade"; try { // Connect to database using EventPersister EventPersister xepPersister = PersisterFactory.CreatePersister(); xepPersister.Connect(ip, port, Namespace, username, password); Console.WriteLine("Connected to InterSystems IRIS."); xepPersister.DeleteExtent(className); // remove old test data xepPersister.ImportSchema(className); // import flat schema // Create Event Event xepEvent = xepPersister.GetEvent(className); // Starting interactive prompt bool always = true; while (always) { Console.WriteLine("1. Make a trade (do not save)"); Console.WriteLine("2. Confirm all trades"); Console.WriteLine("3. Generate and save multiple trades"); Console.WriteLine("4. Retrieve all trades; show execution statistics"); Console.WriteLine("5. ADO.NET Comparison - Create and save multiple trades"); Console.WriteLine("6. Update all trades; show execution statistics"); Console.WriteLine("7. Quit"); Console.WriteLine("What would you like to do? "); String option = Console.ReadLine(); switch (option) { // Task 2 case "1": sampleArray = Task2CreateTrade(sampleArray); break; case "2": Task2SaveTrade(sampleArray, xepEvent); sampleArray = null; break; // Task 3 case "3": Task3(sampleArray, xepEvent); break; // Task 5 case "4": Task5(xepEvent); break; // Task 4 case "5": Task4(sampleArray, xepPersister); break; // Task 6 case "6": Task6(xepEvent); break; case "7": Console.WriteLine("Exited."); always = false; break; default: Console.WriteLine("Invalid option. Try again!"); break; } } xepEvent.Close(); xepPersister.Close(); } catch (Exception e) { Console.WriteLine("Interactive prompt failed:\n" + e); } }
static void Main(string[] args) { Trade[] sampleArray = null; Console.WriteLine("Hello World!"); String ip = "localhost"; int port = 51773; String username = "******"; String password = "******"; String Namespace = "USER"; String className = "myApp.Trade"; try { // Connect to database using EventPersister EventPersister xepPersister = PersisterFactory.CreatePersister(); xepPersister.Connect(ip, port, Namespace, username, password); Console.WriteLine("Connected to InterSystems IRIS."); xepPersister.DeleteExtent(className); // Remove old test data xepPersister.ImportSchema(className); // Import flat schema // Create Event Event xepEvent = xepPersister.GetEvent(className); // Starting interactive prompt bool always = true; while (always) { Console.WriteLine("1. Make a trade (do not save)"); Console.WriteLine("2. Confirm all trades"); Console.WriteLine("3. Generate and save multiple trades"); Console.WriteLine("4. Retrieve all trades; show execution statistics"); Console.WriteLine("5. ADO.NET Comparison - Create and save multiple trades"); Console.WriteLine("6. Quit"); Console.WriteLine("What would you like to do? "); String option = Console.ReadLine(); switch (option) { // Task 2 case "1": // Uncomment below line to run Task 2 - Create Trade // sampleArray = Task2CreateTrade(sampleArray); break; case "2": // Uncomment below line to run Task 2 - Save Trade // Task2SaveTrade(sampleArray, xepEvent); sampleArray = null; break; // Task 3 case "3": // Uncomment below line to run Task 3 //Task3(sampleArray, xepEvent); break; // Task 5 + Task 6 case "4": // Uncomment below line to run Task 5 // Task5(xepEvent); // Uncomment below line to run Task 6 // Task6(xepEvent); break; // Task 4 case "5": // Uncomment below line to run Task 4 // Task4(sampleArray, xepPersister); break; case "6": Console.WriteLine("Exited."); always = false; break; default: Console.WriteLine("Invalid option. Try again!"); break; } } xepEvent.Close(); xepPersister.Close(); } catch (Exception e) { Console.WriteLine("Interactive prompt failed:\n" + e); } }
public void SetUp() { _persister = MockRepository.GenerateMock <IPersister>(); _factory = new PersisterFactory(_persister); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); // Initialize dictionary to store connection details from config.txt IDictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary = generateConfig("..\\..\\..\\config.txt"); // Retrieve connection information from configuration file string ip = dictionary["ip"]; int port = Convert.ToInt32(dictionary["port"]); string Namespace = dictionary["namespace"]; string username = dictionary["username"]; string password = dictionary["password"]; String className = "myApp.StockInfo"; try { // Connect to database using EventPersister EventPersister xepPersister = PersisterFactory.CreatePersister(); xepPersister.Connect(ip, port, Namespace, username, password); Console.WriteLine("Connected to InterSystems IRIS."); xepPersister.DeleteExtent(className); // Remove old test data xepPersister.ImportSchema(className); // Import flat schema // Create Event Event xepEvent = xepPersister.GetEvent(className); IRISADOConnection connection = (IRISADOConnection)xepPersister.GetAdoNetConnection(); IRIS native = IRIS.CreateIRIS(connection); // Starting interactive prompt bool always = true; while (always) { Console.WriteLine("1. Retrieve all stock names"); Console.WriteLine("2. Create objects"); Console.WriteLine("3. Populate properties"); Console.WriteLine("4. Quit"); Console.WriteLine("What would you like to do? "); String option = Console.ReadLine(); switch (option) { // Task 2 case "1": Task2(connection); break; // Task 3 case "2": Task3(connection, xepEvent); break; // Task 4 case "3": Task4(connection, native, xepEvent); break; case "4": Console.WriteLine("Exited."); always = false; break; default: Console.WriteLine("Invalid option. Try again!"); break; } } xepEvent.Close(); xepPersister.Close(); } catch (Exception e) { Console.WriteLine("Interactive prompt failed:\n" + e); } }