Package org.jboss.as.cmp.jdbc2

Examples of org.jboss.as.cmp.jdbc2.PersistentContext


            throw CmpMessages.MESSAGES.errorSettingInstanceField(fieldName, e);
        }
    }

    public void setValueInternal(CmpEntityBeanContext ctx, Object value, boolean makeDirty) {
        PersistentContext pctx = (PersistentContext) ctx.getPersistenceContext();

        // todo this is weird
        if (cmpFieldIAmMappedTo != null && cmpFieldIAmMappedTo.isPrimaryKeyMember) {
            Object curValue = pctx.getFieldValue(rowIndex);
            if (value != null && !value.equals(curValue)) {
                throw CmpMessages.MESSAGES.attemptToModifyPkThroughFk(entity.getEntityName(), cmpFieldIAmMappedTo.getFieldName(), entity.getQualifiedTableName(), cmpFieldIAmMappedTo.getColumnName(), curValue, value);
            }

            makeDirty = false;
        } else {
            pctx.setFieldValue(rowIndex, value);
        }

        if (makeDirty) {
            pctx.setDirty();
        }
    }
View Full Code Here


    public String getFieldName() {
        return fieldName;
    }

    public Object getValue(CmpEntityBeanContext ctx) {
        PersistentContext pctx = (PersistentContext) ctx.getPersistenceContext();
        return pctx.getFieldValue(rowIndex);
    }
View Full Code Here

        this.pkSql = "";
    }

    public Object execute(Method m, Object[] args, CmpEntityBeanContext ctx) throws CreateException {
        Object pk;
        PersistentContext pctx = (PersistentContext) ctx.getPersistenceContext();
        if (ctx.getPrimaryKeyUnchecked() == null) {
            Connection con = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                if (log.isDebugEnabled()) {
                    log.debug("executing sql: " + pkSql);
                }

                con = entityBridge.getDataSource().getConnection();
                ps = con.prepareStatement(pkSql);
                rs = ps.executeQuery();

                if (!rs.next()) {
                    throw CmpMessages.MESSAGES.pkSqlReturnedNoResults(pkSql);
                }

                pk = pkField.loadArgumentResults(rs, 1);
                pctx.setFieldValue(pkField.getRowIndex(), pk);
                pk = entityBridge.extractPrimaryKeyFromInstance(ctx);
            } catch (SQLException e) {
                throw CmpMessages.MESSAGES.failedToExecutePkSql(e);
            } finally {
                JDBCUtil.safeClose(rs);
                JDBCUtil.safeClose(ps);
                JDBCUtil.safeClose(con);
            }

            if (pk == null) {
                throw CmpMessages.MESSAGES.pkIsNullForCreatedInstance();
            }

            pctx.setPk(pk);
        } else {
            // insert-after-ejb-post-create
            try {
                pctx.flush();
            } catch (SQLException e) {
                if ("23000".equals(e.getSQLState())) {
                    throw CmpMessages.MESSAGES.uniqueKeyViolation(ctx.getPrimaryKeyUnchecked());
                } else {
                    throw CmpMessages.MESSAGES.failedToCreateInstance(ctx.getPrimaryKeyUnchecked(), e);
View Full Code Here

        for (JDBCQueryMetaData metadata : queries) {
            if (metadata.getMethod().getName().startsWith("ejbSelect")) {
                try {
                    QueryCommand queryCommand = queryFactory.getQueryCommand(metadata.getMethod());
                    Schema schema = ((JDBCStoreManager2) entityBridge.getManager()).getSchema();
                    EJBSelectBridge ejbSelectBridge = new EJBSelectBridge((JDBCStoreManager2) entityBridge.getManager(), entityBridge.getComponent(), schema, metadata, queryCommand);
                    selectorsByMethod.put(metadata.getMethod(), ejbSelectBridge);
                } catch (FinderException e) {
                    throw new RuntimeException(e);
                }
            }
View Full Code Here

        for (JDBCQueryMetaData metadata : queries) {
            if (metadata.getMethod().getName().startsWith("ejbSelect")) {
                try {
                    QueryCommand queryCommand = queryFactory.getQueryCommand(metadata.getMethod());
                    Schema schema = ((JDBCStoreManager2) entityBridge.getManager()).getSchema();
                    EJBSelectBridge ejbSelectBridge = new EJBSelectBridge((JDBCStoreManager2) entityBridge.getManager(), entityBridge.getComponent(), schema, metadata, queryCommand);
                    selectorsByMethod.put(metadata.getMethod(), ejbSelectBridge);
                } catch (FinderException e) {
                    throw new RuntimeException(e.getMessage());
                }
            }
View Full Code Here

        // UPDATE SQL
        updateSql = "update " + tableName + " set ";
        int setFields = 0;
        for (int i = 0; i < tableFields.length; ++i) {
            JDBCCMPFieldBridge2 field = tableFields[i];
            if (!field.isPrimaryKeyMember()) {
                if (setFields++ > 0) {
                    updateSql += ", ";
                }
                updateSql += field.getColumnName() + "=?";
            }
        }
        updateSql += " where ";
        updateSql += pkFields[0].getColumnName() + "=?";
        for (int i = 1; i < pkFields.length; ++i) {
            updateSql += " and " + pkFields[i].getColumnName() + "=?";
        }

        if (entity.getVersionField() != null) {
            updateSql += " and " + entity.getVersionField().getColumnName() + "=?";
        }
        log.debug("update sql: " + updateSql);

        // SELECT SQL
        String selectColumns = tableFields[0].getColumnName();
        for (int i = 1; i < tableFields.length; ++i) {
            JDBCCMPFieldBridge2 field = tableFields[i];
            selectColumns += ", " + field.getColumnName();
        }

        String whereColumns = pkFields[0].getColumnName() + "=?";
        for (int i = 1; i < pkFields.length; ++i) {
            whereColumns += " and " + pkFields[i].getColumnName() + "=?";
View Full Code Here

            con = dataSource.getConnection();
            ps = con.prepareStatement(selectSql);

            int paramInd = 1;
            for (int i = 0; i < pkFields.length; ++i) {
                JDBCCMPFieldBridge2 pkField = pkFields[i];
                Object pkValue = pkField.getPrimaryKeyValue(id);
                paramInd = pkField.setArgumentParameters(ps, paramInd, pkValue);
            }

            rs = ps.executeQuery();

            if (!rs.next()) {
View Full Code Here

            while (view.deleted != null) {
                Row row = view.deleted;

                int paramInd = 1;
                for (int pkInd = 0; pkInd < pkFields.length; ++pkInd) {
                    JDBCCMPFieldBridge2 pkField = pkFields[pkInd];
                    Object fieldValue = row.fields[pkField.getRowIndex()];
                    paramInd = pkField.setArgumentParameters(ps, paramInd, fieldValue);
                }

                deleteStrategy.executeUpdate(ps);

                ++batchCount;
View Full Code Here

            while (view.dirty != null) {
                Row row = view.dirty;

                int paramInd = 1;
                for (int fInd = 0; fInd < tableFields.length; ++fInd) {
                    JDBCCMPFieldBridge2 field = tableFields[fInd];
                    if (!field.isPrimaryKeyMember()) {
                        Object fieldValue = row.fields[field.getRowIndex()];
                        paramInd = field.setArgumentParameters(ps, paramInd, fieldValue);
                    }
                }

                for (int fInd = 0; fInd < pkFields.length; ++fInd) {
                    JDBCCMPFieldBridge2 pkField = pkFields[fInd];
                    Object fieldValue = row.fields[pkField.getRowIndex()];
                    paramInd = pkField.setArgumentParameters(ps, paramInd, fieldValue);
                }

                JDBCCMPFieldBridge2 versionField = entity.getVersionField();
                if (versionField != null) {
                    int versionIndex = versionField.getVersionIndex();
                    Object curVersion = row.fields[versionIndex];
                    paramInd = versionField.setArgumentParameters(ps, paramInd, curVersion);

                    Object newVersion = row.fields[versionField.getRowIndex()];
                    row.fields[versionIndex] = newVersion;
                }

                updateStrategy.executeUpdate(ps);
View Full Code Here

            while (view.created != null) {
                Row row = view.created;

                int paramInd = 1;
                for (int fInd = 0; fInd < tableFields.length; ++fInd) {
                    JDBCCMPFieldBridge2 field = tableFields[fInd];
                    Object fieldValue = row.fields[field.getRowIndex()];
                    paramInd = field.setArgumentParameters(ps, paramInd, fieldValue);
                }

                insertStrategy.executeUpdate(ps);

                ++batchCount;
View Full Code Here

TOP

Related Classes of org.jboss.as.cmp.jdbc2.PersistentContext

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.