Skip to content

Commit

Permalink
Experimental env var config
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelborn committed Jan 16, 2025
1 parent dc3ee00 commit 4665248
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/ortus/boxlang/modules/orm/config/ORMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package ortus.boxlang.modules.orm.config;

import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Properties;
import java.util.stream.Stream;

import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
Expand Down Expand Up @@ -469,6 +472,25 @@ public Configuration toHibernateConfig() {
// .applyClassLoader( this.classLoader )
.build();
Configuration configuration = new Configuration( bootstrapRegistry );
var sysEnvProps = new Properties();

Field[] availableSettings = AvailableSettings.class.getFields();
for ( var prop : System.getProperties().entrySet() ) {
String settingName = ( String ) prop.getKey();
if ( settingName.startsWith( "HIBERNATE_" ) ) {
Object value = prop.getValue();
Field foundSetting = Stream.of( availableSettings ).filter( field -> field.getName() == settingName ).findFirst().orElse( null );
try {
if ( foundSetting != null ) {
sysEnvProps.put( foundSetting.get( foundSetting ), value );
}
} catch ( IllegalAccessException e ) {
logger.error( "Unable to read or set setting from env var: {}", settingName );
}
}
sysEnvProps.put( prop.getKey(), prop.getValue() );
}
configuration.addProperties( sysEnvProps );

if ( this.dbcreate != null ) {
switch ( dbcreate ) {
Expand Down

0 comments on commit 4665248

Please sign in to comment.