Creating New Entities

Entities are defined as a data object that can be used by DIF. DFEntity is the interface used to interact with these objects (a subinterface of DFItem). While they are usually used to define a single database table, they could be used to define multiple tables. It is important to note that DFEntity only defines the 'structure' of the table. Data itself is handled via DFEntityDataProvider.

In general, there are two types of entities - structure entities and standard entities. The former ones can contain a structure field capable of storing chemical structures while the latter ones can only contain simple data such as text and numbers.

Creating both types of entities is simple when using helper methods in DFEntities class. The code below creates a new JChem Base structure entity with the name STRUCTURES and another standard entity with the name DATA. As you are writing to the schema, you will need to lock it. It should be noted that while these entities are created, they aren't promoted.

        import com.im.commons.progress.*
        import com.im.df.api.ddl.*

        def schema = dataTree.schema

        def lock = schema.lockable.obtainLock('create new entities')
        def env = EnvUtils.createDefaultEnvironmentRW(lock, 'creating new entities', true)

        try {
            def structuresEntity = DFEntities.createJChemEntity(schema, 'STRUCTURES', env)
            def dataEntity = DFEntities.createStandardEntity(schema, 'DATA', env)
        } finally {
            env?.feedback.finish()
            lock?.release()
        }
         


Copyright © 1999-2012 ChemAxon Ltd.    All rights reserved.