3232import  static  com .google .cloud .spanner .connection .ConnectionProperties .ENABLE_EXTENDED_TRACING ;
3333import  static  com .google .cloud .spanner .connection .ConnectionProperties .ENCODED_CREDENTIALS ;
3434import  static  com .google .cloud .spanner .connection .ConnectionProperties .ENDPOINT ;
35+ import  static  com .google .cloud .spanner .connection .ConnectionProperties .IS_EXPERIMENTAL_HOST ;
3536import  static  com .google .cloud .spanner .connection .ConnectionProperties .LENIENT ;
3637import  static  com .google .cloud .spanner .connection .ConnectionProperties .MAX_COMMIT_DELAY ;
3738import  static  com .google .cloud .spanner .connection .ConnectionProperties .MAX_PARTITIONED_PARALLELISM ;
@@ -221,6 +222,7 @@ public String[] getValidValues() {
221222  private  static  final  LocalConnectionChecker  LOCAL_CONNECTION_CHECKER  =
222223      new  LocalConnectionChecker ();
223224  static  final  boolean  DEFAULT_USE_PLAIN_TEXT  = false ;
225+   static  final  boolean  DEFAULT_IS_EXPERIMENTAL_HOST  = false ;
224226  static  final  boolean  DEFAULT_AUTOCOMMIT  = true ;
225227  static  final  boolean  DEFAULT_READONLY  = false ;
226228  static  final  boolean  DEFAULT_RETRY_ABORTS_INTERNALLY  = true ;
@@ -260,6 +262,8 @@ public String[] getValidValues() {
260262  static  final  boolean  DEFAULT_AUTO_BATCH_DML  = false ;
261263  static  final  long  DEFAULT_AUTO_BATCH_DML_UPDATE_COUNT  = 1L ;
262264  static  final  boolean  DEFAULT_AUTO_BATCH_DML_UPDATE_COUNT_VERIFICATION  = true ;
265+   private  static  final  String  EXPERIMENTAL_HOST_PROJECT_ID  = "default" ;
266+   private  static  final  String  DEFAULT_EXPERIMENTAL_HOST_INSTANCE_ID  = "default" ;
263267
264268  private  static  final  String  PLAIN_TEXT_PROTOCOL  = "http:" ;
265269  private  static  final  String  HOST_PROTOCOL  = "https:" ;
@@ -268,6 +272,8 @@ public String[] getValidValues() {
268272  private  static  final  String  DEFAULT_EMULATOR_HOST  = "http://localhost:9010" ;
269273  /** Use plain text is only for local testing purposes. */ 
270274  static  final  String  USE_PLAIN_TEXT_PROPERTY_NAME  = "usePlainText" ;
275+   /** Connect to a Experimental Host * */ 
276+   static  final  String  IS_EXPERIMENTAL_HOST_PROPERTY_NAME  = "isExperimentalHost" ;
271277  /** Client certificate path to establish mTLS */ 
272278  static  final  String  CLIENT_CERTIFICATE_PROPERTY_NAME  = "clientCertificate" ;
273279  /** Client key path to establish mTLS */ 
@@ -444,6 +450,10 @@ static boolean isEnableTransactionalConnectionStateForPostgreSQL() {
444450                      USE_PLAIN_TEXT_PROPERTY_NAME ,
445451                      "Use a plain text communication channel (i.e. non-TLS) for communicating with the server (true/false). Set this value to true for communication with the Cloud Spanner emulator." ,
446452                      DEFAULT_USE_PLAIN_TEXT ),
453+                   ConnectionProperty .createBooleanProperty (
454+                       IS_EXPERIMENTAL_HOST_PROPERTY_NAME ,
455+                       "Set this value to true for communication with an Experimental Host." ,
456+                       DEFAULT_IS_EXPERIMENTAL_HOST ),
447457                  ConnectionProperty .createStringProperty (
448458                      CLIENT_CERTIFICATE_PROPERTY_NAME ,
449459                      "Specifies the file path to the client certificate required for establishing an mTLS connection." ),
@@ -664,7 +674,7 @@ private boolean isValidUri(String uri) {
664674      return  SPANNER_URI_PATTERN .matcher (uri ).matches ();
665675    }
666676
667-     private  boolean  isValidExternalHostUri (String  uri ) {
677+     private  boolean  isValidExperimentalHostUri (String  uri ) {
668678      return  EXTERNAL_HOST_PATTERN .matcher (uri ).matches ();
669679    }
670680
@@ -725,7 +735,7 @@ private boolean isValidExternalHostUri(String uri) {
725735     * @return this builder 
726736     */ 
727737    public  Builder  setUri (String  uri ) {
728-       if  (!isValidExternalHostUri (uri )) {
738+       if  (!isValidExperimentalHostUri (uri )) {
729739        Preconditions .checkArgument (
730740            isValidUri (uri ),
731741            "The specified URI is not a valid Cloud Spanner connection URI. Please specify a URI in the format \" cloudspanner:[//host[:port]]/projects/project-id[/instances/instance-id[/databases/database-name]][\\ ?property-name=property-value[;property-name=property-value]*]?\" " );
@@ -857,10 +867,10 @@ public static Builder newBuilder() {
857867
858868  private  ConnectionOptions (Builder  builder ) {
859869    Matcher  matcher ;
860-     boolean  isExternalHost  = false ;
861-     if  (builder .isValidExternalHostUri (builder .uri )) {
870+     boolean  isExperimentalHostPattern  = false ;
871+     if  (builder .isValidExperimentalHostUri (builder .uri )) {
862872      matcher  = Builder .EXTERNAL_HOST_PATTERN .matcher (builder .uri );
863-       isExternalHost  = true ;
873+       isExperimentalHostPattern  = true ;
864874    } else  {
865875      matcher  = Builder .SPANNER_URI_PATTERN .matcher (builder .uri );
866876    }
@@ -923,8 +933,8 @@ private ConnectionOptions(Builder builder) {
923933            getInitialConnectionPropertyValue (AUTO_CONFIG_EMULATOR ),
924934            usePlainText ,
925935            System .getenv ());
926-     GoogleCredentials  defaultExternalHostCredentials  =
927-         SpannerOptions .getDefaultExternalHostCredentialsFromSysEnv ();
936+     GoogleCredentials  defaultExperimentalHostCredentials  =
937+         SpannerOptions .getDefaultExperimentalCredentialsFromSysEnv ();
928938    // Using credentials on a plain text connection is not allowed, so if the user has not specified 
929939    // any credentials and is using a plain text connection, we should not try to get the 
930940    // credentials from the environment, but default to NoCredentials. 
@@ -939,8 +949,9 @@ && getInitialConnectionPropertyValue(OAUTH_TOKEN) == null
939949      this .credentials  =
940950          new  GoogleCredentials (
941951              new  AccessToken (getInitialConnectionPropertyValue (OAUTH_TOKEN ), null ));
942-     } else  if  (isExternalHost  && defaultExternalHostCredentials  != null ) {
943-       this .credentials  = defaultExternalHostCredentials ;
952+     } else  if  ((isExperimentalHostPattern  || isExperimentalHost ())
953+         && defaultExperimentalHostCredentials  != null ) {
954+       this .credentials  = defaultExperimentalHostCredentials ;
944955    } else  if  (getInitialConnectionPropertyValue (CREDENTIALS_PROVIDER ) != null ) {
945956      try  {
946957        this .credentials  = getInitialConnectionPropertyValue (CREDENTIALS_PROVIDER ).getCredentials ();
@@ -981,16 +992,19 @@ && getInitialConnectionPropertyValue(OAUTH_TOKEN) == null
981992      this .sessionPoolOptions  = sessionPoolOptionsBuilder .build ();
982993    } else  if  (builder .sessionPoolOptions  != null ) {
983994      this .sessionPoolOptions  = builder .sessionPoolOptions ;
995+     } else  if  (isExperimentalHostPattern  || isExperimentalHost ()) {
996+       this .sessionPoolOptions  =
997+           SessionPoolOptions .newBuilder ().setExperimentalHost ().setAutoDetectDialect (true ).build ();
984998    } else  {
985999      this .sessionPoolOptions  = SessionPoolOptions .newBuilder ().setAutoDetectDialect (true ).build ();
9861000    }
9871001
988-     String  projectId  = "default" ;
1002+     String  projectId  = EXPERIMENTAL_HOST_PROJECT_ID ;
9891003    String  instanceId  = matcher .group (Builder .INSTANCE_GROUP );
990-     if  (!isExternalHost ) {
1004+     if  (!isExperimentalHost () && ! isExperimentalHostPattern ) {
9911005      projectId  = matcher .group (Builder .PROJECT_GROUP );
992-     } else  if  (instanceId  == null ) {
993-       instanceId  = "default" ;
1006+     } else  if  (instanceId  == null  &&  isExperimentalHost () ) {
1007+       instanceId  = DEFAULT_EXPERIMENTAL_HOST_INSTANCE_ID ;
9941008    }
9951009    if  (Builder .DEFAULT_PROJECT_ID_PLACEHOLDER .equalsIgnoreCase (projectId )) {
9961010      projectId  = getDefaultProjectId (this .credentials );
@@ -1311,6 +1325,10 @@ boolean isUsePlainText() {
13111325        || getInitialConnectionPropertyValue (USE_PLAIN_TEXT );
13121326  }
13131327
1328+   boolean  isExperimentalHost () {
1329+     return  getInitialConnectionPropertyValue (IS_EXPERIMENTAL_HOST );
1330+   }
1331+ 
13141332  String  getClientCertificate () {
13151333    return  getInitialConnectionPropertyValue (CLIENT_CERTIFICATE );
13161334  }
0 commit comments