Example usage for com.liferay.portal.kernel.dao.jdbc AutoBatchPreparedStatementUtil concurrentAutoBatch

List of usage examples for com.liferay.portal.kernel.dao.jdbc AutoBatchPreparedStatementUtil concurrentAutoBatch

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.jdbc AutoBatchPreparedStatementUtil concurrentAutoBatch.

Prototype

public static PreparedStatement concurrentAutoBatch(Connection connection, String sql) throws SQLException 

Source Link

Usage

From source file:com.liferay.asset.entry.rel.internal.upgrade.v1_0_0.UpgradeAssetEntryAssetCategoryRel.java

License:Open Source License

protected void addAssetEntryAssetCategoryRels() throws Exception {
    StringBundler sb = new StringBundler(3);

    sb.append("insert into AssetEntryAssetCategoryRel (");
    sb.append("assetEntryAssetCategoryRelId, assetEntryId, ");
    sb.append("assetCategoryId) values (?, ?, ?)");

    try (PreparedStatement ps1 = connection.prepareStatement("select * from AssetEntries_AssetCategories");
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    sb.toString());//from  ww w . j a va 2s.  c  o m
            ResultSet rs = ps1.executeQuery()) {

        while (rs.next()) {
            long assetEntryId = rs.getLong("entryId");
            long assetCategoryId = rs.getLong("categoryId");

            ps2.setLong(1, increment());
            ps2.setLong(2, assetEntryId);
            ps2.setLong(3, assetCategoryId);

            ps2.executeUpdate();
        }

        ps2.executeBatch();
    }
}

From source file:com.liferay.dynamic.data.lists.internal.upgrade.v1_0_4.UpgradeDDLRecord.java

License:Open Source License

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

    sb.append("select DDLRecord.recordId, DDLRecordSet.version ");
    sb.append("from DDLRecord inner join DDLRecordSet on ");
    sb.append("DDLRecord.recordSetId = DDLRecordSet.recordSetId ");

    try (PreparedStatement ps1 = connection.prepareStatement(sb.toString());
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDLRecord set recordSetVersion = ? where " + "recordId = ?")) {

        try (ResultSet rs = ps1.executeQuery()) {
            while (rs.next()) {
                long recordId = rs.getLong(1);

                String version = rs.getString(2);

                ps2.setString(1, version);

                ps2.setLong(2, recordId);

                ps2.addBatch();//from www. ja  va2 s  . co  m
            }

            ps2.executeBatch();
        }
    }
}

From source file:com.liferay.dynamic.data.lists.internal.upgrade.v1_0_4.UpgradeDDLRecordVersion.java

License:Open Source License

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

    sb.append("select DDLRecordVersion.recordVersionId, DDLRecordSet.version ");
    sb.append("from DDLRecordVersion inner join DDLRecordSet on ");
    sb.append("DDLRecordVersion.recordSetId = DDLRecordSet.recordSetId ");

    try (PreparedStatement ps1 = connection.prepareStatement(sb.toString());
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDLRecordVersion set recordSetVersion = ? where " + "recordVersionId = ?")) {

        try (ResultSet rs = ps1.executeQuery()) {
            while (rs.next()) {
                long recordVersionId = rs.getLong(1);

                String version = rs.getString(2);

                ps2.setString(1, version);

                ps2.setLong(2, recordVersionId);

                ps2.addBatch();//from  ww w. j a  va  2s.c  o m
            }

            ps2.executeBatch();
        }
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_2.UpgradeCheckboxFieldToCheckboxMultipleField.java

License:Open Source License

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

    sb.append("select DDMStructure.definition, DDLRecordSet.recordSetId, ");
    sb.append("DDMStructure.structureId from DDLRecordSet inner join ");
    sb.append("DDMStructure on DDLRecordSet.DDMStructureId = ");
    sb.append("DDMStructure.structureId where DDLRecordSet.scope = ? and ");
    sb.append("DDMStructure.definition like ?");

    try (PreparedStatement ps1 = connection.prepareStatement(sb.toString());
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDMStructure set definition = ? where " + "structureId = ?")) {

        ps1.setInt(1, _SCOPE_FORMS);//from w  ww  .  j  a v  a 2 s  . com
        ps1.setString(2, "%checkbox%");

        try (ResultSet rs = ps1.executeQuery()) {
            while (rs.next()) {
                String definition = rs.getString(1);
                long recordSetId = rs.getLong(2);
                long structureId = rs.getLong(3);

                String newDefinition = upgradeRecordSetStructureDefinition(definition);

                ps2.setString(1, newDefinition);

                ps2.setLong(2, structureId);

                ps2.addBatch();

                DDMForm ddmForm = _ddmFormJSONDeserializer.deserialize(definition);

                updateRecords(ddmForm, recordSetId);
            }

            ps2.executeBatch();
        }
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_2.UpgradeCheckboxFieldToCheckboxMultipleField.java

License:Open Source License

protected void updateRecords(DDMForm ddmForm, long recordSetId) throws Exception {

    StringBundler sb = new StringBundler(7);

    sb.append("select DDLRecordVersion.ddmStorageId, DDMContent.data_ ");
    sb.append("from DDLRecordVersion inner join DDLRecordSet on ");
    sb.append("DDLRecordVersion.recordSetId = DDLRecordSet.recordSetId ");
    sb.append("inner join DDMContent on DDLRecordVersion.DDMStorageId = ");
    sb.append("DDMContent.contentId where DDLRecordSet.recordSetId = ? ");

    try (PreparedStatement ps1 = connection.prepareStatement(sb.toString());
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDMContent set data_= ? where contentId = ? ")) {

        ps1.setLong(1, recordSetId);//from   w  ww  .  j a  va2 s  .  c  o  m

        try (ResultSet rs = ps1.executeQuery()) {
            while (rs.next()) {
                long contentId = rs.getLong("ddmStorageId");
                String data_ = rs.getString("data_");

                DDMFormValues ddmFormValues = _ddmFormValuesJSONDeserializer.deserialize(ddmForm, data_);

                transformCheckboxDDMFormFieldValues(ddmFormValues);

                ps2.setString(1, _ddmFormValuesJSONSerializer.serialize(ddmFormValues));

                ps2.setLong(2, contentId);

                ps2.addBatch();
            }

            ps2.executeBatch();
        }
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_2.UpgradeDataProviderInstance.java

License:Open Source License

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

    sb.append("select DDMDataProviderInstance.definition, ");
    sb.append("DDMDataProviderInstance.dataProviderInstanceId ");
    sb.append("from DDMDataProviderInstance");

    try (PreparedStatement ps1 = connection.prepareStatement(sb.toString());
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDMDataProviderInstance set definition = ? where "
                            + "dataProviderInstanceId = ?")) {

        try (ResultSet rs = ps1.executeQuery()) {
            while (rs.next()) {
                String definition = rs.getString(1);
                long dataProviderInstanceId = rs.getLong(2);

                String newDefinition = upgradeDataProviderInstanceDefinition(definition);

                ps2.setString(1, newDefinition);

                ps2.setLong(2, dataProviderInstanceId);

                ps2.addBatch();//from  www .j a v a  2 s  . c  o m
            }

            ps2.executeBatch();
        }
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_2.UpgradeDDMStructure.java

License:Open Source License

protected void upgradeDDMStructureDefinition() throws Exception {
    StringBundler sb = new StringBundler(2);

    sb.append("select DDMStructure.definition, DDMStructure.structureId ");
    sb.append("from DDMStructure");

    try (PreparedStatement ps1 = connection.prepareStatement(sb.toString());
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDMStructure set definition = ? where " + "structureId = ?")) {

        try (ResultSet rs = ps1.executeQuery()) {
            while (rs.next()) {
                String definition = rs.getString(1);
                long structureId = rs.getLong(2);

                String newDefinition = updateDefinition(definition);

                ps2.setString(1, newDefinition);

                ps2.setLong(2, structureId);

                ps2.addBatch();/*ww  w  .  j a v  a 2 s.c o m*/
            }

            ps2.executeBatch();
        }
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_2.UpgradeDDMStructure.java

License:Open Source License

protected void upgradeDDMStructureVersionDefinition() throws Exception {
    StringBundler sb = new StringBundler(3);

    sb.append("select DDMStructureVersion.definition, ");
    sb.append("DDMStructureVersion.structureVersionId ");
    sb.append("from DDMStructureVersion");

    try (PreparedStatement ps1 = connection.prepareStatement(sb.toString());
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDMStructureVersion set definition = ? where " + "structureVersionId = ?")) {

        try (ResultSet rs = ps1.executeQuery()) {
            while (rs.next()) {
                String definition = rs.getString(1);
                long structureVersionId = rs.getLong(2);

                String newDefinition = updateDefinition(definition);

                ps2.setString(1, newDefinition);

                ps2.setLong(2, structureVersionId);

                ps2.addBatch();//ww w. j  av  a  2 s. c om
            }

            ps2.executeBatch();
        }
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_3.UpgradeDataProviderInstance.java

License:Open Source License

@Override
protected void doUpgrade() throws Exception {
    try (PreparedStatement ps1 = connection
            .prepareStatement("select dataProviderInstanceId, definition from " + "DDMDataProviderInstance");
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDMDataProviderInstance set definition = ? where " + "dataProviderInstanceId = ?");
            ResultSet rs = ps1.executeQuery()) {

        while (rs.next()) {
            long dataProviderInstanceId = rs.getLong(1);
            String dataProviderInstanceDefinition = rs.getString(2);

            String newDefinition = upgradeDataProviderInstanceDefinition(dataProviderInstanceDefinition);

            ps2.setString(1, newDefinition);

            ps2.setLong(2, dataProviderInstanceId);

            ps2.addBatch();//from  w w w .  j a va 2  s.  c o m
        }

        ps2.executeBatch();
    }
}

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_3.UpgradeDDMFormFieldSettings.java

License:Open Source License

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

    sb.append("select DDMStructure.structureId, DDMStructure.definition ");
    sb.append("from DDLRecordSet inner join DDMStructure on ");
    sb.append("DDLRecordSet.DDMStructureId = DDMStructure.structureId ");
    sb.append("where DDLRecordSet.scope = ? and DDMStructure.definition ");
    sb.append("like ?");

    try (PreparedStatement ps1 = connection.prepareStatement(sb.toString());
            PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection,
                    "update DDMStructure set definition = ? where " + "structureId = ?")) {

        ps1.setInt(1, _SCOPE_FORMS);/*from  w w  w  . j  av a2 s  . co m*/
        ps1.setString(2, "%ddmDataProviderInstanceId%");

        try (ResultSet rs = ps1.executeQuery()) {
            while (rs.next()) {
                long structureId = rs.getLong(1);
                String definition = rs.getString(2);

                String newDefinition = upgradeRecordSetStructure(definition);

                ps2.setString(1, newDefinition);

                ps2.setLong(2, structureId);

                ps2.addBatch();
            }

            ps2.executeBatch();
        }
    }
}