I haven't seen the Modeler breaking relationships on renaming the tables/classes. Which version of Cayenne are you using, and if it is 3.0 or newer, what is the exact scenario - maybe we need a Jira for it?
Beyond that it is all a matter of preference, so as long as you keep in mind all the pieces involved, there can be more than one way to refactor things. I'd usually manually write a SQL script that changes the DB and commit it to version control (as it will need to be rerun in QA/production later on the next release). Then I'd perform needed renaming in the Modeler, then refresh my project in Eclipse (that triggers Maven class generation), and then delete classes no longer in use. Andrus On Feb 18, 2011, at 5:58 PM, Hans C. Poo wrote: > Hi, > > I've been using cayenne three years from now. > > Using the modeller i tried to rename a table and then a class with distinct > levels of problems with broken relationships. Until i see the modeller does > atempts to refactor some things but many gets broken. > > I've found a tricky method to refactor things with relative confidence: > > First: > > 1.- Classes > Rename classes: the entity and the cayenne entity (underscore first > character) using the refactor capabilities of your IDE. > > 2.- XML files > Here it's a very artesanal perl script that refactor a table and the related > entity. If you call it refactor-table-name.pl you can call it this way: > > Move where cayenne files are located and: > > refactor-table-name.pl old-table-name new-table-name *.xml > > 3.- So far some things still may be broken > > Then open the modeller and your project, the use Project > Validate Project > there may be the broken object relationships, these must be deleted an > re-synchronised and will be fine. > > 4.- Database > Finally: rename the table in the database using alter table. > > > Please if there is some better, safer way to do it please let me know. > > The code of the perl script follows. Save it under your bin directory and > name it refactor-table-name.pl, then chmod 755 refactor-table-name.pl. > > #!/usr/bin/perl > > > ## Refactor cayenne table and entity, give table names assumed parts of the > name separated by underscores. > ## Use under your own risk on a copy of your data. > > use strict; > use warnings; > > use File::Copy; > > die "Error, call format: $0 old-table-name new-table-name file1 [ .. more > files ] " if @ARGV < 3; > > my $old_name = shift; > my $new_name = shift; > > # extrapolar object names > > my $old_name_obj = ""; > foreach (split /_/, $old_name) { > $old_name_obj .= ucfirst($_); > } > > my $new_name_obj = ""; > foreach (split /_/, $new_name) { > $new_name_obj .= ucfirst($_); > } > > my @files = @ARGV; > > printf "Renaming table %s to %s\n", $old_name, $new_name; > printf "Renaming clase %s to %s\n", $old_name_obj, $new_name_obj; > > my $i = 1; > foreach my $file (@files) { > > print "Processing file $file\n"; > > open IN, $file or die "File $file, error $!\n"; > > my $tmp = "/tmp/refactor-$i-cayenne-$$"; > $i++; > > open TMP, ">$tmp" or die "File $file, error $!\n"; > > my $flag_modif = 0; > > while (<IN>) { > > my $orig_line = $_; > > s/db-entity name="$old_name"/db-entity name="$new_name"/; > s/dbEntityName="$old_name"/dbEntityName="$new_name"/; > s/target="$old_name"/target="$new_name"/; > s/source="$old_name"/source="$new_name"/; > > s/db-relationship-path="$old_name"/db-relationship-path="$new_name"/; > s/dbEntityName="$old_name"/dbEntityName="$new_name"/; > > > s/<obj-entity name="$old_name_obj"/<obj-entity > name="$new_name_obj"/; > > s/className="(.*?)\.$old_name_obj"/className="$1.$new_name_obj"/; > s/source="$old_name_obj"/source="$new_name_obj"/; > s/target="$old_name_obj"/target="$new_name_obj"/; > > $flag_modif = 1 if $orig_line ne $_; > > print TMP $_; > > } > > close IN; > close TMP; > > if ($flag_modif == 1) { > print "\t * File modified\n"; > copy $tmp, $file or die $!; > } > > } > > > exit 0; > > > > Bye > Hans, Welinux S.A. > >