public DataMapperFactory(PropertyBag dataSource) { if (null != dataSource) { DataSource = new DataSource(dataSource); } }
private static PropertyBag BuildPropertyBag(IDataReader reader) { PropertyBag bag = new PropertyBag(); for (int i = 0; i < reader.FieldCount; ++i) { string name = reader.GetName(i); object value = reader[i]; bag[name] = value; } return bag; }
private static Dictionary<string, int> DetermineColumnWidth(PropertyBag row, int maxWidth) { Dictionary<string, int> colWidths = new Dictionary<string, int>(); foreach (var col in row.Keys) { string sValue = ValueFormatter.Format(row[col]); int keyWidth = col.Length; int valWidth = sValue.Length; int colWidth = 4 + Math.Max(keyWidth, valWidth); colWidth = Math.Min(colWidth, maxWidth); colWidths.Add(col, colWidth); } return colWidths; }
public object MapToObject(IEnumerable<IColumnData> rowData) { var instance = new PropertyBag(); foreach (var column in rowData) { var data = column.RawData != null ? column.ColumnSpec.Deserialize(column.RawData) : null; instance[column.ColumnSpec.Name] = data; } return instance; }
public void TestNull() { CassandraSharpConfig cassandraSharpConfig = new CassandraSharpConfig(); ClusterManager.Configure(cassandraSharpConfig); ClusterConfig clusterConfig = new ClusterConfig { Endpoints = new EndpointsConfig { Servers = new[] {"localhost"} } }; using (ICluster cluster = ClusterManager.GetCluster(clusterConfig)) { var cmd = cluster.CreatePropertyBagCommand(); const string dropFoo = "drop keyspace Tests"; try { cmd.Execute(dropFoo).AsFuture().Wait(); } catch { } const string createFoo = "CREATE KEYSPACE Tests WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}"; Console.WriteLine("============================================================"); Console.WriteLine(createFoo); Console.WriteLine("============================================================"); cmd.Execute(createFoo).AsFuture().Wait(); Console.WriteLine(); Console.WriteLine(); const string createBar = @"CREATE TABLE Tests.AllTypes (a int, b int, primary key (a))"; Console.WriteLine("============================================================"); Console.WriteLine(createBar); Console.WriteLine("============================================================"); cmd.Execute(createBar).AsFuture().Wait(); Console.WriteLine(); Console.WriteLine(); //const string useBar = @"use Tests"; //Console.WriteLine("============================================================"); //Console.WriteLine(useBar); //Console.WriteLine("============================================================"); //cmd.Execute(useBar).AsFuture().Wait(); //Console.WriteLine(); //Console.WriteLine(); const string insertBatch = @"insert into Tests.AllTypes (a, b) values (?, ?)"; var prepared = cmd.Prepare(insertBatch); PropertyBag insertBag = new PropertyBag(); insertBag["a"] = 1; insertBag["b"] = null; prepared.Execute(insertBag).AsFuture().Wait(); const string selectAll = "select * from Tests.AllTypes"; var res = cmd.Execute(selectAll).AsFuture(); Assert.IsTrue(1 == res.Result.Count); PropertyBag selectBag = res.Result.Single(); Assert.IsTrue(selectBag.Keys.Contains("a")); Assert.IsTrue(1 == (int) selectBag["a"]); Assert.IsTrue(null == selectBag["b"]); } }
public DataSource(PropertyBag dataSource) { _dataSource = dataSource; }
private static string BuildRowValues(PropertyBag row, IDictionary<string, int> colWidths, Func<string, object, string> formatter) { StringBuilder sbValues = new StringBuilder(); foreach (var col in row.Keys) { string sValue = formatter(col, row[col]); int colWidth = colWidths[col]; string colFormat = string.Format("{{0,-{0}}}", colWidth); string colValue = string.Format(colFormat, sValue); if (colWidth < colValue.Length) { colValue = colValue.Substring(0, colWidth - 1); colValue += "~"; } sbValues.Append("| ").Append(colValue).Append(" "); } sbValues.Append(" |"); string rowValues = sbValues.ToString(); return rowValues; }