Example #1
0
        public virtual long executeCommand(string commandSql)
        {
            DatabaseConnection sc = null;
            long result           = 0;

            try
            {
                Logger.log(Logger.Level.SQL, commandSql);

                sc = DatabaseConnectionPool.getConnectionPool().getConnection(domainObject.ConnectionName);
                OleDbCommand oledbCommand = new OleDbCommand();
                oledbCommand.Connection  = sc.Connection;
                oledbCommand.CommandType = CommandType.Text;
                oledbCommand.CommandText = commandSql;


                bindParameters(oledbCommand);

                result = (long)oledbCommand.ExecuteNonQuery();


                DatabaseConnectionPool.getConnectionPool().releaseConnection(sc);
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder();

                foreach (string p in parameters)
                {
                    string name = p;
                    object o    = domainObject[p];
                    string type = o.GetType().ToString();

                    string line = name + ":" + type + ">" + o.ToString() + "<\r\n";
                    sb.Append(line);
                }


                throw new PersistException(this, e, string.Format("OleDbPersist.executeCommand(): Error occurred while processing SQL {0}. \r\nParameter(s):\r\n", commandSql) + sb.ToString());
            }
            finally
            {
                if (sc != null)
                {
                    DatabaseConnectionPool.getConnectionPool().releaseConnection(sc);
                }

                parameters.Clear();
            }

            return(result);
        }
Example #2
0
 public static DatabaseConnectionPool getConnectionPool()
 {
     mutex.WaitOne();
     try
     {
         {
             if (!instanceFlag)
             {
                 connectionPool = new OleDbConnectionPool2();
                 instanceFlag   = true;
             }
         }
     }
     finally
     {
         mutex.ReleaseMutex();
     }
     return(connectionPool);
 }
Example #3
0
        public virtual DataSet executeQuery(string sqlQuery)
        {
            System.Data.DataSet dataSet = null;
            DatabaseConnection  sc      = null;

            try
            {
                Logger.log(Logger.Level.SQL, sqlQuery);

                sc = DatabaseConnectionPool.getConnectionPool().getConnection(domainObject.ConnectionName);

                System.Data.OleDb.OleDbDataAdapter queryAdapter = new OleDbDataAdapter(sqlQuery, sc.Connection);

                bindParameters(queryAdapter.SelectCommand);

                dataSet = new DataSet();
                queryAdapter.Fill(dataSet);
                queryAdapter.Dispose();

                DatabaseConnectionPool.getConnectionPool().releaseConnection(sc);
            }
            catch (Exception e)
            {
                //	throw new PersistException( this, e, string.Format("OleDbPersist.handleQuery(): Error occurred while processing sql {0}", sqlQuery ));
                Logger.log(this, e, e.Message);
                throw;
            }
            finally
            {
                if (sc != null)
                {
                    DatabaseConnectionPool.getConnectionPool().releaseConnection(sc);
                }
                parameters.Clear();
            }

            return(dataSet);
        }