List<CommitPropertyDTO> findCommitPropertiesOfSnaphots(Collection<Long> commitPKs, Session session) { if (commitPKs.isEmpty()) { return Collections.emptyList(); } return session.select(COMMIT_PROPERTY_COMMIT_FK + ", " + COMMIT_PROPERTY_NAME + ", " + COMMIT_PROPERTY_VALUE) .from(tableNameProvider.getCommitPropertyTableNameWithSchema()) .queryName("commit properties") .and(COMMIT_PROPERTY_COMMIT_FK + " in (" + Joiner.on(",").join(commitPKs) + ")") .executeQuery(resultSet -> new CommitPropertyDTO( resultSet.getLong(COMMIT_PROPERTY_COMMIT_FK), resultSet.getString(COMMIT_PROPERTY_NAME), resultSet.getString(COMMIT_PROPERTY_VALUE))); } }
List<CommitPropertyDTO> findCommitPropertiesOfSnaphots(Collection<Long> commitPKs, Session session) { if (commitPKs.isEmpty()) { return Collections.emptyList(); } return session.select(COMMIT_PROPERTY_COMMIT_FK + ", " + COMMIT_PROPERTY_NAME + ", " + COMMIT_PROPERTY_VALUE) .from(tableNameProvider.getCommitPropertyTableNameWithSchema()) .queryName("commit properties") .and(COMMIT_PROPERTY_COMMIT_FK + " in (" + Joiner.on(",").join(commitPKs) + ")") .executeQuery(resultSet -> new CommitPropertyDTO( resultSet.getLong(COMMIT_PROPERTY_COMMIT_FK), resultSet.getString(COMMIT_PROPERTY_NAME), resultSet.getString(COMMIT_PROPERTY_VALUE))); } }
private Optional<Long> selectMaxSnapshotPrimaryKey(long globalIdPk, Session session) { Optional<Long> maxPrimaryKey = session .select("MAX(" + SNAPSHOT_PK + ")") .from(tableNameProvider.getSnapshotTableNameWithSchema()) .and(SNAPSHOT_GLOBAL_ID_FK, globalIdPk) .queryName("select max snapshot's PK") .queryForOptionalLong(); if (maxPrimaryKey.isPresent() && maxPrimaryKey.get() == 0){ return Optional.empty(); } return maxPrimaryKey; }
private Optional<Long> selectMaxSnapshotPrimaryKey(long globalIdPk, Session session) { Optional<Long> maxPrimaryKey = session .select("MAX(" + SNAPSHOT_PK + ")") .from(tableNameProvider.getSnapshotTableNameWithSchema()) .and(SNAPSHOT_GLOBAL_ID_FK, globalIdPk) .queryName("select max snapshot's PK") .queryForOptionalLong(); if (maxPrimaryKey.isPresent() && maxPrimaryKey.get() == 0){ return Optional.empty(); } return maxPrimaryKey; }
private Optional<BigDecimal> selectMaxCommitId(Session session) { return session.select("MAX(" + COMMIT_COMMIT_ID + ")") .from(getCommitTableNameWithSchema()) .queryForOptionalBigDecimal("max CommitId"); } }
private Optional<BigDecimal> selectMaxCommitId(Session session) { return session.select("MAX(" + COMMIT_COMMIT_ID + ")") .from(getCommitTableNameWithSchema()) .queryForOptionalBigDecimal("max CommitId"); } }
boolean isCommitPersisted(CommitId commitId, Session session) { long count = session.select("count(*)") .from(getCommitTableNameWithSchema()) .and(COMMIT_COMMIT_ID, commitId.valueAsNumber()) .queryForLong("isCommitPersisted"); return count > 0; }
boolean isCommitPersisted(CommitId commitId, Session session) { long count = session.select("count(*)") .from(getCommitTableNameWithSchema()) .and(COMMIT_COMMIT_ID, commitId.valueAsNumber()) .queryForLong("isCommitPersisted"); return count > 0; }
public SnapshotQuery(TableNameProvider tableNames, QueryParams queryParams, Session session) { this.selectBuilder = session .select( SNAPSHOT_STATE + ", " + SNAPSHOT_TYPE + ", " + SNAPSHOT_VERSION + ", " + SNAPSHOT_CHANGED + ", " + SNAPSHOT_MANAGED_TYPE + ", " + COMMIT_PK + ", " + COMMIT_AUTHOR + ", " + COMMIT_COMMIT_DATE + ", " + COMMIT_COMMIT_DATE_INSTANT + ", " + COMMIT_COMMIT_ID + ", " + "g." + GLOBAL_ID_LOCAL_ID + ", " + "g." + GLOBAL_ID_FRAGMENT + ", " + "g." + GLOBAL_ID_OWNER_ID_FK + ", " + "o." + GLOBAL_ID_LOCAL_ID + " owner_" + GLOBAL_ID_LOCAL_ID + ", " + "o." + GLOBAL_ID_FRAGMENT + " owner_" + GLOBAL_ID_FRAGMENT + ", " + "o." + GLOBAL_ID_TYPE_NAME + " owner_" + GLOBAL_ID_TYPE_NAME ) .from( tableNames.getSnapshotTableNameWithSchema() + " INNER JOIN " + tableNames.getCommitTableNameWithSchema() + " ON " + COMMIT_PK + " = " + SNAPSHOT_COMMIT_FK + " INNER JOIN " + tableNames.getGlobalIdTableNameWithSchema() + " g ON g." + GLOBAL_ID_PK + " = " + SNAPSHOT_GLOBAL_ID_FK + " LEFT OUTER JOIN " + tableNames.getGlobalIdTableNameWithSchema() + " o ON o." + GLOBAL_ID_PK + " = g." + GLOBAL_ID_OWNER_ID_FK) .queryName("snapshots"); this.queryParams = queryParams; this.tableNameProvider = tableNames; applyQueryParams(); }
private Optional<Long> findGlobalIdPkInDB(GlobalId globalId, Session session) { SelectBuilder select = session.select(GLOBAL_ID_PK) .from(getGlobalIdTableNameWithSchema()); if (globalId instanceof ValueObjectId) { final ValueObjectId valueObjectId = (ValueObjectId) globalId; Optional<Long> ownerFk = findGlobalIdPk(valueObjectId.getOwnerId(), session); if (!ownerFk.isPresent()){ return Optional.empty(); } select.and(GLOBAL_ID_FRAGMENT, valueObjectId.getFragment()) .and(GLOBAL_ID_OWNER_ID_FK, ownerFk.get()) .queryName("find PK of valueObjectId"); } else if (globalId instanceof InstanceId){ select.and(GLOBAL_ID_LOCAL_ID, jsonConverter.toJson(((InstanceId)globalId).getCdoId())) .and(GLOBAL_ID_TYPE_NAME, globalId.getTypeName()) .queryName("find PK of InstanceId"); } else if (globalId instanceof UnboundedValueObjectId){ select.and(GLOBAL_ID_TYPE_NAME, globalId.getTypeName()) .queryName("find PK of UnboundedValueObjectId"); } return select.queryForOptionalLong(); }
public SnapshotQuery(TableNameProvider tableNames, QueryParams queryParams, Session session) { this.selectBuilder = session .select( SNAPSHOT_STATE + ", " + SNAPSHOT_TYPE + ", " + SNAPSHOT_VERSION + ", " + SNAPSHOT_CHANGED + ", " + SNAPSHOT_MANAGED_TYPE + ", " + COMMIT_PK + ", " + COMMIT_AUTHOR + ", " + COMMIT_COMMIT_DATE + ", " + COMMIT_COMMIT_DATE_INSTANT + ", " + COMMIT_COMMIT_ID + ", " + "g." + GLOBAL_ID_LOCAL_ID + ", " + "g." + GLOBAL_ID_FRAGMENT + ", " + "g." + GLOBAL_ID_OWNER_ID_FK + ", " + "o." + GLOBAL_ID_LOCAL_ID + " owner_" + GLOBAL_ID_LOCAL_ID + ", " + "o." + GLOBAL_ID_FRAGMENT + " owner_" + GLOBAL_ID_FRAGMENT + ", " + "o." + GLOBAL_ID_TYPE_NAME + " owner_" + GLOBAL_ID_TYPE_NAME ) .from( tableNames.getSnapshotTableNameWithSchema() + " INNER JOIN " + tableNames.getCommitTableNameWithSchema() + " ON " + COMMIT_PK + " = " + SNAPSHOT_COMMIT_FK + " INNER JOIN " + tableNames.getGlobalIdTableNameWithSchema() + " g ON g." + GLOBAL_ID_PK + " = " + SNAPSHOT_GLOBAL_ID_FK + " LEFT OUTER JOIN " + tableNames.getGlobalIdTableNameWithSchema() + " o ON o." + GLOBAL_ID_PK + " = g." + GLOBAL_ID_OWNER_ID_FK) .queryName("snapshots"); this.queryParams = queryParams; this.tableNameProvider = tableNames; applyQueryParams(); }
private Optional<Long> findGlobalIdPkInDB(GlobalId globalId, Session session) { SelectBuilder select = session.select(GLOBAL_ID_PK) .from(getGlobalIdTableNameWithSchema()); if (globalId instanceof ValueObjectId) { final ValueObjectId valueObjectId = (ValueObjectId) globalId; Optional<Long> ownerFk = findGlobalIdPk(valueObjectId.getOwnerId(), session); if (!ownerFk.isPresent()){ return Optional.empty(); } select.and(GLOBAL_ID_FRAGMENT, valueObjectId.getFragment()) .and(GLOBAL_ID_OWNER_ID_FK, ownerFk.get()) .queryName("find PK of valueObjectId"); } else if (globalId instanceof InstanceId){ select.and(GLOBAL_ID_LOCAL_ID, jsonConverter.toJson(((InstanceId)globalId).getCdoId())) .and(GLOBAL_ID_TYPE_NAME, globalId.getTypeName()) .queryName("find PK of InstanceId"); } else if (globalId instanceof UnboundedValueObjectId){ select.and(GLOBAL_ID_TYPE_NAME, globalId.getTypeName()) .queryName("find PK of UnboundedValueObjectId"); } return select.queryForOptionalLong(); }