Skip to content

Commit

Permalink
Further cleanups around DataSourceDefinitionDescriptor
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Sep 18, 2022
1 parent fae5b12 commit 27d3388
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ public JndiNameEnvironment getJndiNameEnvironment(String componentId) {
refCountJndiEnvironment = compId2Env.get(componentId);
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest(
"ComponentEnvManagerImpl: " + "getJndiNameEnvironment " + componentId + " is "
+ (refCountJndiEnvironment == null ? "NULL" : refCountJndiEnvironment.env.getClass().toString()));
"ComponentEnvManagerImpl: getJndiNameEnvironment " + componentId + " is "
+ (refCountJndiEnvironment == null ? "NULL"
: refCountJndiEnvironment.env.getClass().toString()));
}
}

Expand All @@ -197,8 +198,8 @@ public JndiNameEnvironment getCurrentJndiNameEnvironment() {
if (inv.componentId != null) {
desc = getJndiNameEnvironment(inv.componentId);
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest(
"ComponentEnvManagerImpl: " + "getCurrentJndiNameEnvironment " + inv.componentId + " is " + desc.getClass());
_logger.finest("ComponentEnvManagerImpl: getCurrentJndiNameEnvironment " + inv.componentId + " is "
+ desc.getClass());
}
}
}
Expand Down Expand Up @@ -285,7 +286,7 @@ public String bindToComponentNamespace(JndiNameEnvironment jndiEnvironment) thro

if (componentEnvId != null) {
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("ComponentEnvManagerImpl: " + "register " + componentEnvId + " is " + jndiEnvironment.getClass());
_logger.finest("ComponentEnvManagerImpl: register " + componentEnvId + " is " + jndiEnvironment.getClass());
}
register(componentEnvId, jndiEnvironment);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,22 +17,22 @@

package com.sun.enterprise.deployment;

import org.glassfish.deployment.common.Descriptor;
import org.glassfish.deployment.common.JavaEEResourceType;

import com.sun.enterprise.deployment.core.ResourceDescriptor;

import java.util.Set;

import org.glassfish.deployment.common.Descriptor;
import org.glassfish.deployment.common.JavaEEResourceType;

/**
* This class is used to defined common descriptor elements which is shared by classes which implements BundleDescriptor.
* User: naman mehta
* Date: 22/5/12
* Time: 3:58 PM
* To change this template use File | Settings | File Templates.
* This class is used to defined common descriptor elements which is shared by classes which
* implements BundleDescriptor.
*
* @author naman mehta
*/
public abstract class CommonResourceDescriptor extends Descriptor {

private static final long serialVersionUID = 1L;
ResourceDescriptorRegistry resourceDescriptorRegistry = new ResourceDescriptorRegistry();

protected CommonResourceDescriptor() {
Expand Down Expand Up @@ -61,7 +62,7 @@ public Set<ResourceDescriptor> getAllResourcesDescriptors() {
return resourceDescriptorRegistry.getAllResourcesDescriptors();
}

public Set<ResourceDescriptor> getAllResourcesDescriptors(Class givenClazz) {
public Set<ResourceDescriptor> getAllResourcesDescriptors(Class<?> givenClazz) {
return resourceDescriptorRegistry.getAllResourcesDescriptors(givenClazz);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -14,16 +15,18 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/


package com.sun.enterprise.deployment;

import com.sun.enterprise.deployment.core.ResourceDescriptor;
import com.sun.enterprise.deployment.core.ResourcePropertyDescriptor;
import com.sun.enterprise.deployment.util.DOLUtils;

import java.sql.Connection;
import java.util.Properties;
import java.util.logging.Level;
import java.sql.Connection;

import static org.glassfish.deployment.common.JavaEEResourceType.*;
import static org.glassfish.deployment.common.JavaEEResourceType.DSD;

/**
* @author Jagadish Ramu
Expand All @@ -39,28 +42,28 @@ public class DataSourceDefinitionDescriptor extends ResourceDescriptor {
private String url;
private String user;
private String password;
private long loginTimeout =0 ;
private long loginTimeout;
private boolean transactional = true;
private int isolationLevel = -1;
private int initialPoolSize =-1;
private int maxPoolSize = -1;
private int minPoolSize =-1;
private long maxIdleTime=-1 ; //seconds / milliseconds ?
private long maxIdleTime = -1;
private int maxStatements =-1;
private Properties properties = new Properties();
private final Properties properties = new Properties();

private boolean transactionSet = false;
private boolean loginTimeoutSet = false;
private boolean serverNameSet = false;
private boolean transactionSet;
private boolean loginTimeoutSet;
private boolean serverNameSet;



private boolean deployed = false;
private boolean deployed;

private static final String JAVA_URL = "java:";
private static final String JAVA_COMP_URL = "java:comp/";

//represents the valid values for isolation-level in Deployment Descriptors
// represents the valid values for isolation-level in Deployment Descriptors
private static final String TRANSACTION_NONE = "TRANSACTION_NONE";
private static final String TRANSACTION_READ_UNCOMMITTED = "TRANSACTION_READ_UNCOMMITTED";
private static final String TRANSACTION_READ_COMMITTED = "TRANSACTION_READ_COMMITTED";
Expand All @@ -79,10 +82,12 @@ public boolean isDeployed(){
return deployed;
}

@Override
public String getName() {
return name;
}

@Override
public void setName(String name) {
this.name = name;
}
Expand All @@ -94,6 +99,7 @@ public void setUrl(String Url){
public String getUrl(){
return url;
}
@Override
public String getDescription() {
return description;
}
Expand All @@ -106,6 +112,7 @@ public boolean isTransactionSet(){
return transactionSet;
}

@Override
public void setDescription(String description) {
this.description = description;
}
Expand Down Expand Up @@ -164,12 +171,12 @@ public long getLoginTimeout() {
}

public void setLoginTimeout(String loginTimeout) {
try{
try {
this.loginTimeout = Long.parseLong(loginTimeout);
setLoginTimeoutSet(true);
}catch(NumberFormatException nfe){
DOLUtils.getDefaultLogger().log(Level.WARNING, "invalid loginTimeout value [ " + loginTimeout+ " ]," +
" required long");
} catch (NumberFormatException nfe) {
DOLUtils.getDefaultLogger().log(Level.WARNING,
"invalid loginTimeout value [ " + loginTimeout + " ]," + " required long");
}
}

Expand Down Expand Up @@ -200,19 +207,21 @@ public void setTransactional(boolean transactional) {

//DD specified Enumeration values are String
//Annotation uses integer values and hence this mapping is needed
public String getIsolationLevelString(){
public String getIsolationLevelString() {
String isolationLevelString = null;
if(isolationLevel == Connection.TRANSACTION_READ_COMMITTED){
if (isolationLevel == Connection.TRANSACTION_READ_COMMITTED) {
isolationLevelString = TRANSACTION_READ_COMMITTED;
}else if (isolationLevel == Connection.TRANSACTION_READ_UNCOMMITTED){
} else if (isolationLevel == Connection.TRANSACTION_READ_UNCOMMITTED) {
isolationLevelString = TRANSACTION_READ_UNCOMMITTED;
}else if (isolationLevel == Connection.TRANSACTION_REPEATABLE_READ){
} else if (isolationLevel == Connection.TRANSACTION_REPEATABLE_READ) {
isolationLevelString = TRANSACTION_REPEATABLE_READ;
}else if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE){
} else if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE) {
isolationLevelString = TRANSACTION_SERIALIZABLE;
}
return isolationLevelString;
}


public int getIsolationLevel() {
return isolationLevel;
}
Expand Down Expand Up @@ -322,6 +331,8 @@ public Properties getProperties(){
return properties;
}


@Override
public boolean equals(Object object) {
if (object instanceof DataSourceDefinitionDescriptor) {
DataSourceDefinitionDescriptor reference = (DataSourceDefinitionDescriptor) object;
Expand All @@ -330,15 +341,18 @@ public boolean equals(Object object) {
return false;
}


@Override
public int hashCode() {
int result = 17;
result = 37*result + getName().hashCode();
result = 37 * result + getName().hashCode();
return result;
}


public static String getJavaName(String thisName) {
if(!thisName.contains(JAVA_URL)){
thisName = JAVA_COMP_URL + thisName;
if (!thisName.contains(JAVA_URL)) {
thisName = JAVA_COMP_URL + thisName;
}
return thisName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@

package com.sun.enterprise.deployment;

import com.sun.enterprise.deployment.core.ResourceDescriptor;
import com.sun.enterprise.util.LocalStringManagerImpl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.glassfish.deployment.common.JavaEEResourceType;

import static com.sun.enterprise.util.Utility.isEmpty;
import static java.util.Arrays.asList;
import static org.glassfish.deployment.common.JavaEEResourceType.AODD;
Expand All @@ -30,17 +41,6 @@
import static org.glassfish.deployment.common.JavaEEResourceType.MSEDD;
import static org.glassfish.deployment.common.JavaEEResourceType.MTFDD;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.glassfish.deployment.common.JavaEEResourceType;

import com.sun.enterprise.deployment.core.ResourceDescriptor;
import com.sun.enterprise.util.LocalStringManagerImpl;

/**
* This class maintains registry for all resources and used by all Descriptor and BundleDescriptor classes.
*
Expand Down Expand Up @@ -73,7 +73,7 @@ public class ResourceDescriptorRegistry implements Serializable {

private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(ResourceDescriptorRegistry.class);

private Map<JavaEEResourceType, Set<ResourceDescriptor>> resourceDescriptors = new HashMap<>();
private final Map<JavaEEResourceType, Set<ResourceDescriptor>> resourceDescriptors = new HashMap<>();

/**
* This method returns all descriptors associated with the app.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -18,7 +19,6 @@

import org.w3c.dom.Node;


import com.sun.enterprise.deployment.xml.TagNames;
import com.sun.enterprise.deployment.DataSourceDefinitionDescriptor;

Expand All @@ -27,15 +27,18 @@
public class DataSourceDefinitionNode extends DeploymentDescriptorNode<DataSourceDefinitionDescriptor> {

public final static XMLElement tag = new XMLElement(TagNames.DATA_SOURCE);
private DataSourceDefinitionDescriptor descriptor = null;
private DataSourceDefinitionDescriptor descriptor;

public DataSourceDefinitionNode() {
registerElementHandler(new XMLElement(TagNames.RESOURCE_PROPERTY), ResourcePropertyNode.class,
"addDataSourcePropertyDescriptor");
"addDataSourcePropertyDescriptor");
}

protected Map getDispatchTable() {

@Override
protected Map<String, String> getDispatchTable() {
// no need to be synchronized for now
Map table = super.getDispatchTable();
Map<String, String> table = super.getDispatchTable();

table.put(TagNames.DATA_SOURCE_DESCRIPTION, "setDescription");
table.put(TagNames.DATA_SOURCE_NAME, "setName");
Expand All @@ -60,6 +63,7 @@ protected Map getDispatchTable() {
}


@Override
public Node writeDescriptor(Node parent, String nodeName, DataSourceDefinitionDescriptor dataSourceDesc) {

Node node = appendChild(parent, nodeName);
Expand Down Expand Up @@ -93,6 +97,8 @@ public Node writeDescriptor(Node parent, String nodeName, DataSourceDefinitionDe
return node;
}


@Override
public DataSourceDefinitionDescriptor getDescriptor() {
if(descriptor == null){
descriptor = new DataSourceDefinitionDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,8 @@ public void accept(BundleDescriptor descriptor) {
next.validate();
}
}

super.accept(descriptor);
} else {
super.accept(descriptor);
}
super.accept(descriptor);
}

/**
Expand Down

0 comments on commit 27d3388

Please sign in to comment.