Sorry for indelicate, I researched, tried, and nothing illuminate my
way...

But, MAN! I got it! :) Thanks for the explanation!!! :)

I would now look for:
1) If I can use a Key like you said but with a Key that is a number
generated automatically.
2) If 1 above not possible, how I can map foreign keys and control the
associations.

I would research!

THANKS!
Caram.:


On 12 ago, 13:24, Ronmell Fuentes <ringe...@gmail.com> wrote:
> *Hi *Caram it's good to say hi to you again...  jeje Just Kidding.
>
> yup, you are generating an automatic ID, but that's why there is double
> records, because there is for instance 2 differents IDs for the same
> records. I mean:
>
> let's suppose the initial data in your data store is like following:
> *ID   name  desc.*
> 1.    hello   whatever.
>
> but if you try to upload the same data in an CSV file, like this.
>
> *name   desc.*
> hello    whatever
> hello    whatever1.
>
> after uploading the file the data in datastore would be something like this.
>
> *ID  name  desc.*
> 1.   hello  whatever.
> 2.   hello  whatever.
> 3.   hello  whatever1.
>
> because the ID, is been generated every time that an insert occurs.
>
> If you want to avoid this, you can add something to the Constructor of the
> class to manage this. For example:
>
> *public Login(String user, String password) {
>                Key key = KeyFactory.createKey(Login.class.getSimpleName(),
> user);
>                this.user = user;
>                this.password = password;
>        }*
>
> This will make the following:
>
> when inserting for the first time the data:
> user: "hello"
> pass: "world"
>
> the Datastore would be like this.
>
> *Key                      user        password.*
> Login("hello")        hello        world.
>
> then when uploading new data from CSV, smthg like this.
>
> hello         newworld
> hello2       world2
> hello3       world3
>
>  the data store would be like this.
>
> *key                     user             password.*
> Login("hello")      hello             newworld
> Login("hello2")    hello2           world2
> Login("hello3")    hello3           world3
>
> As you can see, in the user "hello" the data was just update, so there's no
> double records, but the others are inserted as new ones.
> this happens because the Key of your Entity is generated depending on the
> user, and since the Key is unique, when making "MakePersistenceAll()" the
> Data just is written over the previous data, if there is already a record
> with the same Key, then data is updated, otherwise is inserted.
>
> Hope this was helpful.
>
> Rgds.
>
> R. F
>
> 2010/8/12 Caram <caram.jun...@gmail.com>
>
>
>
> > I'm confused.
>
> > My class Login of persistence is:
> > ---------------------------------------------------------------
> > import javax.jdo.annotations.IdGeneratorStrategy;
> > import javax.jdo.annotations.PersistenceCapable;
> > import javax.jdo.annotations.Persistent;
> > import javax.jdo.annotations.PrimaryKey;
>
> > @PersistenceCapable
> > public class Login {
>
> >       �...@primarykey
> >       �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> >        private Long id;
>
> >       �...@persistent
> >        private String user;
>
> >       �...@persistent
> >        private String password;
>
> >        public String getUser() {
> >                return user;
> >        }
>
> >        public void setUser(String user) {
> >                this.user = user;
> >        }
>
> >        public String getPassword() {
> >                return password;
> >        }
>
> >        public void setPassword(String password) {
> >                this.password = password;
> >        }
>
> > }
>
> > --------------------------------------------------------------------------- 
> > ------
>
> > So, I'm storing the Entity and automatic generating the ID. Right? If
> > true, my data should not double as is happening, right?
>
> > Thank you very much!
>
> > Rgds,
> > Caram.:
>
> > On 11 ago, 18:38, Ronmell Fuentes <ringe...@gmail.com> wrote:
> > > yup, just in case the ID is not generated when storing the Entity.
> > > ;-)
> > > otherwise the ID 'd be generated every time the data'd be stored.
>
> > > 2010/8/11 Caram <caram.jun...@gmail.com>
>
> > > > But, in
> > > >http://code.google.com/intl/en/appengine/docs/python/tools/uploadingd.
> > ..
> > > > ,
> > > > he said:
>
> > > > "When data is downloaded, the entities are stored along with their
> > > > original keys. When the data is uploaded, the original keys are used.
> > > > If an entity exists in the datastore with the same key as an entity
> > > > being uploaded, the entity in the datastore is replaced.
>
> > > > You can use upload_data to replace the data in the app from which it
> > > > was dumped, or you can use it to upload the data to a different
> > > > application. Entities with numeric system IDs will be uploaded with
> > > > the same IDs, and reference properties will be preserved."
>
> > > > So, my ID of Login is Long, I understand that it should be updating
> > > > like he said above and not adding as is happening.
>
> > > > Am I right?
>
> > > > Thanks!
> > > > Caram.:
>
> > > > On 11 ago, 15:57, Ronmell Fuentes <ringe...@gmail.com> wrote:
> > > > > Hi, ok.
> > > > > what happens is the following.
>
> > > > > As you already know, in DataStore there's no "update" because when
> > you
> > > > > insert a record, depending on the Primary Key you have set in your,
> > all
> > > > the
> > > > > new data just falls over the first records. This means, that if you
> > are
> > > > > generating an ID every time an insert is done, this will keep until
> > > > always.
> > > > > jeje. But if for example you set a primary Key based on an field of
> > your
> > > > > entity, for example you set
> > > > > Primary Key(MyField);  where MyField is a string name, this will
> > create
> > > > > something like this.
> > > > > For MyField="helloworld1";
>
> > > > > MyEntity("helloworld1");
>
> > > > > For MyField="helloworld2";
>
> > > > > MyEntity("helloworld1");
>
> > > > > and so on...
>
> > > > > So that, the main point here is, when inserting a new record, and the
> > > > value
> > > > > of the Primary Key is not set by yourself, this will automatically
> > create
> > > > a
> > > > > new record. All data will be inserted again and again.
>
> > > > > if you already have the ID=1;
> > > > > and you try to insert a new record with ID=1 and ID is the primary
> > key,
> > > > then
> > > > > the record won't be inserted again, but will be updated.
>
> > > > > As you can see, all depends on the way you create your Entities or
> > > > Classes .
>
> > > > > Rgds.
>
> > > > > R. F.
>
> > > > > 2010/8/11 Caram <caram.jun...@gmail.com>
>
> > > > > > Ronmell,
>
> > > > > > These days I study and I succeed in download data from datastore
> > > > > > in .csv.
> > > > > > I understand that I can modifiy this .csv and upload it to make the
> > > > > > changes in my datastore. But, when I try to upload it, duplicate in
> > my
> > > > > > datastore all entities I have. It changes the ID to name, I've
> > tried
> > > > > > many things unsuccessfully, can you help me?
>
> > > > > > Here my commands/codes:
>
> > > > > > bulkloader.yaml:
>
> > ---------------------------------------------------------------------------
> > > > --------------
> > > > > > # Autogenerated bulkloader.yaml file.
> > > > > > # You must edit this file before using it. TODO: Remove this line
> > when
> > > > > > done.
> > > > > > # At a minimum address the items marked with TODO:
> > > > > > #  * Fill in connector and connector_options
> > > > > > #  * Review the property_map.
> > > > > > #    - Ensure the 'external_name' matches the name of your CSV
> > column,
> > > > > > #      XML tag, etc.
> > > > > > #    - Check that __key__ property is what you want. Its value will
> > > > > > become
> > > > > > #      the key name on import, and on export the value will be the
> > Key
> > > > > > #      object.  If you would like automatic key generation on
> > import
> > > > > > and
> > > > > > #      omitting the key on export, you can remove the entire
> > __key__
> > > > > > #      property from the property map.
>
> > > > > > # If you have module(s) with your model classes, add them here.
> > Also
> > > > > > # change the kind properties to model_class.
> > > > > > python_preamble:
> > > > > > - import: base64
> > > > > > - import: re
> > > > > > - import: google.appengine.ext.bulkload.transform
> > > > > > - import: google.appengine.ext.bulkload.bulkloader_wizard
> > > > > > - import: google.appengine.api.datastore
> > > > > > - import: google.appengine.api.users
>
> > > > > > transformers:
>
> > > > > > - kind: Login
> > > > > >  connector: csv
>
> > > > > >  property_map:
> > > > > >    - property: __key__
> > > > > >      external_name: ID
> > > > > >      export_transform: transform.key_id_or_name_as_string
>
> > > > > >    - property: password
> > > > > >      external_name: password
>
> > > > > >    - property: user
> > > > > >      external_name: user
>
> > ---------------------------------------------------------------------------
> > > > ----------------------------------
>
> > > > > > For download:
> > > > > > appcfg.py download_data -e caram.jun...@gmail.com --
> > > > > > config_file=bulkloader.yaml --kind=Login --filename=teste.csv --
> > > > > > url=http://pac-web.appspot.com/remote_api
>
> > > > > > Result (teste.csv):
>
> > ---------------------------------------------------------------------------
> > > > -------------------------------
> > > > > > password,ID,user
> > > > > > swdw,1,User
> > > > > > CARACA,1001,User
> > > > > > CARACA2,2001,User
> > > > > > ,3001,
> > > > > > edsed,4001,User
> > > > > > edsed,4002,User43
> > > > > > edsed,5001,User43
> > > > > > edsed,6001,User47
>
> > ---------------------------------------------------------------------------
> > > > -------------------------------
>
> > > > > > For upload (result inhttps://appengine.google.com/datastore, kind
> > > > > > Login):
>
> > ---------------------------------------------------------------------------
> > > > -------------------------------
> > > > > > ID/Name  password        user
> > > > > >        id=1     swdw    User
> > > > > >        id=1001  CARACA  User
> > > > > >        id=2001  CARACA2         User
> > > > > >        id=3001  <null>  <null>
> > > > > >        id=4001  edsed   User
> > > > > >        id=4002  edsed   User43
> > > > > >        id=5001  edsed   User43
> > > > > >        id=6001  edsed   User47
> > > > > >        name=1   swdw    User
> > > > > >        name=1001        CARACA  User
> > > > > >        name=2001        CARACA2         User
> > > > > >        name=3001
> > > > > >        name=4001        edsed   User
> > > > > >        name=4002        edsed   User43
> > > > > >        name=5001        edsed  
>
> ...
>
> mais »

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to