Search in sources :

Example 6 with Dialect

use of org.alfresco.repo.domain.dialect.Dialect in project alfresco-repository by Alfresco.

the class SchemaBootstrap method updateSchema.

/**
 * Builds the schema from scratch or applies the necessary patches to the schema.
 */
private boolean updateSchema(Connection connection) throws Exception {
    boolean create = false;
    try {
        final int numberOfPatchesApplied = countAppliedPatches(connection);
        if (logger.isInfoEnabled()) {
            logger.info("Applied patches detected: " + numberOfPatchesApplied);
        }
    } catch (NoSchemaException e) {
        create = true;
    }
    // Get the dialect
    final Dialect dialect = this.dialect;
    String dialectStr = dialect.getClass().getSimpleName();
    if (create) {
        long start = System.currentTimeMillis();
        // execute pre-create scripts (not patches)
        for (String scriptUrl : this.preCreateScriptUrls) {
            executeScriptUrl(connection, scriptUrl);
        }
        // execute post-create scripts (not patches)
        for (String scriptUrl : this.postCreateScriptUrls) {
            executeScriptUrl(connection, scriptUrl);
        }
        if (logger.isInfoEnabled()) {
            logger.info("Creating Alfresco tables took " + (System.currentTimeMillis() - start) + " ms");
        }
    } else {
        long start = System.currentTimeMillis();
        // Execute any pre-auto-update scripts
        checkSchemaPatchScripts(connection, preUpdateScriptPatches, true);
        // Execute any post-auto-update scripts
        checkSchemaPatchScripts(connection, postUpdateScriptPatches, true);
        if (logger.isInfoEnabled()) {
            logger.info("Checking and patching Alfresco tables took " + (System.currentTimeMillis() - start) + " ms");
        }
    }
    ensureCurrentClusterMemberIsBootstrapping(connection);
    // Initialise Activiti DB, using an unclosable connection
    boolean activitiTablesExist = checkActivitiTablesExist(connection);
    if (logger.isInfoEnabled()) {
        logger.info("Activiti tables need to be " + (activitiTablesExist ? "checked for patches" : " created"));
    }
    if (!activitiTablesExist) {
        long start = System.currentTimeMillis();
        ensureCurrentClusterMemberIsBootstrapping(connection);
        // Activiti DB updates are performed as patches in alfresco, only give
        // control to activiti when creating new one.
        initialiseActivitiDBSchema(new UnclosableConnection(connection));
        // ALF-18996: Upgrade from 3.4.12 to 4.2.0 fails: Activiti tables have not been bootstrapped
        // The Activiti bootstrap is effectively doing the work of all the other patches,
        // which should be considered complete.
        int installedSchemaNumber = getInstalledSchemaNumber(connection);
        for (Patch activitiScriptPatch : updateActivitiScriptPatches) {
            AppliedPatch appliedPatch = new AppliedPatch();
            appliedPatch.setId(activitiScriptPatch.getId());
            appliedPatch.setDescription(activitiScriptPatch.getDescription());
            appliedPatch.setFixesFromSchema(activitiScriptPatch.getFixesFromSchema());
            appliedPatch.setFixesToSchema(activitiScriptPatch.getFixesToSchema());
            appliedPatch.setTargetSchema(activitiScriptPatch.getTargetSchema());
            appliedPatch.setAppliedToSchema(installedSchemaNumber);
            appliedPatch.setAppliedToServer("UNKNOWN");
            // the date applied
            appliedPatch.setAppliedOnDate(new Date());
            appliedPatch.setSucceeded(true);
            appliedPatch.setWasExecuted(false);
            appliedPatch.setReport("Placeholder for Activiti bootstrap at schema " + installedSchemaNumber);
            appliedPatchDAO.createAppliedPatch(appliedPatch);
        }
        if (logger.isInfoEnabled()) {
            logger.info("Creating Activiti tables took " + (System.currentTimeMillis() - start) + " ms");
        }
    } else {
        long start = System.currentTimeMillis();
        // Execute any auto-update scripts for Activiti tables
        checkSchemaPatchScripts(connection, updateActivitiScriptPatches, true);
        // verify that all Activiti patches have been applied correctly
        checkSchemaPatchScripts(connection, updateActivitiScriptPatches, false);
        if (logger.isInfoEnabled()) {
            logger.info("Checking and patching Activiti tables took " + (System.currentTimeMillis() - start) + " ms");
        }
    }
    if (!create) {
        long start = System.currentTimeMillis();
        // verify that all patches have been applied correctly
        // check scripts
        checkSchemaPatchScripts(connection, preUpdateScriptPatches, false);
        // check scripts
        checkSchemaPatchScripts(connection, postUpdateScriptPatches, false);
        if (logger.isInfoEnabled()) {
            logger.info("Checking that all patches have been applied took " + (System.currentTimeMillis() - start) + " ms");
        }
    }
    return create;
}
Also used : MySQLInnoDBDialect(org.alfresco.repo.domain.dialect.MySQLInnoDBDialect) Oracle9Dialect(org.alfresco.repo.domain.dialect.Oracle9Dialect) SQLServerDialect(org.alfresco.repo.domain.dialect.SQLServerDialect) PostgreSQLDialect(org.alfresco.repo.domain.dialect.PostgreSQLDialect) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) Dialect(org.alfresco.repo.domain.dialect.Dialect) SchemaUpgradeScriptPatch(org.alfresco.repo.admin.patch.impl.SchemaUpgradeScriptPatch) AppliedPatch(org.alfresco.repo.admin.patch.AppliedPatch) Patch(org.alfresco.repo.admin.patch.Patch) Savepoint(java.sql.Savepoint) Date(java.util.Date) AppliedPatch(org.alfresco.repo.admin.patch.AppliedPatch)

Example 7 with Dialect

use of org.alfresco.repo.domain.dialect.Dialect in project alfresco-repository by Alfresco.

the class ScriptExecutorImpl method executeScriptUrl.

private void executeScriptUrl(Connection connection, String scriptUrl) throws Exception {
    Dialect dialect = this.dialect;
    String dialectStr = dialect.getClass().getSimpleName();
    InputStream scriptInputStream = getScriptInputStream(dialect.getClass(), scriptUrl);
    // check that it exists
    if (scriptInputStream == null) {
        throw AlfrescoRuntimeException.create(ERR_SCRIPT_NOT_FOUND, scriptUrl);
    }
    // write the script to a temp location for future and failure reference
    File tempFile = null;
    try {
        tempFile = TempFileProvider.createTempFile("AlfrescoSchema-" + dialectStr + "-Update-", ".sql");
        ContentWriter writer = new FileContentWriter(tempFile);
        writer.putContent(scriptInputStream);
    } finally {
        // usually a duplicate close
        try {
            scriptInputStream.close();
        } catch (Throwable e) {
        }
    }
    // now execute it
    String dialectScriptUrl = scriptUrl.replaceAll(DialectUtil.PLACEHOLDER_DIALECT, dialect.getClass().getName());
    // Replace the script placeholders
    executeScriptFile(connection, tempFile, dialectScriptUrl);
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileContentWriter(org.alfresco.repo.content.filestore.FileContentWriter) PostgreSQLDialect(org.alfresco.repo.domain.dialect.PostgreSQLDialect) MySQLInnoDBDialect(org.alfresco.repo.domain.dialect.MySQLInnoDBDialect) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) Dialect(org.alfresco.repo.domain.dialect.Dialect) File(java.io.File)

Example 8 with Dialect

use of org.alfresco.repo.domain.dialect.Dialect in project alfresco-repository by Alfresco.

the class AuditDAOTest method testScriptCanDeleteOrphanedProps.

/**
 * MNT-10067: use a script to delete the orphaned audit data (property values).
 */
public void testScriptCanDeleteOrphanedProps() throws Exception {
    Dialect dialect = (Dialect) ctx.getBean("dialect");
    if (dialect instanceof MySQLClusterNDBDialect) {
        throw new Exception("TODO review this test case with NDB - note: throw exeception here else causes later tests to fail (when running via AllDBTestTestSuite)");
    }
    // single test
    scriptCanDeleteOrphanedPropsWork(false);
}
Also used : MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) Dialect(org.alfresco.repo.domain.dialect.Dialect) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 9 with Dialect

use of org.alfresco.repo.domain.dialect.Dialect in project alfresco-repository by Alfresco.

the class FileFolderServiceImplTest method testMoveCopyLotsOfFiles.

public void testMoveCopyLotsOfFiles() throws FileNotFoundException {
    final String CONTAINING_FOLDER = "CONTAINING FOLDER " + GUID.generate(), FOLDER_1 = "FOLDER 1 " + GUID.generate(), FOLDER_2 = "FOLDER 2 " + GUID.generate();
    FileInfo containingFolder = fileFolderService.create(workingRootNodeRef, CONTAINING_FOLDER, ContentModel.TYPE_FOLDER), folder1 = fileFolderService.create(containingFolder.getNodeRef(), FOLDER_1, ContentModel.TYPE_FOLDER), folder2 = fileFolderService.create(containingFolder.getNodeRef(), FOLDER_2, ContentModel.TYPE_FOLDER);
    // create thousand(s) of files within the folder
    int COUNT = 3000;
    Dialect dialect = (Dialect) ctx.getBean("dialect");
    if (dialect instanceof MySQLClusterNDBDialect) {
        // note: to increase the file count on NDB, may need to further bump-up NDB cluster config
        // eg. DataMemory, IndexMemory, MaxNoOfConcurrentOperations, ...
        // also consider splitting into separate txns (eg. after each bulk create, move, delete, copy, ...)
        COUNT = 1000;
    }
    for (int index = 0; index < COUNT; index++) {
        fileFolderService.create(folder1.getNodeRef(), "Name " + index, ContentModel.TYPE_CONTENT);
    }
    assertEquals(COUNT, fileFolderService.listFiles(folder1.getNodeRef()).size());
    assertEquals(0, fileFolderService.list(folder2.getNodeRef()).size());
    // move the folder
    fileFolderService.move(folder1.getNodeRef(), folder2.getNodeRef(), null);
    assertEquals(COUNT, fileFolderService.listFiles(folder1.getNodeRef()).size());
    assertEquals(1, fileFolderService.list(folder2.getNodeRef()).size());
    // move it back
    fileFolderService.move(folder1.getNodeRef(), containingFolder.getNodeRef(), null);
    assertEquals(0, fileFolderService.list(folder2.getNodeRef()).size());
    assertEquals(2, fileFolderService.list(containingFolder.getNodeRef()).size());
    // lets copy it
    fileFolderService.copy(folder1.getNodeRef(), folder2.getNodeRef(), null);
    assertEquals(2, fileFolderService.list(containingFolder.getNodeRef()).size());
    List<FileInfo> folders = fileFolderService.listFolders(folder2.getNodeRef());
    assertEquals(1, folders.size());
    assertEquals(COUNT, fileFolderService.listFiles(folders.get(0).getNodeRef()).size());
    fileFolderService.delete(folder1.getNodeRef());
    assertEquals(1, fileFolderService.list(containingFolder.getNodeRef()).size());
    folder1 = folders.get(0);
    // copy back
    FileInfo newFolder = fileFolderService.copy(folder1.getNodeRef(), containingFolder.getNodeRef(), null);
    assertEquals(2, fileFolderService.list(containingFolder.getNodeRef()).size());
    assertEquals(COUNT, fileFolderService.list(newFolder.getNodeRef()).size());
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) Dialect(org.alfresco.repo.domain.dialect.Dialect)

Example 10 with Dialect

use of org.alfresco.repo.domain.dialect.Dialect in project alfresco-repository by Alfresco.

the class DbNodeServiceImplTest method testMySQLInnoDBNodeStringLengthWorker.

/**
 * Check that the maximum string lengths can be adjusted up and down.
 * Note that this test ONLY works for MySQL because the other databases cannot support more than 1024 characters
 * in the string_value column and the value may not be set to less than 1024.
 *
 * @see SchemaBootstrap#DEFAULT_MAX_STRING_LENGTH
 */
@SuppressWarnings("deprecation")
public void testMySQLInnoDBNodeStringLengthWorker() throws Exception {
    TestTransaction.flagForCommit();
    TestTransaction.end();
    // Skip of the dialect if not MySQL (also skip for MySQL Cluster NDB)
    Dialect dialect = (Dialect) applicationContext.getBean("dialect");
    if ((dialect instanceof MySQLClusterNDBDialect) || (!(dialect instanceof MySQLInnoDBDialect))) {
        return;
    }
    SchemaBootstrap schemaBootstrap = (SchemaBootstrap) applicationContext.getBean("schemaBootstrap");
    assertEquals("Expected max string length to be MAX", Integer.MAX_VALUE, SchemaBootstrap.getMaxStringLength());
    NodeStringLengthWorker worker = (NodeStringLengthWorker) applicationContext.getBean("nodeStringLengthWorker");
    // If we run this worker just to get everything into the correct starting state.
    // If it does not work, then that will be detected later anyway
    NodeStringLengthWorkResult result = worker.execute();
    assertTrue(result.getPropertiesProcessed() > 0);
    assertEquals(0, result.getErrors());
    // Now set the max string length to DEFAULT_MAX_STRING_LENGTH characters
    schemaBootstrap.setMaximumStringLength(SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH);
    schemaBootstrap.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
    // Move any values persisted before the test
    result = worker.execute();
    int firstPassChanged = result.getPropertiesChanged();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH + 1; i++) {
        sb.append("A");
    }
    final String longString = sb.toString();
    // Persist the property using the default MAX_VALUE so that it goes into the string_value
    schemaBootstrap.setMaximumStringLength(Integer.MAX_VALUE);
    schemaBootstrap.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
    txnService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            nodeService.setProperty(rootNodeRef, PROP_QNAME_STRING_VALUE, longString);
            return null;
        }
    });
    // The worker should do nothing
    result = worker.execute();
    assertEquals(firstPassChanged, result.getPropertiesChanged());
    // Now bring the limit down to the match for other DBs
    schemaBootstrap.setMaximumStringLength(SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH);
    schemaBootstrap.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
    result = worker.execute();
    assertEquals(firstPassChanged + 1, result.getPropertiesChanged());
    // Put the limit back to the MySQL default and all the large values should go back into MySQL's TEXT field
    schemaBootstrap.setMaximumStringLength(Integer.MAX_VALUE);
    schemaBootstrap.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
    result = worker.execute();
    assertEquals(firstPassChanged + 1, result.getPropertiesChanged());
    // Check that our string is still OK
    String checkLongString = txnService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>() {

        @Override
        public String execute() throws Throwable {
            return (String) nodeService.getProperty(rootNodeRef, PROP_QNAME_STRING_VALUE);
        }
    });
    assertEquals("String manipulation corrupted the long string value. ", longString, checkLongString);
}
Also used : MySQLInnoDBDialect(org.alfresco.repo.domain.dialect.MySQLInnoDBDialect) SchemaBootstrap(org.alfresco.repo.domain.schema.SchemaBootstrap) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) MySQLInnoDBDialect(org.alfresco.repo.domain.dialect.MySQLInnoDBDialect) MySQLClusterNDBDialect(org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect) Dialect(org.alfresco.repo.domain.dialect.Dialect) NodeStringLengthWorkResult(org.alfresco.repo.node.db.NodeStringLengthWorker.NodeStringLengthWorkResult)

Aggregations

Dialect (org.alfresco.repo.domain.dialect.Dialect)10 MySQLClusterNDBDialect (org.alfresco.repo.domain.dialect.MySQLClusterNDBDialect)8 MySQLInnoDBDialect (org.alfresco.repo.domain.dialect.MySQLInnoDBDialect)7 PostgreSQLDialect (org.alfresco.repo.domain.dialect.PostgreSQLDialect)6 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 SQLServerDialect (org.alfresco.repo.domain.dialect.SQLServerDialect)4 Oracle9Dialect (org.alfresco.repo.domain.dialect.Oracle9Dialect)3 BufferedInputStream (java.io.BufferedInputStream)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 Savepoint (java.sql.Savepoint)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 FileContentWriter (org.alfresco.repo.content.filestore.FileContentWriter)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1