Package org.jpox.store.mapped

Examples of org.jpox.store.mapped.DatastoreClass


     * @throws JPOXDataStoreException when an error occurs in the datastore communication
     */
    public void locateObject(StateManager sm)
    {
        ClassLoaderResolver clr = sm.getObjectManager().getClassLoaderResolver();
        DatastoreClass table = storeMgr.getDatastoreClass(sm.getObject().getClass().getName(), clr);
        LocateRequest req = getLocateRequest(table, sm.getObject().getClass().getName());
        req.execute(sm);
    }
View Full Code Here


            Iterator subclass_iter = storeMgr.getSubClassesForClass(schemaDataOption.getName(),false, om.getClassLoaderResolver()).iterator();
            int subclasses_seq_id = 0;
            while (subclass_iter.hasNext())
            {
                String subclass = (String)subclass_iter.next();
                DatastoreClass subclassTable = storeMgr.getDatastoreClass(subclass, om.getClassLoaderResolver());

                // No need to LEFT OUTER JOIN for "subclass-table" and "superclass-table" cases
                // "subclass-table" objects dont exist on their own
                // "superclass-table" are excluded using the discriminator clause
                if (subclassTable != null && !subclassTable.getIdentifier().equals(schemaDataOption.getDatastoreContainerObject().getIdentifier()))
                {
                    DatastoreIdentifier subclassTableIdentifier = storeMgr.getIdentifierFactory().newIdentifier(IdentifierFactory.TABLE, "SUBCLASS" + (subclasses_seq_id++));
                    QueryExpression st = storeMgr.getDatastoreAdapter().newQueryStatement(subclassTable, subclassTableIdentifier, om.getClassLoaderResolver());
                    LogicSetExpression table_expr_sub = st.newTableExpression(subclassTable, subclassTableIdentifier);
                    JavaTypeMapping subMapping = subclassTable.getIDMapping();
                    st.select(subclassTableIdentifier, subMapping);

                    ScalarExpression subExpr = subMapping.newScalarExpression(qs, table_expr_sub);
                    ScalarExpression schExpr =
                        (((DatastoreClass)schemaDataOption.getDatastoreContainerObject()).getIDMapping()).newScalarExpression(
View Full Code Here

        // Form the query to find which one of these classes has the instance with this id
        DiscriminatorIteratorStatement discrimStmt = new DiscriminatorIteratorStatement(clr, new Class[] {primaryClass}, true, storeMgr, true);

        // Check all instances of this table to see if we have all possible candidates in our "options" list
        DatastoreClass primaryTable = storeMgr.getDatastoreClass(primaryClass.getName(), clr);
        StoreData[] storeData = storeMgr.getStoreDataForDatastoreContainerObject(primaryTable.getIdentifier());
        boolean haveAllCandidates = true;
        for (int i=0;i<storeData.length;i++)
        {
            if (storeData[i] instanceof MappedStoreData)
            {
                ClassTable tbl = (ClassTable)((MappedStoreData)storeData[i]).getDatastoreContainerObject();
                String[] managedClasses = tbl.getManagedClasses();
                for (int j=0;j<managedClasses.length;j++)
                {
                    boolean managedClassFound = false;
                    Iterator optionsIter = schemaDataOptions.iterator();
                    while (optionsIter.hasNext())
                    {
                        StoreData optionData = (StoreData)optionsIter.next();
                        if (optionData.getName().equals(managedClasses[j]))
                        {
                            managedClassFound = true;
                            break;
                        }
                    }
                    if (!managedClassFound)
                    {
                        haveAllCandidates = false;
                        break;
                    }
                }
                if (!haveAllCandidates)
                {
                    break;
                }
            }
        }

        if (haveAllCandidates)
        {
            // We have all possible candidates that are stored in this table so we can omit the restriction on the discriminator
            discrimStmt.setRestrictDiscriminator(false); // Just retrieve the discriminator for this id (accept any possible disc values)
        }

        // Create the statement
        QueryExpression stmt = discrimStmt.getQueryStatement(null);

        // WHERE (object id) = ?
        // We have to create a StateManager here just to map fields from the AppId key object to the table fields.
        // Really the table should have some way of doing this. TODO : Refactor this
        StateManager sm = StateManagerFactory.newStateManagerForHollow(om, objectClass, id);
        JavaTypeMapping idMapping = primaryTable.getIDMapping();
        ScalarExpression fieldExpr = idMapping.newScalarExpression(stmt, stmt.getMainTableExpression());
        ScalarExpression fieldValue = idMapping.newLiteral(stmt, sm.getObject());
        stmt.andCondition(fieldExpr.eq(fieldValue), true);

        // Perform the query
View Full Code Here

                            AbstractClassMetaData cmd = (AbstractClassMetaData) data.getMetaData();
                            InheritanceMetaData imd = cmd.getInheritanceMetaData();
                            if (imd.getStrategyValue() == InheritanceStrategy.SUPERCLASS_TABLE)
                            {
                                AbstractClassMetaData[] managingCmds = getClassesManagingTableForClass(cmd, clr);
                                DatastoreClass superTable = null;
                                if (managingCmds != null && managingCmds.length == 1)
                                {
                                    RDBMSStoreData superData =
                                        (RDBMSStoreData) storeDataMgr.get(managingCmds[0].getFullClassName());
View Full Code Here

                                JPOXLogger.DATASTORE.warn(msg);
                            }
                        }

                        // Create the table to use for this class
                        DatastoreClass t = null;
                        boolean hasViewDef = false;
                        if (dba.getVendorID() != null)
                        {
                            hasViewDef = cmd.hasExtension("view-definition" + '-' + dba.getVendorID());
                        }
View Full Code Here

     * @param type
     * @param expectedMappingType
     */
    private void assertCompatibleFieldType(AbstractMemberMetaData fmd, ClassLoaderResolver clr, Class type, Class expectedMappingType)
    {
        DatastoreClass ownerTable = getDatastoreClass(fmd.getClassName(), clr);
        JavaTypeMapping m = ownerTable.getFieldMapping(fmd);
        if (!expectedMappingType.isAssignableFrom(m.getClass()))
        {
            throw new IncompatibleFieldTypeException(fmd.getFullFieldName(),
                type.getName(), fmd.getTypeName());
        }
View Full Code Here

        {
            // Perform a check on the exact object inheritance level with this key (uses SQL query)
            String className = null;
            if( cmd != null && cmd.getDiscriminatorStrategy()!=null)
            {
                DatastoreClass primaryTable = this.getDatastoreClass(cmd.getFullClassName(), om.getClassLoaderResolver());
                if (primaryTable != null)
                {
                    classTree.add(storeDataMgr.get(cmd.getFullClassName()));
                    HashSet subclasses = getSubClassesForClass(cmd.getFullClassName(), true, clr);
                    Iterator subclassesIter = subclasses.iterator();
View Full Code Here

        if (!cmd.isRequiresExtent())
        {
            throw new NoExtentException(c.getName());
        }

        DatastoreClass t = getDatastoreClass(cmd.getFullClassName(), om.getClassLoaderResolver());
        if (cmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.COMPLETE_TABLE)
        {
            // "complete-table" may imply many tables not discoverable from the root table
            HashSet candidateTables = new HashSet();
            if (t != null)
            {
                candidateTables.add(t);
            }
            if (subclasses)
            {
                HashSet subclassNames = getSubClassesForClass(cmd.getFullClassName(), subclasses, om.getClassLoaderResolver());
                if (subclassNames != null)
                {
                    Iterator subclassIter = subclassNames.iterator();
                    while (subclassIter.hasNext())
                    {
                        String subclassName = (String)subclassIter.next();
                        DatastoreClass tbl = getDatastoreClass(subclassName, om.getClassLoaderResolver());
                        if (tbl != null)
                        {
                            candidateTables.add(tbl);
                        }
                    }
View Full Code Here

            extensions = cmd.getIdentityMetaData().getExtensions();
        }

        // Get base table with the required field
        // TODO The passed-in table may already be the right one - do this better
        DatastoreClass tbl = getDatastoreClass(cmd.getBaseAbstractClassMetaData().getFullClassName(),
            om.getClassLoaderResolver());
        if (tbl == null)
        {
            tbl = getTableForStrategy(cmd,absoluteFieldNumber,om.getClassLoaderResolver());
        }
        JavaTypeMapping m = null;
        if (mmd != null)
        {
            m = tbl.getFieldMapping(mmd);
            if (m == null)
            {
                // Field not mapped in root table so use passed-in table
                tbl = getTableForStrategy(cmd,absoluteFieldNumber,om.getClassLoaderResolver());
                m = tbl.getFieldMapping(mmd);
            }
        }
        else
        {
            m = tbl.getIDMapping();
        }
        StringBuffer columnsName = new StringBuffer();
        for (int i = 0; i < m.getNumberOfDatastoreFields(); i++)
        {
            if (i > 0)
            {
                columnsName.append(",");
            }
            columnsName.append(m.getDataStoreMapping(i).getDatastoreField().getIdentifier().toString());
        }

        Properties properties = new Properties();
        properties.setProperty("class-name", cmd.getFullClassName());
        properties.put("root-class-name", cmd.getBaseAbstractClassMetaData().getFullClassName());
        if (mmd != null)
        {
            properties.setProperty("field-name", mmd.getFullFieldName());
        }
        if (cmd.getCatalog() != null)
        {
            properties.setProperty("catalog-name", cmd.getCatalog());
        }
        if (cmd.getSchema() != null)
        {
            properties.setProperty("schema-name", cmd.getSchema());
        }
        properties.setProperty("table-name", tbl.getIdentifier().toString());
        properties.setProperty("column-name", columnsName.toString());

        if (sequence != null)
        {
            properties.setProperty("sequence-name", sequence);
View Full Code Here

        return properties;
    }

    private DatastoreClass getTableForStrategy(AbstractClassMetaData cmd, int fieldNumber, ClassLoaderResolver clr)
    {
        DatastoreClass t = getDatastoreClass(cmd.getFullClassName(), clr);
        if (t == null && cmd.getInheritanceMetaData().getStrategyValue() == InheritanceStrategy.SUBCLASS_TABLE)
        {
            throw new JPOXUserException(LOCALISER.msg("032013", cmd.getFullClassName()));
        }

        if (fieldNumber>=0)
        {
            AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
            t = t.getBaseDatastoreClassWithField(fmd);
        }
        else if (t!=null)
        {
            // Go up to overall superclass to find id for that class.
            boolean has_superclass = true;
            while (has_superclass)
            {
                DatastoreClass supert = t.getSuperDatastoreClass();
                if (supert != null)
                {
                    t = supert;
                }
                else
View Full Code Here

TOP

Related Classes of org.jpox.store.mapped.DatastoreClass

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.