Search in sources :

Example 1 with JdbcTransaction

use of com.fathomdb.jdbc.JdbcTransaction in project platformlayer by platformlayer.

the class JdbcJobRepository method recordJobEnd.

@Override
@JdbcTransaction
public void recordJobEnd(PlatformLayerKey jobKey, String executionId, Date endedAt, JobState state, String logCookie) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        ProjectId project = jobKey.getProject();
        String jobId = jobKey.getItemIdString();
        int projectId = db.mapToValue(project);
        int updateCount = db.queries.updateExecution(logCookie, endedAt, state, projectId, jobId, executionId);
        if (updateCount != 1) {
            throw new RepositoryException("Unexpected number of rows updated");
        }
        updateCount = db.queries.updateJob(endedAt, state, executionId, projectId, jobId);
        if (updateCount != 1) {
            throw new RepositoryException("Unexpected number of rows updated");
        }
    } catch (SQLException e) {
        throw new RepositoryException("Error updating job execution", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 2 with JdbcTransaction

use of com.fathomdb.jdbc.JdbcTransaction in project platformlayer by platformlayer.

the class JdbcJobRepository method findJob.

@Override
@JdbcTransaction
public JobData findJob(PlatformLayerKey jobKey) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        ProjectId projectId = jobKey.getProject();
        String jobId = jobKey.getItemIdString();
        JobEntity execution = db.queries.findJob(db.mapToValue(projectId), jobId);
        if (execution == null) {
            return null;
        }
        return mapFromEntity(execution, jobKey);
    } catch (SQLException e) {
        throw new RepositoryException("Error listing job executions", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 3 with JdbcTransaction

use of com.fathomdb.jdbc.JdbcTransaction in project platformlayer by platformlayer.

the class JdbcJobRepository method insertJob.

@Override
@JdbcTransaction
public String insertJob(ProjectId projectId, JobData jobData) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        String jobId = UUID.randomUUID().toString();
        JobEntity entity = new JobEntity();
        entity.project = db.mapToValue(projectId);
        entity.jobId = jobId;
        entity.actionXml = toXml(jobData.action);
        entity.target = jobData.targetId.getUrl();
        int updateCount = db.queries.insert(entity);
        if (updateCount != 1) {
            throw new RepositoryException("Unexpected number of rows inserted");
        }
        return jobId;
    } catch (SQLException e) {
        throw new RepositoryException("Error inserting job execution", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 4 with JdbcTransaction

use of com.fathomdb.jdbc.JdbcTransaction in project platformlayer by platformlayer.

the class JdbcUserRepository method listProjectsByUserId.

@Override
@JdbcTransaction
public List<ProjectEntity> listProjectsByUserId(int userId) throws RepositoryException {
    DbHelper db = new DbHelper();
    try {
        List<ProjectEntity> projects = Lists.newArrayList();
        projects.addAll(db.findProjectsByUserId(userId));
        return projects;
    } catch (SQLException e) {
        throw new RepositoryException("Error reading groups", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Example 5 with JdbcTransaction

use of com.fathomdb.jdbc.JdbcTransaction in project platformlayer by platformlayer.

the class JdbcUserRepository method listAllProjectNames.

@Override
@JdbcTransaction
public List<String> listAllProjectNames(String prefix) throws RepositoryException {
    String match;
    if (prefix == null) {
        match = "%";
    } else {
        match = prefix + "%";
    }
    DbHelper db = new DbHelper();
    try {
        return db.listProjects(match);
    } catch (SQLException e) {
        throw new RepositoryException("Error listing projects", e);
    } finally {
        db.close();
    }
}
Also used : SQLException(java.sql.SQLException) RepositoryException(org.platformlayer.RepositoryException) JdbcTransaction(com.fathomdb.jdbc.JdbcTransaction)

Aggregations

JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)30 SQLException (java.sql.SQLException)30 RepositoryException (org.platformlayer.RepositoryException)30 ProjectId (org.platformlayer.ids.ProjectId)7 CryptoKey (com.fathomdb.crypto.CryptoKey)6 AesCryptoKey (com.fathomdb.crypto.AesCryptoKey)4 IOException (java.io.IOException)4 SecretStore (org.platformlayer.auth.crypto.SecretStore)4 Writer (org.platformlayer.auth.crypto.SecretStore.Writer)4 JoinedQueryResult (com.fathomdb.jpa.impl.JoinedQueryResult)3 PublicKey (java.security.PublicKey)3 ResultSet (java.sql.ResultSet)3 Tag (org.platformlayer.core.model.Tag)3 ManagedItemId (org.platformlayer.ids.ManagedItemId)3 JdbcConnection (com.fathomdb.jdbc.JdbcConnection)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 KeyPair (java.security.KeyPair)2 X509Certificate (java.security.cert.X509Certificate)2 PreparedStatement (java.sql.PreparedStatement)2 ItemBase (org.platformlayer.core.model.ItemBase)2