public int PopulateStatement(PreparedStatement ps, int startPosition) { int rpos = pos + startPosition - 1; if (value == null) { ps.setNull(rpos, sqlType); return(1); } switch (sqlType) { case Types.VARCHAR: { ps.SetString(rpos, (String)value); break; } case Types.INTEGER: { ps.SetInt(rpos, ((int)value)); break; } case Types.DOUBLE: { ps.SetDouble(rpos, ((double)value)); break; } case Types.SMALLINT: { ps.setShort(rpos, ((short)value)); break; } case Types.TIME: { ps.SetTime(rpos, ((TimeSpan)value)); break; } case Types.TIMESTAMP: { ps.SetTimestamp(rpos, ((DateTime)value)); break; } case Types.BIGINT: { ps.SetLong(rpos, ((long)value)); break; } case Types.FLOAT: { ps.SetFloat(rpos, ((float)value)); break; } case Types.DATE: { ps.SetDate(rpos, ((DateTime)value)); break; } default: { throw new Exception("Unhandled sql type " + sqlType); } } return(1); }
/// <exception cref="Java.Sql.SQLException"/> public virtual void Write(PreparedStatement statement) { statement.SetString(1, url); statement.SetString(2, referrer); statement.SetLong(3, time); }
/// <exception cref="Java.Sql.SQLException"/> public virtual void Write(PreparedStatement statement) { statement.SetString(1, url); statement.SetLong(2, pageview); }
/// <summary>Populates the Access table with generated records.</summary> /// <exception cref="Java.Sql.SQLException"/> private void PopulateAccess() { PreparedStatement statement = null; try { statement = connection.PrepareStatement("INSERT INTO Access(url, referrer, time)" + " VALUES (?, ?, ?)"); Random random = new Random(); int time = random.Next(50) + 50; int ProbabilityPrecision = 100; // 1 / 100 int NewPageProbability = 15; // 15 / 100 //Pages in the site : string[] pages = new string[] { "/a", "/b", "/c", "/d", "/e", "/f", "/g", "/h", "/i" , "/j" }; //linkMatrix[i] is the array of pages(indexes) that page_i links to. int[][] linkMatrix = new int[][] { new int[] { 1, 5, 7 }, new int[] { 0, 7, 4, 6 } , new int[] { 0, 1, 7, 8 }, new int[] { 0, 2, 4, 6, 7, 9 }, new int[] { 0, 1 }, new int[] { 0, 3, 5, 9 }, new int[] { 0 }, new int[] { 0, 1, 3 }, new int[] { 0, 2, 6 }, new int[] { 0, 2, 6 } }; //a mini model of user browsing a la pagerank int currentPage = random.Next(pages.Length); string referrer = null; for (int i = 0; i < time; i++) { statement.SetString(1, pages[currentPage]); statement.SetString(2, referrer); statement.SetLong(3, i); statement.Execute(); int action = random.Next(ProbabilityPrecision); // go to a new page with probability // NEW_PAGE_PROBABILITY / PROBABILITY_PRECISION if (action < NewPageProbability) { currentPage = random.Next(pages.Length); // a random page referrer = null; } else { referrer = pages[currentPage]; action = random.Next(linkMatrix[currentPage].Length); currentPage = linkMatrix[currentPage][action]; } } connection.Commit(); } catch (SQLException ex) { connection.Rollback(); throw; } finally { if (statement != null) { statement.Close(); } } }