public int hashCode() { int result = 17; result = 37*result + getName().hashCode(); return result; }
public int hashCode() { int result = 17; result = 37*result + getName().hashCode(); return result; }
protected DataSourceDefinitionDescriptor getDataSourceDefinitionDescriptor(String name) { DataSourceDefinitionDescriptor ddDesc = null; for (DataSourceDefinitionDescriptor ddd : this.getDataSourceDefinitionDescriptors()) { if (ddd.getName().equals(name)) { ddDesc = ddd; break; } } return ddDesc; }
public void addDataSourceDefinitionDescriptor(DataSourceDefinitionDescriptor reference) { for(Iterator itr = this.getDataSourceDefinitionDescriptors().iterator(); itr.hasNext();){ DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor)itr.next(); if(desc.getName().equals(reference.getName())){ throw new IllegalStateException( localStrings.getLocalString("exceptionappclientduplicatedatasourcedefinition", "The application client [{0}] cannot have datasource definitions of same name : [{1}]", getName(), reference.getName())); } } getDataSourceDefinitionDescriptors().add(reference); }
public void addDataSourceDefinitionDescriptor(DataSourceDefinitionDescriptor reference) { for(Iterator itr = this.getDataSourceDefinitionDescriptors().iterator(); itr.hasNext();){ DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor)itr.next(); if(desc.getName().equals(reference.getName())){ throw new IllegalStateException( localStrings.getLocalString("exceptionapplicationduplicatedatasourcedefinition", "This application [{0}] cannot have datasource definitions of same name : [{1}]", getName(), reference.getName())); } } getDataSourceDefinitionDescriptors().add(reference); }
public void addDataSourceDefinitionDescriptor(DataSourceDefinitionDescriptor reference) { for(Iterator itr = this.getDataSourceDefinitionDescriptors().iterator(); itr.hasNext();){ DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor)itr.next(); if(desc.getName().equals(reference.getName())){ throw new IllegalStateException( localStrings.getLocalString("exceptionapplicationduplicatedatasourcedefinition", "This application [{0}] cannot have datasource definitions of same name : [{1}]", getName(), reference.getName())); } } getDataSourceDefinitionDescriptors().add(reference); }
/** * Adds the specified data-source-definition to the receiver. * @param reference DataSourceDefinitionDescriptor to add. */ public void addDataSourceDefinitionDescriptor(DataSourceDefinitionDescriptor reference) { for(Iterator itr = this.getDataSourceDefinitionDescriptors().iterator(); itr.hasNext();){ DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor)itr.next(); if(desc.getName().equals(reference.getName())){ throw new IllegalStateException( localStrings.getLocalString("exceptionduplicatedatasourcedefinition", "This descriptor/class cannot have datasource definitions of same name : [{0}]", getName(), reference.getName())); } } getDataSourceDefinitionDescriptors().add(reference); }
private void unregisterDSDReferredByApplication(DataSourceDefinitionDescriptor dsd){ try{ if(dsd.isDeployed()){ undeployResource(dsd); } }catch(Exception e){ _logger.log(Level.WARNING, "exception while unregistering DSD [ "+dsd.getName()+" ]", e); } }
@Override public void addDataSourceDefinitionDescriptor( DataSourceDefinitionDescriptor reference) { if (env != null) { env.addDataSourceDefinitionDescriptor(reference); return; } for(Iterator itr = this.getDataSourceDefinitionDescriptors().iterator(); itr.hasNext();){ DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor)itr.next(); if(desc.getName().equals(reference.getName())){ throw new IllegalStateException( localStrings.getLocalString("exceptionejbduplicatedatasourcedefinition", "This ejb [{0}] cannot have datasource definitions of same name : [{1}]", getName(), reference.getName())); } } getDataSourceDefinitionDescriptors().add(reference); }
public void addDataSourceDefinitionDescriptor(DataSourceDefinitionDescriptor reference) { DataSourceDefinitionDescriptor ddDesc = getDataSourceDefinitionDescriptor(reference.getName()); if (ddDesc != null) { throw new IllegalStateException( localStrings.getLocalString("exceptionwebduplicatedatasourcedefinition", "This web app [{0}] cannot have datasource definitions of same name : [{1}]", getName(), reference.getName())); } getDataSourceDefinitionDescriptors().add(reference); }
private void registerDSDReferredByApplication(String appName, DataSourceDefinitionDescriptor dsd) { // It is possible that JPA might call this method multiple times in a single deployment, // when there are multiple PUs eg: one PU in each of war, ejb-jar. Make sure that // DSD is bound to JNDI only when it is not already deployed. if(!dsd.isDeployed()){ DataSourceDefinitionProxy proxy = habitat.getComponent(DataSourceDefinitionProxy.class); ResourceNamingService resourceNamingService = habitat.getComponent(ResourceNamingService.class); proxy.setDescriptor(dsd); //String appName = application.getAppName(); String moduleName = null; if(dsd.getName().startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)){ dsd.setResourceId(appName); } if(dsd.getName().startsWith(ConnectorConstants.JAVA_GLOBAL_SCOPE_PREFIX) /*|| next.getName().startsWith("java:module/")*/ || dsd.getName().startsWith(ConnectorConstants.JAVA_APP_SCOPE_PREFIX)){ ResourceInfo resourceInfo = new ResourceInfo(dsd.getName(), appName, moduleName); try { resourceNamingService.publishObject(resourceInfo, proxy, true); dsd.setDeployed(true); } catch (NamingException e) { Object params[] = new Object[]{appName, dsd.getName(), e}; _logger.log(Level.WARNING, "dsd.registration.failed", params); } } } }
public Object create(Context ic) throws NamingException { if(actualResourceName == null){ actualResourceName = ConnectorsUtil.deriveDataSourceDefinitionResourceName (desc.getResourceId(), desc.getName()); try{ if(habitat == null){ habitat = Globals.getDefaultHabitat(); if(habitat == null){ throw new NamingException("Unable to create resource " + "["+ desc.getName() +" ] as habitat is null"); } } getResourceDeployer(desc, habitat.getAllByContract(ResourceDeployer.class)).deployResource(desc); }catch(Exception e){ NamingException ne = new NamingException("Unable to create resource ["+ desc.getName() +" ]"); ne.initCause(e); throw ne; } } return ic.lookup(actualResourceName); }
@Override protected void combineDataSourceDefinitionDescriptors(JndiNameEnvironment env) { for (DataSourceDefinitionDescriptor ddd: env.getDataSourceDefinitionDescriptors()) { DataSourceDefinitionDescriptor ddDesc = getDataSourceDefinitionDescriptor(ddd.getName()); if (ddDesc != null) { if (ddDesc.isConflict(ddd)) { conflictDataSourceDefinition = true; } } else { getDataSourceDefinitionDescriptors().add(ddd); } } }
public void deployResource(Object resource) throws Exception { final DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor) resource; String poolName = ConnectorsUtil.deriveDataSourceDefinitionPoolName(desc.getResourceId(), desc.getName()); String resourceName = ConnectorsUtil.deriveDataSourceDefinitionResourceName(desc.getResourceId(), desc.getName()); if(_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE, "DataSourceDefinitionDeployer.deployResource() : pool-name ["+poolName+"], " + " resource-name ["+resourceName+"]"); } JdbcConnectionPool jdbcCp = new MyJdbcConnectionPool(desc, poolName); Collection<ResourceDeployer> deployers = habitat.getAllByContract(ResourceDeployer.class); //deploy pool getDeployer(jdbcCp, deployers).deployResource(jdbcCp); //deploy resource JdbcResource jdbcResource = new MyJdbcResource(poolName, resourceName); getDeployer(jdbcResource, deployers).deployResource(jdbcResource); }
private void undeployDataSourceDefinitions(JndiNameEnvironment env) { for (DataSourceDefinitionDescriptor dsd : env.getDataSourceDefinitionDescriptors()) { Collection<ResourceDeployer> resourceDeployers = habitat.getAllByContract(ResourceDeployer.class); try{ if(dsd.isDeployed()){ ResourceDeployer deployer = getResourceDeployer(dsd, resourceDeployers); deployer.undeployResource(dsd); dsd.setDeployed(false); } }catch(Exception e){ _logger.log(Level.WARNING, "unable to undeploy DataSourceDefinition [ " + dsd.getName() + " ] ", e); } } }
public void undeployResource(Object resource) throws Exception { final DataSourceDefinitionDescriptor desc = (DataSourceDefinitionDescriptor) resource; Collection<ResourceDeployer> deployers = habitat.getAllByContract(ResourceDeployer.class); String poolName = ConnectorsUtil.deriveDataSourceDefinitionPoolName(desc.getResourceId(), desc.getName()); String resourceName = ConnectorsUtil.deriveDataSourceDefinitionResourceName(desc.getResourceId(), desc.getName()); if(_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE, "DataSourceDefinitionDeployer.undeployResource() : pool-name ["+poolName+"], " + " resource-name ["+resourceName+"]"); } //undeploy resource JdbcResource jdbcResource = new MyJdbcResource(poolName, resourceName); getDeployer(jdbcResource, deployers).undeployResource(jdbcResource); //undeploy pool JdbcConnectionPool jdbcCp = new MyJdbcConnectionPool(desc, poolName); getDeployer(jdbcCp, deployers).undeployResource(jdbcCp); desc.setDeployed(false); }
public boolean isConflict(DataSourceDefinitionDescriptor other) { return (getName().equals(other.getName())) && !( DOLUtils.equals(getClassName(), other.getClassName()) && DOLUtils.equals(getServerName(), other.getServerName()) && getPortNumber() == other.getPortNumber() && DOLUtils.equals(getDatabaseName(), other.getDatabaseName()) && DOLUtils.equals(getUrl(), other.getUrl()) && DOLUtils.equals(getUser(), other.getUser()) && DOLUtils.equals(getPassword(), other.getPassword()) && properties.equals(other.properties) && getLoginTimeout() == other.getLoginTimeout() && isTransactional() == other.isTransactional() && getIsolationLevel() == other.getIsolationLevel() && getInitialPoolSize() == other.getInitialPoolSize() && getMinPoolSize() == other.getMinPoolSize() && getMaxPoolSize() == other.getMaxPoolSize() && getMaxIdleTime() == other.getMaxIdleTime() && getMaxStatements() == other.getMaxStatements() ); } }
public Node writeDescriptor(Node parent, String nodeName, DataSourceDefinitionDescriptor dataSourceDesc) { Node node = appendChild(parent, nodeName); appendTextChild(node, TagNames.DATA_SOURCE_DESCRIPTION, dataSourceDesc.getDescription()); appendTextChild(node, TagNames.DATA_SOURCE_NAME, dataSourceDesc.getName()); appendTextChild(node, TagNames.DATA_SOURCE_CLASS_NAME, dataSourceDesc.getClassName()); appendTextChild(node, TagNames.DATA_SOURCE_SERVER_NAME, dataSourceDesc.getServerName()); appendTextChild(node, TagNames.DATA_SOURCE_PORT_NUMBER, dataSourceDesc.getPortNumber()); appendTextChild(node, TagNames.DATA_SOURCE_DATABASE_NAME, dataSourceDesc.getDatabaseName()); appendTextChild(node, TagNames.DATA_SOURCE_URL, dataSourceDesc.getUrl()); appendTextChild(node, TagNames.DATA_SOURCE_USER, dataSourceDesc.getUser()); appendTextChild(node, TagNames.DATA_SOURCE_PASSWORD, dataSourceDesc.getPassword()); ResourcePropertyNode propertyNode = new ResourcePropertyNode(); propertyNode.writeDescriptor(node, dataSourceDesc); appendTextChild(node, TagNames.DATA_SOURCE_LOGIN_TIMEOUT, String.valueOf(dataSourceDesc.getLoginTimeout())); appendTextChild(node, TagNames.DATA_SOURCE_TRANSACTIONAL, String.valueOf(dataSourceDesc.isTransactional())); //DD specified Enumeration values are String //Annotation uses integer values and hence this mapping is needed String isolationLevelString = dataSourceDesc.getIsolationLevelString(); if(isolationLevelString != null){ appendTextChild(node, TagNames.DATA_SOURCE_ISOLATION_LEVEL, isolationLevelString); } appendTextChild(node, TagNames.DATA_SOURCE_INITIAL_POOL_SIZE, dataSourceDesc.getInitialPoolSize()); appendTextChild(node, TagNames.DATA_SOURCE_MAX_POOL_SIZE, dataSourceDesc.getMaxPoolSize()); appendTextChild(node, TagNames.DATA_SOURCE_MIN_POOL_SIZE, dataSourceDesc.getMinPoolSize()); appendTextChild(node, TagNames.DATA_SOURCE_MAX_IDLE_TIME, String.valueOf(dataSourceDesc.getMaxIdleTime())); appendTextChild(node, TagNames.DATA_SOURCE_MAX_STATEMENTS, dataSourceDesc.getMaxStatements()); return node; }