Search in sources :

Example 6 with DBParam

use of net.java.ao.DBParam in project stash-codesearch-plugin by palantir.

the class SettingsManagerImpl method getRepositorySettings.

@Override
public RepositorySettings getRepositorySettings(Repository repository) {
    String repoId = repository.getProject().getKey() + "^" + repository.getSlug();
    RepositorySettings[] settings;
    synchronized (ao) {
        settings = ao.find(RepositorySettings.class, Query.select().where("REPOSITORY_ID = ?", repoId));
    }
    if (settings.length > 0) {
        return settings[0];
    }
    synchronized (ao) {
        return ao.create(RepositorySettings.class, new DBParam("REPOSITORY_ID", repoId));
    }
}
Also used : DBParam(net.java.ao.DBParam)

Example 7 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class ConfigurationV2UpgradeTask method upgrade.

/* This is safe to do because the ao.migrate() API uses varargs with a templated type
     * and there's no way around that, but it's just classes and how the API works, so I
     * think it's safe.
     */
@SuppressWarnings("unchecked")
@Override
public void upgrade(ModelVersion currentVersion, ActiveObjects ao) {
    if (!currentVersion.isSame(ModelVersion.valueOf("1"))) {
        throw new IllegalStateException("ConfigurationV2UpgradeTask can only upgrade from version 1");
    }
    // Migrate the old table to base the info off it.
    ao.migrate(RepositoryConfiguration.class);
    // Migrate the new table so we can populate it
    ao.migrate(JobTypeStatusMapping.class);
    for (RepositoryConfiguration rc : ao.find(RepositoryConfiguration.class)) {
        for (JobType jt : ImmutableList.of(JobType.PUBLISH, JobType.VERIFY_COMMIT, JobType.VERIFY_PR)) {
            ao.create(JobTypeStatusMapping.class, new DBParam("REPO_CONFIG_ID", rc.getID()), new DBParam("IS_ENABLED", true), new DBParam("JOB_TYPE_RAW", jt.name()));
        }
    }
}
Also used : JobType(com.palantir.stash.stashbot.jobtemplate.JobType) DBParam(net.java.ao.DBParam) RepositoryConfiguration(com.palantir.stash.stashbot.persistence.RepositoryConfiguration)

Example 8 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class JobTemplateManager method setJobTemplate.

public void setJobTemplate(String name, String templateFile, JobType jenkinsJobType) throws SQLException {
    JobTemplate[] jobs = ao.find(JobTemplate.class, Query.select().where("NAME = ?", name));
    if (jobs.length == 0) {
        log.info("Creating jenkins job template: " + name);
        ao.create(JobTemplate.class, new DBParam("NAME", name), new DBParam("TEMPLATE_FILE", templateFile), new DBParam("JOB_TYPE", jenkinsJobType));
        return;
    }
    // already exists, so update it
    jobs[0].setTemplateFile(templateFile);
    jobs[0].setJobType(jenkinsJobType);
    jobs[0].save();
}
Also used : DBParam(net.java.ao.DBParam) JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate)

Example 9 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class JobTemplateManager method getDefaultPublishJob.

public JobTemplate getDefaultPublishJob() {
    JobTemplate[] jobs = ao.find(JobTemplate.class, Query.select().where("NAME = ?", DEFAULT_PUBLISH_JOB_NAME));
    if (jobs.length == 1) {
        return jobs[0];
    }
    // Create the default verify job
    JobTemplate jjt = ao.create(JobTemplate.class, new DBParam("NAME", DEFAULT_PUBLISH_JOB_NAME), new DBParam("TEMPLATE_FILE", DEFAULT_PUBLISH_JOB_FILE), new DBParam("JOB_TYPE", JobType.PUBLISH));
    jjt.save();
    return jjt;
}
Also used : DBParam(net.java.ao.DBParam) JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate)

Example 10 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class JobTemplateManager method setJenkinsJobMapping.

public void setJenkinsJobMapping(RepositoryConfiguration rc, JobTemplate jjt, Boolean isVisible, Boolean isEnabled) throws SQLException {
    JobMapping[] mappings = ao.find(JobMapping.class, Query.select().where("REPOSITORY_CONFIGURATION_ID = ? and JOB_TEMPLATE_ID = ?", rc.getID(), jjt.getID()));
    if (mappings.length == 0) {
        // just use the defaults
        JobMapping jjm = ao.create(JobMapping.class, new DBParam("REPOSITORY_CONFIGURATION_ID", rc.getID()), new DBParam("JOB_TEMPLATE_ID", jjt.getID()));
        if (isVisible != null) {
            jjm.setVisible(isVisible);
        }
        if (isEnabled != null) {
            jjm.setEnabled(isEnabled);
        }
        jjm.save();
    }
}
Also used : DBParam(net.java.ao.DBParam) JobMapping(com.palantir.stash.stashbot.persistence.JobMapping)

Aggregations

DBParam (net.java.ao.DBParam)16 JobTemplate (com.palantir.stash.stashbot.persistence.JobTemplate)4 JenkinsServerConfiguration (com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration)3 RepositoryConfiguration (com.palantir.stash.stashbot.persistence.RepositoryConfiguration)3 PullRequestMetadata (com.palantir.stash.stashbot.persistence.PullRequestMetadata)2 SearchUpdater (com.palantir.stash.codesearch.updater.SearchUpdater)1 JobType (com.palantir.stash.stashbot.jobtemplate.JobType)1 JobMapping (com.palantir.stash.stashbot.persistence.JobMapping)1 Test (org.junit.Test)1