Example usage for com.liferay.portal.dao.orm.common SQLTransformer transform

List of usage examples for com.liferay.portal.dao.orm.common SQLTransformer transform

Introduction

In this page you can find the example usage for com.liferay.portal.dao.orm.common SQLTransformer transform.

Prototype

public static String transform(String sql) 

Source Link

Usage

From source file:com.liferay.layout.internal.upgrade.v1_0_0.UpgradeLayoutPermissions.java

License:Open Source License

@Override
protected void doUpgrade() throws Exception {
    StringBundler sb = new StringBundler(9);

    sb.append("select Layout.companyId, Layout.plid, Layout.privateLayout");
    sb.append(", Layout.groupId, Layout.userId from Layout left join ");
    sb.append("ResourcePermission on (ResourcePermission.companyId = ");
    sb.append("Layout.companyId and ResourcePermission.name = '");
    sb.append(Layout.class.getName());
    sb.append("' and ResourcePermission.scope = ");
    sb.append(ResourceConstants.SCOPE_INDIVIDUAL);
    sb.append(" and ResourcePermission.primKeyId = Layout.plid) where ");
    sb.append("ResourcePermission.resourcePermissionId is null");

    String sql = SQLTransformer.transform(sb.toString());

    try (LoggingTimer loggingTimer = new LoggingTimer();
            PreparedStatement ps = connection.prepareStatement(sql);
            ResultSet rs = ps.executeQuery()) {

        while (rs.next()) {
            long companyId = rs.getLong("companyId");
            long groupId = rs.getLong("groupId");
            long plid = rs.getLong("plid");
            boolean privateLayout = rs.getBoolean("privateLayout");
            long userId = rs.getLong("userId");

            boolean addGroupPermission = true;
            boolean addGuestPermission = true;

            if (privateLayout) {
                addGuestPermission = false;

                Group group = GroupLocalServiceUtil.getGroup(groupId);

                if (group.isUser() || group.isUserGroup()) {
                    addGroupPermission = false;
                }/*  www .j  av a2 s . c om*/
            }

            ResourceLocalServiceUtil.addResources(companyId, groupId, userId, Layout.class.getName(), plid,
                    false, addGroupPermission, addGuestPermission);
        }
    }
}

From source file:com.liferay.sync.internal.upgrade.v1_0_2.UpgradeSyncDLObject.java

License:Open Source License

protected void verifyLocks(long groupId) throws Exception {
    StringBundler sb = new StringBundler(5);

    sb.append("select Lock_.expirationDate, Lock_.userId, ");
    sb.append("Lock_.userName, DLFileVersion.fileEntryId from ");
    sb.append("DLFileVersion, Lock_ where DLFileVersion.version = '");
    sb.append(DLFileEntryConstants.PRIVATE_WORKING_COPY_VERSION);
    sb.append("' and CAST_TEXT(DLFileVersion.fileEntryId) = Lock_.key_");

    String sql = SQLTransformer.transform(sb.toString());

    try (PreparedStatement ps1 = connection.prepareStatement(sql);
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    StringBundler.concat("update SyncDLObject set lockExpirationDate = ?, ",
                            "lockUserId = ?, lockUserName = ? where typePK = ? ", "and repositoryId = ",
                            String.valueOf(groupId)));
            ResultSet rs = ps1.executeQuery()) {

        while (rs.next()) {
            ps2.setTimestamp(1, rs.getTimestamp("expirationDate"));
            ps2.setLong(2, rs.getLong("userId"));
            ps2.setString(3, rs.getString("userName"));
            ps2.setLong(4, rs.getLong("fileEntryId"));

            ps2.addBatch();/*w w  w  .j a v a2 s .  co m*/
        }

        ps2.executeBatch();
    }
}