Search in sources :

Example 1 with MethodFactory

use of org.apache.derby.iapi.store.access.conglomerate.MethodFactory in project derby by apache.

the class RAMTransaction method createConglomerate.

/**
 * Create a new conglomerate.
 * <p>
 * @see TransactionController#createConglomerate
 *
 * @exception  StandardException  Standard exception policy.
 */
public long createConglomerate(String implementation, DataValueDescriptor[] template, ColumnOrdering[] columnOrder, int[] collationIds, Properties properties, int temporaryFlag) throws StandardException {
    // Find the appropriate factory for the desired implementation.
    MethodFactory mfactory;
    mfactory = accessmanager.findMethodFactoryByImpl(implementation);
    if (mfactory == null || !(mfactory instanceof ConglomerateFactory)) {
        throw StandardException.newException(SQLState.AM_NO_SUCH_CONGLOMERATE_TYPE, implementation);
    }
    ConglomerateFactory cfactory = (ConglomerateFactory) mfactory;
    // Create the conglomerate
    // RESOLVE (mikem) - eventually segmentid's will be passed into here
    // in the properties.  For now just use 0.]
    int segment;
    long conglomid;
    if ((temporaryFlag & TransactionController.IS_TEMPORARY) == TransactionController.IS_TEMPORARY) {
        segment = ContainerHandle.TEMPORARY_SEGMENT;
        conglomid = ContainerHandle.DEFAULT_ASSIGN_ID;
    } else {
        // RESOLVE - only using segment 0
        segment = 0;
        conglomid = accessmanager.getNextConglomId(cfactory.getConglomerateFactoryId());
    }
    // call the factory to actually create the conglomerate.
    Conglomerate conglom = cfactory.createConglomerate(this, segment, conglomid, template, columnOrder, collationIds, properties, temporaryFlag);
    long conglomId;
    if ((temporaryFlag & TransactionController.IS_TEMPORARY) == TransactionController.IS_TEMPORARY) {
        conglomId = nextTempConglomId--;
        if (tempCongloms == null)
            tempCongloms = new HashMap<Long, Conglomerate>();
        tempCongloms.put(conglomId, conglom);
    } else {
        conglomId = conglom.getContainerid();
        accessmanager.conglomCacheAddEntry(conglomId, conglom);
    }
    return conglomId;
}
Also used : MethodFactory(org.apache.derby.iapi.store.access.conglomerate.MethodFactory) ConglomerateFactory(org.apache.derby.iapi.store.access.conglomerate.ConglomerateFactory) HashMap(java.util.HashMap) Conglomerate(org.apache.derby.iapi.store.access.conglomerate.Conglomerate)

Example 2 with MethodFactory

use of org.apache.derby.iapi.store.access.conglomerate.MethodFactory in project derby by apache.

the class RAMTransaction method openSortCostController.

/**
 * Return an open SortCostController.
 * <p>
 * Return an open SortCostController which can be used to ask about
 * the estimated costs of SortController() operations.
 * <p>
 *
 * @return The open StoreCostController.
 *
 * @exception  StandardException  Standard exception policy.
 *
 * @see StoreCostController
 */
public SortCostController openSortCostController() throws StandardException {
    // Get the implementation type from the parameters.
    // RESOLVE (mikem) need to figure out how to select sort implementation.
    String implementation = null;
    if (implementation == null)
        implementation = AccessFactoryGlobals.SORT_EXTERNAL;
    // Find the appropriate factory for the desired implementation.
    MethodFactory mfactory;
    mfactory = accessmanager.findMethodFactoryByImpl(implementation);
    if (mfactory == null || !(mfactory instanceof SortFactory)) {
        throw (StandardException.newException(SQLState.AM_NO_FACTORY_FOR_IMPLEMENTATION, implementation));
    }
    SortFactory sfactory = (SortFactory) mfactory;
    // open sort cost controller
    return (sfactory.openSortCostController());
}
Also used : MethodFactory(org.apache.derby.iapi.store.access.conglomerate.MethodFactory) SortFactory(org.apache.derby.iapi.store.access.conglomerate.SortFactory)

Example 3 with MethodFactory

use of org.apache.derby.iapi.store.access.conglomerate.MethodFactory in project derby by apache.

the class RAMTransaction method createSort.

/**
 *	@see TransactionController#createSort
 *	@exception StandardException Standard error policy.
 */
public long createSort(Properties implParameters, DataValueDescriptor[] template, ColumnOrdering[] columnOrdering, SortObserver sortObserver, boolean alreadyInOrder, long estimatedRows, int estimatedRowSize) throws StandardException {
    // Get the implementation type from the parameters.
    // XXX (nat) need to figure out how to select sort implementation.
    String implementation = null;
    if (implParameters != null)
        implementation = implParameters.getProperty(AccessFactoryGlobals.IMPL_TYPE);
    if (implementation == null)
        implementation = AccessFactoryGlobals.SORT_EXTERNAL;
    // Find the appropriate factory for the desired implementation.
    MethodFactory mfactory;
    mfactory = accessmanager.findMethodFactoryByImpl(implementation);
    if (mfactory == null || !(mfactory instanceof SortFactory)) {
        throw (StandardException.newException(SQLState.AM_NO_FACTORY_FOR_IMPLEMENTATION, implementation));
    }
    SortFactory sfactory = (SortFactory) mfactory;
    // Decide what segment the sort should use.
    // XXX (nat) sorts always in segment 0
    int segment = 0;
    // Create the sort.
    Sort sort = sfactory.createSort(this, segment, implParameters, template, columnOrdering, sortObserver, alreadyInOrder, estimatedRows, estimatedRowSize);
    // Add the sort to the sorts vector
    if (sorts == null) {
        sorts = new ArrayList<Sort>();
        freeSortIds = new ArrayList<Integer>();
    }
    int sortid;
    if (freeSortIds.isEmpty()) {
        // no free identifiers, add sort at the end
        sortid = sorts.size();
        sorts.add(sort);
    } else {
        // reuse a sort identifier
        sortid = (freeSortIds.remove(freeSortIds.size() - 1)).intValue();
        sorts.set(sortid, sort);
    }
    return sortid;
}
Also used : MethodFactory(org.apache.derby.iapi.store.access.conglomerate.MethodFactory) Sort(org.apache.derby.iapi.store.access.conglomerate.Sort) SortFactory(org.apache.derby.iapi.store.access.conglomerate.SortFactory)

Example 4 with MethodFactory

use of org.apache.derby.iapi.store.access.conglomerate.MethodFactory in project derby by apache.

the class RAMAccessManager method findMethodFactoryByFormat.

/**
 *    Find an access method that implements a format type.
 *    @see AccessFactory#findMethodFactoryByFormat
 */
public MethodFactory findMethodFactoryByFormat(UUID format) {
    MethodFactory factory;
    // See if there's an access method that supports the desired
    // format type as its primary format type.
    factory = formathash.get(format);
    if (factory != null)
        return factory;
    // No primary format.  See if one of the access methods
    // supports it as a secondary format.
    Enumeration<MethodFactory> e = formathash.elements();
    while (e.hasMoreElements()) {
        factory = e.nextElement();
        if (factory.supportsFormat(format))
            return factory;
    }
    // No such implementation.
    return null;
}
Also used : MethodFactory(org.apache.derby.iapi.store.access.conglomerate.MethodFactory)

Example 5 with MethodFactory

use of org.apache.derby.iapi.store.access.conglomerate.MethodFactory in project derby by apache.

the class RAMAccessManager method findMethodFactoryByImpl.

/**
 *    Find an access method that implements an implementation type.
 *    @see AccessFactory#findMethodFactoryByImpl
 */
public MethodFactory findMethodFactoryByImpl(String impltype) throws StandardException {
    // See if there's an access method that supports the desired
    // implementation type as its primary implementation type.
    MethodFactory factory = implhash.get(impltype);
    if (factory != null)
        return factory;
    // No primary implementation.  See if one of the access methods
    // supports the implementation type as a secondary.
    Enumeration<MethodFactory> e = implhash.elements();
    while (e.hasMoreElements()) {
        factory = e.nextElement();
        if (factory.supportsImplementation(impltype))
            return factory;
    }
    factory = null;
    // try and load an implementation.  a new properties object needs
    // to be created to hold the conglomerate type property, since
    // that value is specific to the conglomerate we want to boot, not
    // to the service as a whole
    Properties conglomProperties = new Properties(serviceProperties);
    conglomProperties.put(AccessFactoryGlobals.CONGLOM_PROP, impltype);
    try {
        factory = (MethodFactory) bootServiceModule(false, this, MethodFactory.MODULE, impltype, conglomProperties);
    } catch (StandardException se) {
        if (!se.getMessageId().equals(SQLState.SERVICE_MISSING_IMPLEMENTATION))
            throw se;
    }
    conglomProperties = null;
    if (factory != null) {
        registerAccessMethod(factory);
        return factory;
    }
    // No such implementation.
    return null;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) MethodFactory(org.apache.derby.iapi.store.access.conglomerate.MethodFactory) Properties(java.util.Properties)

Aggregations

MethodFactory (org.apache.derby.iapi.store.access.conglomerate.MethodFactory)6 ConglomerateFactory (org.apache.derby.iapi.store.access.conglomerate.ConglomerateFactory)2 SortFactory (org.apache.derby.iapi.store.access.conglomerate.SortFactory)2 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Conglomerate (org.apache.derby.iapi.store.access.conglomerate.Conglomerate)1 Sort (org.apache.derby.iapi.store.access.conglomerate.Sort)1 StandardException (org.apache.derby.shared.common.error.StandardException)1