Package com.force.sdk.jpa.table

Examples of com.force.sdk.jpa.table.TableImpl


        registerTable(ForceOwner.class);
    }
   
    @SuppressWarnings("rawtypes")
    public void registerTable(Class<?> entityClass) {
        TableImpl tableImpl;
        CustomObject customObjectAnnotation = entityClass.getAnnotation(CustomObject.class);
        if (customObjectAnnotation != null && customObjectAnnotation.virtualSchema()) {
            tableImpl = MockPersistenceUtils.constructVirtualTableImpl(entityClass);
        } else {
            tableImpl = MockPersistenceUtils.constructTableImpl(entityClass);
View Full Code Here


    @Override
    public void locateObject(ObjectProvider op) {
        ForceManagedConnection mconn = (ForceManagedConnection) storeManager.getConnection(op.getExecutionContext());
        try {
            AbstractClassMetaData acmd = op.getClassMetaData();
            TableImpl table = storeManager.getTable(acmd);
            QueryResult qr = ((PartnerConnection) mconn.getConnection())
                .query("select count() from " + table.getTableName().getForceApiName() + " where id='"
                        + op.provideField(op.getClassMetaData().getPKMemberPositions()[0]) + "'");
            if (qr.getSize() == 0) {
                throw new NucleusObjectNotFoundException();
            }
        } catch (ConnectionException x) {
View Full Code Here

                             * This is instance of AllOrNothing transaction
                             * Since the parent object has not been saved to the db yet
                             * we do not have an id yet so we link objects by extId
                             */
                            SObject parentRef = new SObject();
                            TableImpl parent = storeManager.getTable(acmd);
                            if (parent.getExternalIdColumn() == null) {
                                throw new NucleusUserException("EntityManager in persistence.xml has 'force.AllOrNothing'"
                                                               + " set to true. In this mode all top parent Entities must"
                                                               + " have an externalId field. Offending entity: "
                                                               + parent.getTableName().getName());
                            }
                            parentRef.setType(parent.getTableName().getForceApiName());
                            SObject parentSObject = ((ForceObjectManagerImpl) om).getParentSObject(value);
                            parentRef.setField(parent.getExternalIdColumn().getFieldName(),
                                                parentSObject.getField(parent.getExternalIdColumn().getFieldName()));
                            actualValue = parentRef;
                            actualFieldName = column.getForceApiRelationshipName();
                        } else {
                            throw new NucleusUserException("Child entity cannot be saved before parent entity.");
                        }
View Full Code Here

        throw new NucleusUserException("DataNucleus doesnt currently support deletion of schemas for Force.com");
    }

    @Override
    public StoreSchemaData getSchemaData(Object conn, String objName, Object[] values) {
        final TableImpl table = getTable(objName);
        return table == null ? null : new StoreSchemaData() {
           
            @Override
            public Object getProperty(String name) {
                return table.getColumnByForceApiName(name);
            }
           
            @Override
            public void addProperty(String name, Object value) {
                throw new NucleusUserException("DataNucleus doesnt currently support adding properties"
View Full Code Here

     */
    public TableImpl addTable(AbstractClassMetaData acmd, ForceManagedConnection conn) {
        String entityName = PersistenceUtils.getEntityName(acmd).toLowerCase();
        try {
            TableName tableName = TableName.createTableName(conn.getNamespace(), acmd);
            TableImpl tableImpl = tables.get(tableName.getForceApiName().toLowerCase());
            if (tableImpl == null) {
                tableImpl = new TableImpl(conn.getNamespace(), tableName, sObjectResults.get(tableName.getForceApiName()), conn);
                tables.put(tableName.getForceApiName().toLowerCase(), tableImpl);
            }
            entityTables.put(entityName, tableImpl);
            return tableImpl;
        } catch (ConnectionException e) {
View Full Code Here

     * @return the created TableImpl
     */
    public TableImpl addVirtualTable(AbstractClassMetaData acmd) {
        String entityName = PersistenceUtils.getEntityName(acmd).toLowerCase();
        TableName tableName = TableName.createTableName("", acmd);
        TableImpl tableImpl = tables.get(tableName.getForceApiName().toLowerCase());
        if (tableImpl == null) {
            tableImpl = new TableImpl(tableName, acmd);
            tables.put(tableName.getForceApiName().toLowerCase(), tableImpl);
        }
        entityTables.put(entityName, tableImpl);
        return tableImpl;
    }
View Full Code Here

        new ClassInitializer() {
            @Override
            void init(AbstractClassMetaData cmd, ForceStoreManager storeManager, ForceManagedConnection mconn)
                throws ConnectionException {
               
                TableImpl table = storeManager.getTable(cmd);
                table.getMetaData(cmd).emit(storeManager, mconn);
            }
        } .initialize(fileMD, storeManager);
       
        // now do the writing
        try {
            storeManager.getSchemaWriter().write(storeManager.createConnection());
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new NucleusException(e.getMessage(), e);
            }
        }
       
        // Reload new metadata
        new ClassInitializer() {
            @Override
            void init(AbstractClassMetaData cmd, ForceStoreManager storeManager, ForceManagedConnection mconn)
                throws ConnectionException {
               
                TableImpl table = storeManager.getTable(cmd);
                if (!table.isValid()) {
                    table.refresh(null, mconn);
                }
            }
        } .initialize(fileMD, storeManager);
       
        for (FileMetaData md : fileMD) {
View Full Code Here

     * The SchemaWriter's {@code write()} call is made after calling this method.
     */
    private void createSchema(final ClassMetaData cmd, Class cls, final ClassLoaderResolver clr, ForceStoreManager storeManager) {
        synchronized (cmd) {
            ForceManagedConnection mconn = storeManager.createConnection();
            TableImpl table = storeManager.getTable(cmd);
           
            if (PersistenceUtils.hasNoSchema(cmd)) return; //nothing to create
           
            // only create the table if autoCreateTables is true.
            // create the fields without creating the table if the object is already in the organization
            if (storeManager.isAutoCreateTables() && (!table.getTableAlreadyExistsInOrg()
                    || storeManager.isForDelete()) && !PersistenceUtils.isReadOnlySchema(cmd, true)) {
                table.createTableAndFields(cmd, storeManager, mconn);
            } else if (table.getTableAlreadyExistsInOrg() && !PersistenceUtils.isReadOnlySchema(cmd, false)) {
                table.createFields(cmd, storeManager);
            }
           
            // handle the case where autoCreateTables is disabled but the object does not exist in the organization
            if (!storeManager.isAutoCreateTables() && !table.getTableAlreadyExistsInOrg()) {
                StringBuilder msg = new StringBuilder(256);
                msg.append("Table does not exist in force.com and datanucleus.autoCreateTables is false, table: ")
                   .append(table.getTableName().getForceApiName());
                if (storeManager.isAutoCreateWarnOnError()) {
                    LOGGER.warn(msg.toString());
                } else {
                    throw new NucleusUserException(msg.toString());
                }
View Full Code Here

            }
            sb.append(col.getFieldName());
            return;
        }

        TableImpl joinTable = ((ForceStoreManager) forceQuery.getExecutionContext().getStoreManager()).getTable(cmd);

        TableImpl parentTable = this.table;
        AbstractClassMetaData parentCmd = this.acmd;
        this.table = joinTable;
        this.acmd = cmd;
        this.fetchDepth++;
View Full Code Here

   
    private void populateFieldNames(AbstractClassMetaData acmd, OMFContext omf) throws ConnectionException {
        ForceStoreManager storeManager = (ForceStoreManager) omfContext.getStoreManager();
       
        // Grab transactional connection factory
        TableImpl table = storeManager.getTable(acmd);
        // now that we've stored all the Salesforce fields, find the {@code @Entity} definition and register the
        // Java field name on the ColumnImpl.  We'll need this info later
        int[] fieldNumbers =  acmd.getAllMemberPositions();
        if (fieldNumbers != null && fieldNumbers.length > 0) {
            for (int column : fieldNumbers) {
                addColumn(table, acmd.getMetaDataForManagedMemberAtAbsolutePosition(column), omf);
            }
        }
       
        DiscriminatorMetaData dmd = acmd.getDiscriminatorMetaData();
        if (dmd != null && dmd.getColumnName() != null) {
            ColumnImpl col = table.getColumnByForceApiName(dmd.getColumnName());
            if (col != null) {
                String javaFieldName = dmd.getColumnName();
                table.registerJavaColumn(javaFieldName, col);
            }
        }
       
    }
View Full Code Here

TOP

Related Classes of com.force.sdk.jpa.table.TableImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.