Search in sources :

Example 21 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class Statement method generateColumnText.

/**
 * Generates the column text for field <code>desc</code>.
 * The column has to be associated to the corresponding query table
 * from the list <code>tableList</code>.
 * For fields mapped to multiple columns choose one column to be included,
 * as all mapped columns should have the same value.
 *
 * @param desc Local field descriptor to be included in the constraint text.
 * @param thePlan Query plan corresponding to <code>desc</code>.
 * @param sb String buffer taking the resulting text.
 */
protected void generateColumnText(LocalFieldDesc desc, QueryPlan thePlan, StringBuffer sb) {
    QueryTable table = null;
    ColumnElement column = null;
    Iterator iter = desc.getColumnElements();
    while (iter.hasNext() && table == null) {
        column = (ColumnElement) iter.next();
        // from the query plan to find the table matching the column.
        if (action == QueryPlan.ACT_SELECT) {
            table = thePlan.findQueryTable(column.getDeclaringTable());
        } else {
            table = findQueryTable(column.getDeclaringTable());
        }
    }
    if (table == null) {
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
        "core.configuration.fieldnotable", desc.getName()));
    }
    // Qualify the column with the table index.
    if (action == QueryPlan.ACT_SELECT) {
        // NOI18N
        sb.append("t").append(table.getTableIndex()).append(".");
    }
    appendQuotedText(sb, column.getName().getName());
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) Iterator(java.util.Iterator) ColumnElement(org.netbeans.modules.dbschema.ColumnElement)

Example 22 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class TransactionImpl method begin.

/**
 * Begin a transaction in managed environment
 */
public void begin(javax.transaction.Transaction t) {
    persistenceManager.acquireExclusiveLock();
    try {
        beginInternal();
        try {
            jta = t;
            EJBHelper.registerSynchronization(jta, this);
        } catch (Exception e) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, "transaction.transactionimpl.begin.registersynchfailed"), // NOI18N
            e);
        }
        txType = CMT;
    } finally {
        persistenceManager.releaseExclusiveLock();
    }
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) JDOException(com.sun.jdo.api.persistence.support.JDOException) JDOUnsupportedOptionException(com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException) JDODataStoreException(com.sun.jdo.api.persistence.support.JDODataStoreException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 23 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class TransactionImpl method begin.

// 
// ----- Methods from javax.transaction.Transaction interface ------
// 
/**
 * Begin a transaction.
 */
public void begin() {
    persistenceManager.acquireExclusiveLock();
    try {
        // Check and set status...
        beginInternal();
        // BMT with JDO Transaction
        if (EJBHelper.isManaged()) {
            txType = BMT_JDO;
            try {
                TransactionManager tm = EJBHelper.getLocalTransactionManager();
                tm.begin();
                jta = tm.getTransaction();
                EJBHelper.registerSynchronization(jta, this);
                pmFactory.registerPersistenceManager(persistenceManager, jta);
            } catch (JDOException e) {
                // re-throw it.
                throw e;
            } catch (Exception e) {
                throw new JDOFatalInternalException(I18NHelper.getMessage(messages, "transaction.transactionimpl.begin.failedlocaltx"), // NOI18N
                e);
            }
        } else {
            txType = NON_MGD;
        }
    } finally {
        persistenceManager.releaseExclusiveLock();
    }
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) JDOException(com.sun.jdo.api.persistence.support.JDOException) JDOUnsupportedOptionException(com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException) JDODataStoreException(com.sun.jdo.api.persistence.support.JDODataStoreException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) JDOException(com.sun.jdo.api.persistence.support.JDOException)

Example 24 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class ForeignFieldDesc method createObjectId.

/**
 * Constructs the oid of a related instance. If called by {@link
 * SQLStateManager#updateTrackedFields}, the new value for the
 * local field <code>fieldDesc</code> is not yet set and passed as
 * parameter <code>value</code>. If called for navigation by
 * {@link SQLStateManager#populateForeignField}, values of updated
 * local fields must be retrieved from the before image.  In both
 * cases, the actual call to this method is in {@link
 * SQLStateManager#getObjectById}.<p>
 * For tracked field usage, see
 * {@link SQLStateManager#setForeignKey} and
 * {@link SQLStateManager#updateTrackedFields}.
 * For navigation usage, see
 * {@link SQLStateManager#realizeForeignField}.
 *
 * @param sm State manager on the local side.
 * @param fieldDesc Local field being set.
 * @param value New value of the field being set.
 * @return The object id for the related instance. This id is used
 * to lookup the instance from the persistence manager cache. The
 * construced oid is invalid, if one of the oid fields is
 * null. In this case the returned value is null.
 */
public Object createObjectId(SQLStateManager sm, LocalFieldDesc fieldDesc, Object value) {
    assert isMappedToPk();
    Class oidClass = foreignConfig.getOidClass();
    Object oid = null;
    try {
        oid = oidClass.newInstance();
    } catch (Exception e) {
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, "core.statemanager.cantnewoid", oidClass.getName()), // NOI18N
        e);
    }
    Field[] keyFields = foreignConfig.getKeyFields();
    String[] keyFieldNames = foreignConfig.getKeyFieldNames();
    for (int i = 0; i < keyFields.length && oid != null; i++) {
        Field keyField = keyFields[i];
        for (int j = 0; j < foreignFields.size() && oid != null; j++) {
            LocalFieldDesc fa = (LocalFieldDesc) foreignFields.get(j);
            if (fa.getName().compareTo(keyFieldNames[i]) == 0) {
                LocalFieldDesc la = (LocalFieldDesc) localFields.get(j);
                Object keyFieldValue = null;
                if (la == fieldDesc) {
                    keyFieldValue = value;
                } else if (sm.getSetMaskBit(la.absoluteID) && !sm.getSetMaskBit(absoluteID)) {
                    keyFieldValue = la.getValue(sm.getBeforeImage());
                } else {
                    keyFieldValue = la.getValue(sm);
                }
                if (keyFieldValue != null) {
                    try {
                        // We need to convert the keyFieldValue to the proper type before
                        // setting it.
                        keyField.set(oid, fa.convertValue(keyFieldValue, sm));
                    } catch (IllegalAccessException e) {
                        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, "core.statemanager.cantsetkeyfield", keyField.getName()), // NOI18N
                        e);
                    }
                } else {
                    oid = null;
                }
            }
        }
    }
    return oid;
}
Also used : Field(java.lang.reflect.Field) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 25 with JDOFatalInternalException

use of com.sun.jdo.api.persistence.support.JDOFatalInternalException in project Payara by payara.

the class ForeignFieldDesc method initializeFieldLists.

/**
 * Initialize the field lists based on column list information.
 */
private void initializeFieldLists() {
    ClassDesc theConfig = classDesc;
    for (int i = 0; i < 4; i++) {
        ArrayList fields = null;
        ArrayList columns = null;
        switch(i) {
            case 0:
                columns = localColumns;
                fields = getLocalFields();
                break;
            case 1:
                columns = assocLocalColumns;
                fields = getAssocLocalFields();
                break;
            case 2:
                columns = assocForeignColumns;
                fields = getAssocForeignFields();
                break;
            case 3:
                columns = foreignColumns;
                fields = getForeignFields();
                theConfig = foreignConfig;
                break;
        }
        if (columns == null)
            continue;
        for (int j = 0; j < columns.size(); j++) {
            ColumnElement ce = (ColumnElement) columns.get(j);
            TableElement te = ce.getDeclaringTable();
            if (te == null) {
                throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
                "core.configuration.columnnotable"));
            }
            fields.add(theConfig.getLocalFieldDesc(ce));
        }
    }
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) ArrayList(java.util.ArrayList) ColumnElement(org.netbeans.modules.dbschema.ColumnElement) TableElement(org.netbeans.modules.dbschema.TableElement)

Aggregations

JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)26 com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)4 ColumnElement (org.netbeans.modules.dbschema.ColumnElement)4 LocalFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)3 ArrayList (java.util.ArrayList)3 JDODataStoreException (com.sun.jdo.api.persistence.support.JDODataStoreException)2 JDOException (com.sun.jdo.api.persistence.support.JDOException)2 JDOUnsupportedOptionException (com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException)2 JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)2 RetrieveDescImpl (com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl)2 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 TableElement (org.netbeans.modules.dbschema.TableElement)2 JDOQueryException (com.sun.jdo.api.persistence.support.JDOQueryException)1 ClassDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc)1 FieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc)1 ForeignFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)1 TableDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.TableDesc)1 DateType (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.DateType)1