Skip to content

Commit

Permalink
#24093 Working on the migration task to populate missing contentlet a…
Browse files Browse the repository at this point in the history
…s JSON data
  • Loading branch information
jgambarios committed Mar 24, 2023
1 parent 81da8ee commit b5bf377
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.dotcms.util.content.json;

import com.dotcms.IntegrationTestBase;
import com.dotmarketing.exception.DotDataException;
import org.junit.Test;

import java.io.IOException;
import java.sql.SQLException;

public class PopulateContentletAsJSONUtilTest {
public class PopulateContentletAsJSONUtilTest extends IntegrationTestBase {

@Test
public void Test_Run() throws SQLException, DotDataException, IOException {
PopulateContentletAsJSONUtil.getInstance().run("Host");
PopulateContentletAsJSONUtil.getInstance().populate("Host");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotcms.util.content.json;

import com.dotcms.business.CloseDBIfOpened;
import com.dotcms.business.WrapInTransaction;
import com.dotcms.content.business.json.ContentletJsonAPI;
import com.dotcms.content.business.json.ContentletJsonHelper;
Expand Down Expand Up @@ -62,7 +63,8 @@ public class PopulateContentletAsJSONUtil {

// Cursor related queries
private final String DECLARE_CURSOR = "DECLARE missingContentletAsJSONCursor CURSOR FOR %s";
private final String FETCH_CURSOR = "FETCH FORWARD 100 FROM missingContentletAsJSONCursor";
private final String FETCH_CURSOR_POSTGRES = "FETCH FORWARD 100 FROM missingContentletAsJSONCursor";
private final String FETCH_CURSOR_MSSQL = "FETCH NEXT 100 FROM missingContentletAsJSONCursor";
private final String CLOSE_CURSOR = "CLOSE missingContentletAsJSONCursor";

private static class SingletonHolder {
Expand All @@ -87,6 +89,16 @@ private interface CheckedConsumer<T, E extends Exception> {
void accept(T t) throws E;
}

/**
* Finds all the contentlets that need to be updated with the contentlet_as_json column for a given
* optional assetSubtype (Content Type).
*
* @param assetSubtype Optional assetSubtype (Content Type) to filter the contentlets to process, if null then all
* the contentlets will be processed.
* @throws SQLException
* @throws DotDataException
* @throws IOException
*/
@WrapInTransaction
public void populate(@Nullable String assetSubtype) throws SQLException, DotDataException, IOException {

Expand Down Expand Up @@ -134,6 +146,7 @@ private void processFile(final File taskDataFile) throws IOException {
* @throws DotDataException
* @throws IOException
*/
@CloseDBIfOpened
private void findAndStoreToDisk(@Nullable String assetSubtype,
final File populateJSONTaskDataFile) throws
SQLException, DotDataException, IOException {
Expand All @@ -154,7 +167,12 @@ private void findAndStoreToDisk(@Nullable String assetSubtype,

do {

stmt.execute(FETCH_CURSOR);// Fetching batches of 100 records
// Fetching batches of 100 records
if (DbConnectionFactory.isMsSql()) {
stmt.execute(FETCH_CURSOR_MSSQL);
} else {
stmt.execute(FETCH_CURSOR_POSTGRES);
}

try (ResultSet rs = stmt.getResultSet()) {

Expand Down

0 comments on commit b5bf377

Please sign in to comment.