Friday, May 6, 2011

Updating the db 6000 times will take few minutes ?

I am writing a test program with Ruby and ActiveRecord, and it reads a document which is like 6000 words long. And then I just tally up the words by

recordWord = Word.find_by_s(word);
if (recordWord.nil?)
  recordWord = Word.new
  recordWord.s = word
end
if recordWord.count.nil?
  recordWord.count = 1
else
  recordWord.count += 1
end
recordWord.save

and so this part loops for 6000 times... and it takes a few minutes to run at least using sqlite3. Is it normal? I was expecting it could run within a couple seconds... can MySQL speed it up a lot?

From stackoverflow
  • With 6000 calls to write to the database, you're going to see speed issues. I would save the various tallies in memory and save to the database once at the end, not 6000 times along the way.

    動靜能量 : even writing all the records at the end, it hits the database 6000 times... and took quite a while. i was thinking of more like 10, 15 seconds max. if i write all data to a flat file, it should only take 1 or 2 seconds. can't i turn off sqlite3 to not "force write" to the db every time, but write it once after all the insert of records?
    James Avery : look at my answer, using bulk insert should speed it way up.
  • What kind of database connection are you using? Some databases allow you to connect 'directly' rather then using a TCP network connection that goes through the network stack. In other words, if you're making an internet connection and sending data through that way, it can slow things down.

    Another way to boost performance of a database connection is to group SQL statements together in a single command.

    For example, making a single 6,000 line SQL statement that looks like this

    "update words set count = count + 1 where word = 'the'
    update words set count = count + 1 where word = 'in'
    ...
    update words set count = count + 1 where word = 'copacetic'"
    

    and run that as a single command, performance will be a lot better. By default, MySQL has a 'packet size' limit of 1 megabyte, but you can change that in the my.ini file to be larger if you want.

    Since you're abstracting away your database calls through ActiveRecord, you don't have much control over how the commands are issued, so it can be difficult to optimize your code.

    Another thin you could do would be to keep a count of words in memory, and then only insert the final total into the database, rather then doing an update every time you come across a word. That will probably cut down a lot on the number of inserts, because if you do an update every time you come across the word 'the', that's a huge, huge waste. Words have a 'long tail' distribution and the most common words are hugely more common then more obscure words. Then the underlying SQL would look more like this:

    "update words set count = 300 where word = 'the'
    update words set count = 250 where word = 'in'
    ...
    update words set count = 1 where word = 'copacetic'"
    

    If you're worried about taking up too much memory, you could count words and periodically 'flush' them. So read a couple megabytes of text, then spend a few seconds updating the totals, rather then updating each word every time you encounter it. If you want to improve performance even more, you should consider issuing SQL commands in batches directly

    動靜能量 : it is using sqlite3... and if i use activerecord, looks like it will hit the db and the hard drive 6000 times and thus quite slow. so i hope to write it all at once...
  • I wrote up some quick code in perl that simply does:

    1. Create the database
    2. Insert a record that only contains a single integer
    3. Retrieve the most recent record and verify that it returns what it inserted

    And it does steps #2 and #3 6000 times. This is obviously a considerably lighter workload than having an entire object/relational bridge. For this trivial case with SQLite it still took 17 seconds to execute, so your desire to have it take "a couple of seconds" is not realistic on "traditional hardware."

    Using the monitor I verified that it was primarily disk activity that was slowing it down. Based on that if for some reason you really do need the database to behave that quickly I suggest one of two options:

    1. Do what people have suggested and find away around the requirement
    2. Try buying some solid state disks.

    I think #1 is a good way to start :)

    Code:

    #!/usr/bin/perl
    
    use warnings;
    use strict;
    
    use DBI;
    
    my $dbh = DBI->connect('dbi:SQLite:dbname=/tmp/dbfile', '', '');
    
    create_database($dbh);
    insert_data($dbh);
    
    sub insert_data {
      my ($dbh) = @_;
    
      my $insert_sql = "INSERT INTO test_table (test_data) values (?)";
      my $retrieve_sql = "SELECT test_data FROM test_table WHERE test_data = ?";
    
      my $insert_sth = $dbh->prepare($insert_sql);
      my $retrieve_sth = $dbh->prepare($retrieve_sql);
    
      my $i = 0;
      while (++$i < 6000) {
         $insert_sth->execute(($i));
         $retrieve_sth->execute(($i));
    
         my $hash_ref = $retrieve_sth->fetchrow_hashref;
    
         die "bad data!" unless $hash_ref->{'test_data'} == $i;
      }
    }
    
    sub create_database {
       my ($dbh) = @_;
    
       my $status = $dbh->do("DROP TABLE test_table");
       # return error status if CREATE resulted in error
       if (!defined $status) {
         print "DROP TABLE failed";
       }
    
       my $create_statement = "CREATE TABLE test_table (id INTEGER PRIMARY KEY AUTOINCREMENT, \n";
       $create_statement .= "test_data varchar(255)\n";
       $create_statement .= ");";
    
       $status = $dbh->do($create_statement);
    
       # return error status if CREATE resulted in error
       if (!defined $status) {
         die "CREATE failed";
       }
    }
    
    Chad Okere : Modern databases can easily deal with 6k inserts in a second if they're setup properly, with the right connection types, indexes, disk caching, etc.
  • Without knowing about Ruby and Sqlite, some general hints:

    create a unique index on Word.s (you did not state whether you have one)

    define a default for Word.count in the database ( DEFAULT 1 )

    optimize assignment of count:

    recordWord = Word.find_by_s(word);
    if (recordWord.nil?)
        recordWord = Word.new
        recordWord.s = word
        recordWord.count = 1
    else
        recordWord.count += 1
    end
    recordWord.save
    
  • Take a look at AR:Extensions as well to handle the bulk insertions.

    http://rubypond.com/articles/2008/06/18/bulk-insertion-of-data-with-activerecord/

  • Use BEGIN TRANSACTION before your updates then COMMIT at the end.

  • ok, i found some general rule:

    1) use a hash to keep the count first, not the db
    2) at the end, wrap all insert or updates in one transaction, so that it won't hit the db 6000 times.

Updating one-to-many with Fluent NHibernate

I'm trying to build a modified role system that has the following class/relationship structure:

Project ProjectRole Employee

where

ProjectEmployee maps the three entities together.

I have a one-to-many mapping from Project to ProjectEmployee and a reference mapping from ProjectEmployee to Project.

I can add new ProjectEmployee's just fine (which means my Create activities are fine as well), but I want to constrain the relationship to have only one entry per Employee. This affects the logic of my Update activities.

In hacking this together, I am attempting to empty the Project.ProjectEmployees (by setting the value to a new List) and then adding a new instance of ProjectEmployee with the appropriate role, etc.

In doing this, I get an error that is related to setting Project.ProjectEmployees to an empty List.

"Cannot insert the value NULL into column 'ProjectId', table 'AppDB.dbo.ProjectEmployees'; column does not allow nulls. UPDATE fails. The statement has been terminated."

If I remove the line that news up the List, the subsequent records get added, but then I'm staring at too many records per employee.

Here's my Project -> ProjectEmployees mapping:

mapping.HasMany(x => x.ProjectEmployees) .Cascade.All() .WithKeyColumn("ProjectId");

And the mapping in ProjectEmployee -> Project:

mapping.References(x => x.Project, "ProjectId");

Should be simple right?

For what it's worth, I also added a method to my Project class called AddProjectEmployee that searches for the Employee in question, removes his ProjectEmployee if he exists, then adds the new ProjectEmployee. I get the same error when I call this.

Any help would be appreciated.

Nick

From stackoverflow
  • This was cross-posted on the Fluent NHibernate group and answered there by Hudson Akridge. As Hudson said, the solution is to use Clear() on the collection as that allows NHibernate to track the changes (whereas newing up the collection causes the property to reference an instance NH doesn't know about).

    mannish : Thanks Stuart. I saw the response on the FNH group as well, and the Clear did in fact resolve my issue.

Which one to use c++ stl container or the MFC container?

For every stl container there is a MFC container available in visual c++.Which is better than the other one in what sense and what do you use?

I always use STL container is that wrong?

From stackoverflow
  • I would always prefer the STL containers because of the portability.

    MFC containers will nearly never be available on Linux.

    Even if you don't plan to use you're code on Linux...you never know what the future brings.

    Aidan Ryan : YAGNI. If you're coding an MFC application you're not writing a portable app.
    rstevens : But maybe you write some non-UI classes to support you're app. And maybe you will re-use them later on in another project that is not using MFC and should also run on Linux.
  • The STL ones. Seriously.

    Aidan Ryan : Why? ......................
    milan1612 : That should be obvious, portability, defined in an industry standard, available on every implementation (that is standard compatible) etc etc...
  • People have pointed out portability of code as a reason to use STL, but there is a much better reason and one which is more in your self interest: Portability of skills and experience. In my opinion when you go looking for your next job having experience with STL on your resume will give you more opportunities. Why? STL effectively is part of standard C++ and if I was hiring I would assume that someone who knows STL could pick up the MFC containers fairly quickly, but I wouldn't necessarily make the opposite assumption if I was looking for someone with STL skills.

    Tim : Yep - stl is just better anyway. I HATED the mfc containers with a passion.
  • Preffer portability and freedom to proprietarism. Go for STL & Boost (www.boost.org).

  • Even when they show you numbers that MFC containers are faster, can be exception-free and make free double-espresso: just close your eyes and use the DEL key (aka NO-LOCK-IN key).

    You can do all that and more portably and in plugabble ways prop solutions can only dream of. STL all the way..

  • Can the MFC containers be used with standard algorithms in the STL?

    Logan Capaldo : Some of them, basically the Arrays (CArray, C*Array). The rest of the containers do have iterators, but not with an STL-style interface, although you could write wrappers.
  • MFC collection classes do have some advantages if you are working within confines of MFC land. E.g. you get things like serialization (if your container elements inherit from CObject or similar) and some debugging support for "free". MSDN has a breakdown of how to choose between different MFC collection types here.

    As a default though, I would lean towards the STL classes.

    yesraaj : what does it mean by dumped? mentioned in the url you are refering
    Logan Capaldo : It's basically a debug pretty print.
    yesraaj : oh thanks......
  • From the source:

    "And frankly the team will give you the same answer. The MFC collection classes are only there for backwards compatibility. C++ has a standard for collection classes and that is the Standards C++ Library. There is no technical drawback for using any of the standard library in an MFC application.

    We do not plan on making significant changes in this area.

    Ronald Laeremans Acting Product Unit Manager Vsual C++ Team "

  • I use STL containers for many reasons: they're well tested, well documented, and well understood by people all over. They're also constantly being improved: look at all the new functionality added by Boost, and it's all backwards compatible. And if you really want to bend your mind, read Alexandrescu's Modern C++ Design: Generic Programming and Design Patterns Applied. Use of Boost and the STL is required to employ many of his techniques.

    Something else to consider is the STL is "Standard" but the MFC is only "Microsoft". Any random generic C++ coder will likely understand STL, but only an old Microsoft coder will know MFC. Besides, Microsoft has pretty much abandoned MFC.

RollBack or Commit (Enterprise Library Transaction) over classes when other class get result in C#

I have a class which is mirror of table.

    public class Patient
    {
        public int Patient_id { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public bool Sex { get; set; }

        public Patient f_UpdatePatient(Patient _patient)
        {
            string QUpdate = "  UPDATE Patients "
                             + "   SET Name    = '" + _patient.Name + "'"
                             + "      ,Address = '" + _patient.Address + "'"
                             + "      ,Sex = " + (_patient.Sex ? "M" : "F")
                             + " WHERE patient_id = " + _patient.Patient_id;

            Database db1 = DatabaseFactory.CreateDatabase("cnnStr");
            DataSet ds = db1.ExecuteDataSet(CommandType.Text, QUpdate);

            // First, How can i set my instance which is coming as a parameter 
            // to my real object. Without passing each value to eac prop of obj.
            return this = _patient;
        }
    }

I have another class which uses Patient. Before use it, it is setting new values to one instance of Patient class, thus i can send the last value to web service. (In fact i need to write db before i use web service which is not in my project)

    public class ServiceConnection
    {
        public static void Main(string[] args)
        {
            Patient pt = new Patient(12);

            // Just want to show that i need DB update.
            pt.Name = args[0];
            pt.Address = args[1];

            try
            {
                // Now i am connection web service and sending pt instance
                bool isOk = f_SendToService(pt);
            }
            catch (Exception ex)
            {
                // Now, at this point, I WANT TO ROLLBACK MY UPDATE with TRANSACTION 
                // or something else
                throw (ex);
            }
        }

        private static bool f_SendToService(Patient pt)
        {
            // trying to send. But sometimes, i get timeout errors
            // sometimes i get false result.
            throw new WebException("Sorry it couldn't reach to WS");
        }
    }

If i get exception or false result, do you have any suggest to me about how can i handle it??

I want to use TRANSACTION (because i don't want to set same row again.) but HOW?

Thanks in advice ...

From stackoverflow
  • You could implement System.ComponentModel.IEditableObject interface and use that entity like this

      Patient pt = new Patient(12);
      pt.BeginEdit();
      pt.Name = args[0];
      pt.Address = args[1];
      if (WSCallIsOK())
         pt.EndEdit();       // save is OK
      else
         pt.CancelEdit();   // sets values back
    

    Example code only for property Sex

    // holds backup of values
    private string __Sex;
    private string _Sex;
    public string Sex
    {
        get
        {
         return _Sex;
        }
        set
        {
         bool changed = _Sex != value;
           if (changed)
          {
           this.RaisePropertyChanged("Sex");
          }
    
        }
    }
    
    
    #region IEditableObject Members
    
    private bool _editing = false;
    
    public void BeginEdit()
    {
        if (!_editing)
        {
         // create copy of property
         __Sex = _Sex;
         //other properties here
         _editing = true;
        }
    }
    
    public void CancelEdit()
    {
        if (_editing)
        {
         // revert back
         _Sex = __Sex;
         //other properties here
         _editing = false;
    
        }
    }
    
    public void EndEdit()
    {
        if (_editing)
        {
         _editing = false;
        }
    }
    
    #endregion
    
    uzay95 : thank you for your answer.

Using OpenID with WCF and no browser, is it possible?

From most of the reading I've done on OpenID, it seems a browser may be required. I'm writing a WCF app and wanted to use OpenID as the authentication method, but my app is not a web app. Is it possible to use WCF and OpenID together without requiring a web browser?

From stackoverflow
  • From reading the OpenID Authentication 2.0 Specification, I seem to have arrived at an answer:

    While nothing in the protocol requires JavaScript or modern browsers, the authentication scheme plays nicely with "AJAX"-style setups. This means an end user can prove their Identity to a Relying Party without having to leave their current Web page.

    OpenID Authentication uses only standard HTTP(S) requests and responses, so it does not require any special capabilities of the User-Agent or other client software. OpenID is not tied to the use of cookies or any other specific mechanism of Relying Party or OpenID Provider session management. Extensions to User-Agents can simplify the end user interaction, though are not required to utilize the protocol.

    Now I just need to figure out a clever way to get it to work with a WCF-based relying party...

  • Hi Chris,

    While OpenID can tout in its spec independence from cookies and such because the spec doesn't actually mandate how those things are used, in reality I've never seen a good OpenID solution for anything besides logging into a web site, which is really its primary use case.

    However there is a good way to go and still use WCF and OpenID. Add OAuth to the mix. The DotNetOpenAuth library has a sample that shows how a WCF client can get authorized to call a WCF service via OAuth, where at the service-side the user uses OpenID to log in as part of the authorization process.

    So basically if you WCF app needs to "log in" in order to call the WCF service, as part of a one-time setup:

    1. The app pops up a browser where the user sees the WCF service web site (the OAuth Service Provider)
    2. The user logs in with their OpenID (although the user may already be logged in, in which case they can skip this step)
    3. The OAuth SP asks the user "do you want to authorize this [wcf app] to access this site?"
    4. The user says yes, and closes the browser.
    5. The WCF app now has access, thanks to the OAuth protocol, to the WCF service.

    This works because behind the scenes, when the user says "yes" to the service through the web browser, a special machine-friendly credential is assigned to the WCF app, which it uses with every WCF service call the a similar way a username/password would be.

    Check out the DotNetOpenAuth library. It has the sample and everything you should need to get this working.

    Chris Gillum : This post was very insightful, thanks! I'll take a look at DotNetOpenAuth.
  • Take a OpenIdMembershipProvider (maybe others exist). Then configure Message security in WCF, with Username authentication, then you can use the ASPNET MembershipProvider to authenticate your user. I don't think you can find an easier solution ;)

    Chris Gillum : This sounds really simple. No browser interaction is required?
    Nicolas Dorier : No browser interaction is required, but I don't know how to use this provider, maybe he has some depedencies on ASP.NET which make you to activate the compatibility mode. see : http://msdn.microsoft.com/en-us/library/aa702682.aspx There is several OpenIDMembershipProvider which exists, I didn't test any of them. Assuming they work as expected, you just have to "plug" your openIdMembershipProvider, and then say WCF to use it to authenticate requests.

Many-to-many relationship: use associative table or delimited values in a column?

Update 2009.04.24

The main point of my question is not developer confusion and what to do about it.

The point is to understand when delimited values are the right solution.

I've seen delimited data used in commercial product databases (Ektron lol).

SQL Server even has an XML datatype, so that could be used for the same purpose as delimited fields.

/end Update

The application I'm designing has some many-to-many relationships. In the past, I've often used associative tables to represent these in the database. This has caused some confusion to the developers.

Here's an example DB structure:

Document
---------------
ID (PK)
Title
CategoryIDs (varchar(4000))


Category
------------
ID (PK)
Title

There is a many-to-many relationship between Document and Category.

In this implementation, Document.CategoryIDs is a big pipe-delimited list of CategoryIDs.

To me, this is bad because it requires use of substring matching in queries -- which cannot make use of indexes. I think this will be slow and will not scale.

With that model, to get all Documents for a Category, you would need something like the following:

select * from documents where categoryids like '%|' + @targetCategoryId + '|%'

My solution is to create an associative table as follows:

Document_Category
-------------------------------
DocumentID (PK)
CategoryID (PK)

This is confusing to the developers. Is there some elegant alternate solution that I'm missing?

I'm assuming there will be thousands of rows in Document. Category may be like 40 rows or so. The primary concern is query performance. Am I over-engineering this?

Is there a case where it's preferred to store lists of IDs in database columns rather than pushing the data out to an associated table?

Consider also that we may need to create many-to-many relationships among documents. This would suggest an associative table Document_Document. Is that the preferred design or s it better to store the associated Document IDs in a single column?

Thanks.

From stackoverflow
  • This is confusing to the developers.

    Get better developers. That is the right approach.

    Paul Tomblin : Agreed 100%. A joiner table is the way to go.
    SQLMenace : true, get rid of them and their stinking CSV data
    Adam Robinson : If your developers are dealing with a database system and encouraging you (directly or indirectly) to violate freaking FIRST normal form, then yeah, they should be on on the curb.
    RibaldEddie : Tell us where you work, so we can all stay away.
    S.Lott : Educate your developers on how associations work. Draw pictures. Write sample code. Administer beatings until they stop acting confused.
    Fake Code Monkey Rashid : I second the beatings.
  • It's almost always a big mistake to use comma separated IDs.
    RDBMS are designed to store relationships.

  • The many-to-many mapping you are doing is fine and normalized. It also allows for other data to be added later if needed. For example, say you wanted to add a time that the category was added to the document.

    I would suggest having a surrogate primary key on the document_category table as well. And a Unique(documentid, categoryid) constraint if that makes sense to do so.

    Why are the developers confused?

  • My solution is to create an associative table as follows: This is confusing to the developers

    Really? this is database 101, if this is confusing to them then maybe they need to step away from their wizard generated code and learn some basic DB normalization.

    What you propose is the right solution!!

  • The Document_Category table in your design is certainly the correct way to approach the problem. If it's possible, I would suggest that you educate the developers instead of coming up with a suboptimal solution (and taking a performance hit, and not having referential integrity).

    Your other options may depend on the database you're using. For example, in SQL Server you can have an XML column that would allow you to store your array in a pre-defined schema and then do joins based on the contents of that field. Other database systems may have something similar.

    Adam Robinson : -1 for proposing to violate 1NF.
    Iceman : +1 for strongly suggesting normalization while providing an alternative that is still better than what the OP's developers were suggesting.
    frankadelic : While normalization is my preference, I'll definitely investigate use of this XML column. How would a query against this column look?
    Ilya Haykinson : There's a discussion at http://www.eggheadcafe.com/community/aspnet/13/80066/xml-column--use-value-to.aspx about doing that However, the discussion at http://social.msdn.microsoft.com/Forums/en-US/sqlxml/thread/47c3582e-ee17-4a3f-92f5-9c92401441ef probably gives the better option. In brief, if your XML column is schema-typed (as opposed to untyped) you can query with something like SELECT t1.* FROM t1 JOIN t2 on t2.x.exist ('/foo/bar[.=sql:column("t1.i")]') = 1 This should use native XML indexing in SQL Server.
  • Your current solution is the best practice for creating many-to-many dimensions, see what Kimball has to say about it.

    Your developers need to take off the training wheels.

    Walter Mitty : Educate the developers!
  • Your suggestion IS the elegant, powerful, best practice solution.

    Since I don't think the other answers said the following strongly enough, I'm going to do it.

    If your developers 1) can't understand how to model a many-to-many relationship in a relational database, and 2) strongly insist on storing your CategoryIDs as delimited character data,

    Then they ought to be IMMEDIATELY REMOVED FROM THEIR POSITIONS, if not right out of the company, perhaps to the help desk or as harmless data entry monkeys. At the very least, they need an actual experienced professional to join their team who has the authority to stop them from doing something this stupid and can give them the years of training they are completely lacking.

    Last, you should NEVER refer to them as "developers" again as this is an insult to those of us who actually are developers.

    I hope this answer is very helpful to you.

    Update

    The main point of my question is not developer confusion and what to do about it.

    Don't store delimited values in columns. Using XML to essentially do the same thing is almost always wrong, too. Storing XML in a column could make sense when it is treated as a "property bag" of sorts that is NOT regularly queried on by the database, but is sent whole to another consumer (perhaps a web server or an EDI recipient).

  • The 'this is confusing to the developers' design means you have under-educated developers. It is the better relational database design - you should use it if at all possible.

    If you really want to use the list structure, then use a DBMS that understands them. Examples of such databases would be the U2 (Unidata, Universe) DBMS, which are (or were, once upon a long time ago) based on the Pick DBMS. There are likely to be other similar DBMS providers.

    Jonathan Leffler : Since I wrote this answer, the U2 DBMS have been sold by IBM to Rocket Software (http://rocketsoftware.com/).
  • Store it as your separate table like you know you should.

    If your developers are that ignorant, just make a view (depending on your RDBMS and requirements, possibly updateable) to show them the data as they want it. I wouldn't encourage this, as it just breeds bad design from their standpoint, but its an option.

  • This is the classic object-relational mapping problem. The developers are probably not stupid, just inexperienced or unaccustomed to doing things the right way. Shouting "3NF!" over and over again won't convince them of the right way.

    I suggest you ask your developers to explain to you how they would get a count of documents by category using the pipe-delimited approach. It would be a nightmare, whereas the link table makes it quite simple.

    frankadelic : Yes - the count of documents use case is a great example to demonstrate the limitations of the pipe-delimited approach.
  • The number one reason that my developers try this "comma-delimited values in a database column" approach is that they have a perception that adding a new table to address the need for multiple values will take too long to add to the data model and the database.

    Most of them know that their work around is bad for all kinds of reasons, but they choose this suboptimal method because they just can. They can do this and maybe never get caught, or they will get caught much later in the project when it is too expensive and risky to fix it. Why do they do this? Because their performance is measured solely on speed and not on quality or compliance.

    It could also be, as on one of my projects, that the developers had a table to put the multi values in but were under the impression that duplicating that data in the parent table would speed up performance. They were wrong and they were called out on it.

    So while you do need an answer to how to handle these costly, risky, and business-confidence damaging tricks, you should also try to find the reason why the developers believe that taking this course of action is better in the short and the long run for the project and company. Then fix both the perception and the data structures.

    Yes, it could just be laziness, malicious intent, or cluelessness, but I'm betting most of the time developers do this stuff because they are constantly being told "just get it done". We on the data model and database design sides need to ensure that we aren't sending the wrong message about how responsive we can be to requests to fulfill a business requirement for a new entity/table/piece of information.

    We should also see that data people need to be constantly monitoring the "as-built" part of our data architectures.

    Personally, I never authorize the use of comma delimited values in a relational database because it is actually faster to build a new table than it is to build a parsing routine to create, update, and manage multiple values in a column and deal with all the anomalies introduced because sometimes that data has embedded commas, too.

    Bottom line, don't do comma delimited values, but find out why the developers want to do it and fix that problem.

embed a java code editor with limited scope in a swing application?

Here's what I want to do. I want to store code objects in my hibernate driven java swing application. I want to allow the user to create code objects that can affect the data with a limited scope, like in a function with only access to members of that member's class. I'd even really like to have a full on little ide (though scaled down with all the irrelevencies hidden) in there which would allow auto-completion and have a button to compile and check, then have all that wrapped so I can drop the thing in my database and schedule it's execution.

Anyone have a good idea, know a good component or way to use eclipse or some such to accomplish this without having a roll out a solution myself?

From stackoverflow
  • To achieve code highlighting and some simple auto complete functionality it would be worth looking at the jsyntaxpane component.

    It's pretty simple and easy to use but you're not going to get the compile functionality from that.

  • you may use Eclipse RCP editor, it has lots of functionality available for reuse. e.g. text highlighting, pair constructions highlighting, text hovers, completion assist, etc. its a lot more powerful, but a lot heavier. and RCP is not only editor...

    Imaskar : glad it helped!