Skip to content

Commit

Permalink
Support external config file for eclipselink
Browse files Browse the repository at this point in the history
    Due to the limitation of eclipselink, the config file has to be a resource inside a jar so a config file like /tmp/persistence.xml can't be supported directly.
    To workaround the issue,
    1. create a jar file from persistence.xml through 'jar cf conf.jar ./persistence.xml'
    2. place conf.jar in the classpath
    3. configure eclipselink in polaris-server.yml
           metaStoreManager:
             type: eclipse-link
             persistence-unit: polaris
             conf-file: conf.jar!/persistence.xml
  • Loading branch information
aihuaxu committed Aug 5, 2024
1 parent 167459d commit cf557b3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import jakarta.persistence.OptimisticLockException;
import jakarta.persistence.Persistence;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -118,13 +120,26 @@ public PolarisEclipseLinkMetaStoreSessionImpl(
}

/** Load the persistence unit properties from a given configuration file */
private Map<String, String> loadProperties(String confFile, String persistenceUnitName) {
private Map<String, String> loadProperties(
@NotNull String confFile, @NotNull String persistenceUnitName) {
if (this.properties != null) {
return this.properties;
}

try {
InputStream input = this.getClass().getClassLoader().getResourceAsStream(confFile);
InputStream input = null;
int splitPosition = confFile.indexOf("!/");
if (splitPosition == -1) {
input = this.getClass().getClassLoader().getResourceAsStream(confFile);
} else {
String jarPrefixPath = confFile.substring(0, splitPosition);
String descPath = confFile.substring(splitPosition + 2);
URL prefixUrl = this.getClass().getClassLoader().getResource(jarPrefixPath);
URLClassLoader child =
new URLClassLoader(new URL[] {prefixUrl}, this.getClass().getClassLoader());
input = child.getResourceAsStream(descPath);
}

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(input);
Expand Down
3 changes: 2 additions & 1 deletion polaris-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ defaultRealms:
metaStoreManager:
type: in-memory
# type: eclipse-link # uncomment to use eclipse-link as metastore
# persistence-unit: polaris-dev
# persistence-unit: polaris


# TODO - avoid duplicating token broker config
oauth2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
# limitations under the License.
#

io.polaris.extension.persistence.impl.hibernate.HibernatePolarisMetaStoreManagerFactory
io.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory
com.snowflake.polaris.persistence.impl.remote.RemotePolarisMetaStoreManagerFactory
io.polaris.extension.persistence.impl.eclipselink.EclipseLinkPolarisMetaStoreManagerFactory
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="polaris" transaction-type="RESOURCE_LOCAL">
<persistence-unit name="polaris-dev" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>io.polaris.core.persistence.models.ModelEntity</class>
<class>io.polaris.core.persistence.models.ModelEntityActive</class>
Expand Down

0 comments on commit cf557b3

Please sign in to comment.