Package org.jboss.dashboard.database.hibernate

Examples of org.jboss.dashboard.database.hibernate.HibernateTxFragment


        }
    }

    protected void processTheView(final HttpServletRequest request, final HttpServletResponse response) {
        try {
            new HibernateTxFragment() {
            protected void txFragment(Session session) throws Exception {
                if (log.isDebugEnabled()) log.debug("Rendering response. Id=" + Thread.currentThread().getName());
                RequestChainProcessor renderingProcessor = (RequestChainProcessor) Factory.lookup("org.jboss.dashboard.ui.controller.requestChain.StartingRenderer");
                renderingProcessor.doRequestProcessing();
            }}.execute();
View Full Code Here


    public Section doGetCurrentSection() {
        if (getCurrentSectionId() == null)
            return null;
        try {
            final Section[] sectionToReturn = new Section[]{null};
            new HibernateTxFragment() {
                protected void txFragment(Session session) throws Exception {
                    sectionToReturn[0] = (Section) session.get(Section.class, getCurrentSectionId());
                }
            }.execute();
            return sectionToReturn[0];
View Full Code Here

        return dbid != null;
    }

    public boolean save() throws Exception {
        final boolean isTransient = !isPersistent();
        new HibernateTxFragment() {
            protected void txFragment(Session session) throws Exception {
                if (isTransient) persist(0);
                else persist(1);
            }}.execute();
        return isTransient;
View Full Code Here

        persist(2);
        return true;
    }

    protected void persist(final int op) throws Exception {
        new HibernateTxFragment() {
        protected void txFragment(Session session) throws Exception {
            switch(op) {
                case 0: session.save(PermissionDescriptor.this);
                    break;
                case 1: session.update(PermissionDescriptor.this);
View Full Code Here

    /**
     * Find the permission descriptor for given principal and permission
     */
    public PermissionDescriptor find(final Principal prpal, final Permission perm) {
        final List results = new ArrayList(1);
        HibernateTxFragment txFragment = new HibernateTxFragment() {
            protected void txFragment(Session session) throws Exception {
                StringBuffer buf = new StringBuffer();
                buf.append(" from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null ");
                if (prpal != null) {
                    buf.append(" and item.principalClass = :principalClass  ");
                    buf.append(" and item.principalName =  :principalName  ");
                }
                buf.append("and item.permissionClass = :permissionClass and item.permissionResource = :permissionResource");
                Query query = session.createQuery(buf.toString());
                if (prpal != null) {
                    query.setString("principalClass", prpal.getClass().getName());
                    query.setString("principalName", prpal.getName());
                }
                query.setString("permissionClass", perm.getClass().getName());
                query.setString("permissionResource", perm.getName());
                query.setCacheable(true);
                FlushMode oldFlushMode = session.getFlushMode();
                session.setFlushMode(FlushMode.NEVER);
                results.addAll(query.list());
                session.setFlushMode(oldFlushMode);
            }
        };

        try {
            txFragment.execute();
            if (!results.isEmpty())
                return (PermissionDescriptor) results.get(0);
            else
                return null;
        } catch (Exception e) {
View Full Code Here

    /**
     * Recover the Permissions for the given permission resource name
     */
    public List<PermissionDescriptor> find(final String resourceName) throws Exception {
        final List results = new ArrayList();
        new HibernateTxFragment() {
        protected void txFragment(Session session) throws Exception {
            StringBuffer buf = new StringBuffer();
            buf.append(" from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null ");
            if (!StringUtils.isBlank(resourceName)) buf.append(" and item.permissionResource = :res1 or  item.permissionResource = :res2");
            Query query = session.createQuery(buf.toString());
View Full Code Here

    /**
     * Recover Permissions for the given permission class and resource name, including or excluding the ones marked as readonly
     */
    public List<PermissionDescriptor> find(final String permissionClass, final String permissionResource, final Boolean includeReadOnly) {
        final List<PermissionDescriptor> results = new ArrayList<PermissionDescriptor>(10);
        HibernateTxFragment txFragment = new HibernateTxFragment() {
            protected void txFragment(Session session) throws Exception {
                StringBuffer buf = new StringBuffer(" from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null ");
                buf.append("and item.permissionClass = :permissionClass and item.permissionResource = :permissionResource");
                if (!includeReadOnly) buf.append(" and item.readonly = :readonly");
                Query query = session.createQuery(buf.toString());
                query.setString("permissionClass", permissionClass);
                query.setString("permissionResource", permissionResource);
                if (!includeReadOnly) query.setBoolean("readonly", includeReadOnly);
                query.setCacheable(true);
                FlushMode oldFlushMode = session.getFlushMode();
                session.setFlushMode(FlushMode.NEVER);
                results.addAll(query.list());
                session.setFlushMode(oldFlushMode);
            }
        };
        try {
            txFragment.execute();
        } catch (Exception e) {
            log.error("Error retrieving PermissionDescriptors for permission class "  + permissionClass + " and resource " + permissionResource, e);
        }
        return results;
    }
View Full Code Here

     * Recover a Permission by its Id
     */
    public PermissionDescriptor findPermissionDescriptorById(final Long idPermission) {
        final List<PermissionDescriptor> result = new ArrayList<PermissionDescriptor>(1);
        try {
            new HibernateTxFragment() {
                protected void txFragment(Session session) throws Exception {
                    String sql = new String(" from " + PermissionDescriptor.class.getName() + " as item where item.dbid = :dbid");
                    Query query = session.createQuery(sql);
                    query.setLong("dbid", idPermission);
                    FlushMode oldFlushMode = session.getFlushMode();
View Full Code Here

            for (int i = 0; i < permissionIds.size(); i++) {
                idString.append(permissionIds.get(i));
                if (i != permissionIds.size()-1) idString.append(",");
            }
            idString.append(")");
            HibernateTxFragment txFragment = new HibernateTxFragment() {
                protected void txFragment(Session session) throws Exception {
                    Query query = session.createQuery(idString.toString());
                    FlushMode oldFlushMode = session.getFlushMode();
                    session.setFlushMode(FlushMode.NEVER);
                    results.addAll(query.list());
                    session.setFlushMode(oldFlushMode);
                }
            };
            try {
                txFragment.execute();
            } catch (Exception e) {
                log.error("Error deleting PermissionDescriptors with dbids in ("  + idString + ")", e);
            }
        }
        return results;
View Full Code Here

        return CDIBeanLocator.getBeanByType(DataSourceTableManager.class);
    }

     public List<DataSourceTableEntry> getSelectedTablesEntries(final String datasource) throws Exception {
        final List<DataSourceTableEntry> existingEntries = new ArrayList<DataSourceTableEntry>();
        new HibernateTxFragment() {
            protected void txFragment(Session session) throws Exception {
                Query query = session.createQuery(" from " + DataSourceTableEntry.class.getName() + " entry where entry.datasource = :datasource");
                query.setString("datasource", datasource);
                query.setCacheable(true);
                FlushMode oldFlushMode = session.getFlushMode();
View Full Code Here

TOP

Related Classes of org.jboss.dashboard.database.hibernate.HibernateTxFragment

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.