-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base persistence APIs for Policy Mapping
- Loading branch information
Showing
10 changed files
with
801 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
...tence/jpa-model/src/main/java/org/apache/polaris/jpa/models/ModelPolicyMappingRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.polaris.jpa.models; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Index; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Version; | ||
import org.apache.polaris.core.policy.PolarisPolicyMappingRecord; | ||
|
||
@Entity | ||
@Table( | ||
name = "POLICY_MAPPING_RECORDS", | ||
indexes = { | ||
@Index( | ||
name = "POLICY_MAPPING_RECORDS_BY_POLICY_INDEX", | ||
columnList = "policyCatalogId,policyId,targetCatalogId,targetId") | ||
}) | ||
public class ModelPolicyMappingRecord { | ||
// id of the catalog where target entity resides | ||
@Id private long targetCatalogId; | ||
|
||
// id of the target entity | ||
@Id private long targetId; | ||
|
||
// id associated to the policy type | ||
@Id private int policyTypeCode; | ||
|
||
// id of the catalog where the policy entity resides | ||
@Id private long policyCatalogId; | ||
|
||
// id of the policy | ||
@Id private long policyId; | ||
|
||
// additional parameters of the mapping | ||
private String parameters; | ||
|
||
// Used for Optimistic Locking to handle concurrent reads and updates | ||
@Version private long version; | ||
|
||
public long getTargetCatalogId() { | ||
return targetCatalogId; | ||
} | ||
|
||
public long getTargetId() { | ||
return targetId; | ||
} | ||
|
||
public int getPolicyTypeCode() { | ||
return policyTypeCode; | ||
} | ||
|
||
public long getPolicyCatalogId() { | ||
return policyCatalogId; | ||
} | ||
|
||
public long getPolicyId() { | ||
return policyId; | ||
} | ||
|
||
public String getParameters() { | ||
return parameters; | ||
} | ||
|
||
public static ModelPolicyMappingRecord.Builder builder() { | ||
return new ModelPolicyMappingRecord.Builder(); | ||
} | ||
|
||
public static final class Builder { | ||
private final ModelPolicyMappingRecord policyMappingRecord; | ||
|
||
private Builder() { | ||
policyMappingRecord = new ModelPolicyMappingRecord(); | ||
} | ||
|
||
public Builder targetCatalogId(long targetCatalogId) { | ||
policyMappingRecord.targetCatalogId = targetCatalogId; | ||
return this; | ||
} | ||
|
||
public Builder targetId(long targetId) { | ||
policyMappingRecord.targetId = targetId; | ||
return this; | ||
} | ||
|
||
public Builder policyTypeCode(int policyTypeCode) { | ||
policyMappingRecord.policyTypeCode = policyTypeCode; | ||
return this; | ||
} | ||
|
||
public Builder policyCatalogId(long policyCatalogId) { | ||
policyMappingRecord.policyCatalogId = policyCatalogId; | ||
return this; | ||
} | ||
|
||
public Builder policyId(long policyId) { | ||
policyMappingRecord.policyId = policyId; | ||
return this; | ||
} | ||
|
||
public Builder parameters(String parameters) { | ||
policyMappingRecord.parameters = parameters; | ||
return this; | ||
} | ||
|
||
public ModelPolicyMappingRecord build() { | ||
return policyMappingRecord; | ||
} | ||
} | ||
|
||
public static ModelPolicyMappingRecord fromPolicyMappingRecord( | ||
PolarisPolicyMappingRecord record) { | ||
if (record == null) return null; | ||
|
||
return ModelPolicyMappingRecord.builder() | ||
.targetCatalogId(record.getTargetCatalogId()) | ||
.targetId(record.getTargetId()) | ||
.policyTypeCode(record.getPolicyTypeCode()) | ||
.policyCatalogId(record.getPolicyCatalogId()) | ||
.policyId(record.getPolicyId()) | ||
.parameters(record.getParameters()) | ||
.build(); | ||
} | ||
|
||
public static PolarisPolicyMappingRecord toPolicyMappingRecord(ModelPolicyMappingRecord model) { | ||
if (model == null) return null; | ||
|
||
return new PolarisPolicyMappingRecord( | ||
model.getTargetCatalogId(), | ||
model.getTargetId(), | ||
model.getPolicyCatalogId(), | ||
model.getPolicyId(), | ||
model.getPolicyTypeCode(), | ||
model.getParameters()); | ||
} | ||
} |
Oops, something went wrong.