Esempio n. 1
0
        public void PopulateStatement(PreparedStatement statement)
        {
            int size = parameters.Count;

            for (int i = 0; i < size; i++)
            {
                int      pos   = i + 1;
                SqlParam param = (SqlParam)parameters[pos];
                //TODO take into consideration null parameters
                switch (param.GetSqlType())
                {
                case Types.VARCHAR: {
                    statement.SetString(pos, (String)param.GetValue());
                    break;
                }

                case Types.DOUBLE: {
                    statement.SetDouble(pos, Convert.ToDouble(param.GetValue()));
                    break;
                }

                case Types.INTEGER: {
                    statement.SetInt(pos, Convert.ToInt32(param.GetValue()));
                    break;
                }

                case Types.DATE: {
                    statement.SetDate(pos, (DateTime)param.GetValue());
                    break;
                }

                case Types.TIME: {
                    statement.SetTime(pos, (TimeSpan)param.GetValue());
                    break;
                }

                case Types.TIMESTAMP: {
                    statement.SetTimestamp(pos, (DateTime)param.GetValue());
                    break;
                }

                default: {
                    throw new Exception("Unsupported param : " + param);
                }
                }
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 /// <exception cref="Java.Sql.SQLException"/>
 public virtual void Write(PreparedStatement statement)
 {
     statement.SetString(1, url);
     statement.SetString(2, referrer);
     statement.SetLong(3, time);
 }
Esempio n. 4
0
 /// <exception cref="Java.Sql.SQLException"/>
 public virtual void Write(PreparedStatement statement)
 {
     statement.SetString(1, url);
     statement.SetLong(2, pageview);
 }
Esempio n. 5
0
        /// <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();
                }
            }
        }