Examples of DatasourceLogin


Examples of org.eclipse.persistence.sessions.DatasourceLogin

     * INTERNAL:
     * Process the sequencing information.
     */
    protected void processSequencingAccessors() {
        if (! m_generatedValues.isEmpty()) {
            DatasourceLogin login = m_session.getProject().getLogin();
   
            Sequence defaultAutoSequence = null;
            TableSequence defaultTableSequence = new TableSequence(DEFAULT_TABLE_GENERATOR);
            NativeSequence defaultObjectNativeSequence = new NativeSequence(DEFAULT_SEQUENCE_GENERATOR, false);
            NativeSequence defaultIdentityNativeSequence = new NativeSequence(DEFAULT_IDENTITY_GENERATOR, 1, true);
           
            // Sequences keyed on generator names.
            Hashtable<String, Sequence> sequences = new Hashtable<String, Sequence>();
           
            for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
                String sequenceGeneratorName = sequenceGenerator.getName();
               
                String seqName;
                if (sequenceGenerator.getSequenceName() != null && (! sequenceGenerator.getSequenceName().equals(""))) {
                    seqName = sequenceGenerator.getSequenceName();
                } else {
                    // TODO: Log a message.
                    seqName = sequenceGeneratorName;
                }
               
                Integer allocationSize = sequenceGenerator.getAllocationSize();
                if (allocationSize == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    allocationSize = new Integer(50);
                }
               
                NativeSequence sequence = new NativeSequence(seqName, allocationSize, false);
                sequence.setQualifier(sequenceGenerator.getQualifier());
                sequences.put(sequenceGeneratorName, sequence);
               
                if (sequenceGeneratorName.equals(DEFAULT_AUTO_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_AUTO_GENERATOR.
                    // The sequence it defines will be used as a defaultSequence.
                    defaultAutoSequence = sequence;
                } else if (sequenceGeneratorName.equals(DEFAULT_SEQUENCE_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_SEQUENCE_GENERATOR.
                    // All sequences of GeneratorType SEQUENCE referencing
                    // non-defined generators will use a clone of the sequence
                    // defined by this generator.
                    defaultObjectNativeSequence = sequence;
                }
            }

            for (TableGeneratorMetadata tableGenerator : m_tableGenerators.values()) {
                String tableGeneratorName = tableGenerator.getGeneratorName();
               
                String seqName;
                if (tableGenerator.getPkColumnValue() != null && (! tableGenerator.getPkColumnValue().equals(""))) {
                    seqName = tableGenerator.getPkColumnValue();
                } else {
                    // TODO: Log a message.
                    seqName = tableGeneratorName;
                }
               
                Integer allocationSize = tableGenerator.getAllocationSize();
                if (allocationSize == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    allocationSize = new Integer(50);
                }
               
                Integer initialValue = tableGenerator.getInitialValue();
                if (initialValue == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    initialValue = new Integer(0);
                }
               
                TableSequence sequence = new TableSequence(seqName, allocationSize, initialValue);
                sequences.put(tableGeneratorName, sequence);

                // Get the database table from the table generator.
                sequence.setTable(tableGenerator.getDatabaseTable());
               
                if (tableGenerator.getPkColumnName() != null && (! tableGenerator.getPkColumnName().equals(""))) {
                    sequence.setNameFieldName(tableGenerator.getPkColumnName());
                }
                   
                if (tableGenerator.getValueColumnName() != null && (! tableGenerator.getValueColumnName().equals(""))) {
                    sequence.setCounterFieldName(tableGenerator.getValueColumnName());
                }

                if (tableGeneratorName.equals(DEFAULT_AUTO_GENERATOR)) {
                    // TableGenerator defined with DEFAULT_AUTO_GENERATOR.
                    // The sequence it defines will be used as a defaultSequence.
                    defaultAutoSequence = sequence;
                } else if (tableGeneratorName.equals(DEFAULT_TABLE_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_TABLE_GENERATOR.
                    // All sequences of GenerationType TABLE referencing non-
                    // defined generators will use a clone of the sequence
                    // defined by this generator.
                    defaultTableSequence = sequence;
                }
            }

            // Finally loop through descriptors and set sequences as required
            // into Descriptors and Login
            boolean usesAuto = false;
            for (MetadataClass entityClass : m_generatedValues.keySet()) {
                // 266912: skip setting sequences if our accessor is null for mappedSuperclasses
                ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
                if(null != accessor) {
                    MetadataDescriptor descriptor = accessor.getDescriptor();
                    GeneratedValueMetadata generatedValue = m_generatedValues.get(entityClass);
                    String generatorName = generatedValue.getGenerator();

                    if (generatorName == null) {
                        // Value was loaded from XML (and it wasn't specified) so
                        // assign it the annotation default of ""
                        generatorName = "";
                    }

                    Sequence sequence = null;
                    if (! generatorName.equals("")) {
                        sequence = sequences.get(generatorName);
                    }

                    if (sequence == null) {
                        String strategy = generatedValue.getStrategy();

                        // A null strategy will default to AUTO.
                        if (strategy == null || strategy.equals(GenerationType.AUTO.name())) {
                            usesAuto = true;
                        } else if (strategy.equals(GenerationType.TABLE.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultTableSequence;
                            } else {
                                sequence = (Sequence)defaultTableSequence.clone();
                                sequence.setName(generatorName);
                            }
                        } else if (strategy.equals(GenerationType.SEQUENCE.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultObjectNativeSequence;
                            } else {
                                sequence = (Sequence)defaultObjectNativeSequence.clone();
                                sequence.setName(generatorName);
                            }
                        } else if (strategy.equals(GenerationType.IDENTITY.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultIdentityNativeSequence;
                            } else {
                                sequence = (Sequence)defaultIdentityNativeSequence.clone();
                                sequence.setName(generatorName);
                            }
                        }
                    }

                    if (sequence != null) {
                        descriptor.setSequenceNumberName(sequence.getName());
                        login.addSequence(sequence);
                    } else {
                        String seqName;

                        if (generatorName.equals("")) {
                            if (defaultAutoSequence != null) {
                                seqName = defaultAutoSequence.getName();
                            } else {
                                seqName = DEFAULT_AUTO_GENERATOR;
                            }
                        } else {
                            seqName = generatorName;
                        }

                        descriptor.setSequenceNumberName(seqName);
                    }
                }

                if (usesAuto) {
                    if (defaultAutoSequence != null) {
                        login.setDefaultSequence(defaultAutoSequence);
                    }
                }
            }
        }
    }
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

            // Use a temporary sequence generator to build a qualifier to set on
            // the default generator. Don't use this generator as the default
            // auto generator though.
            SequenceGeneratorMetadata tempGenerator = new SequenceGeneratorMetadata(DEFAULT_AUTO_GENERATOR, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema());
            DatasourceLogin login = m_session.getProject().getLogin();
            login.getDefaultSequence().setQualifier(tempGenerator.processQualifier());
               
            // 3 - Loop through generated values and set sequences for each.
            for (MetadataClass entityClass : m_generatedValues.keySet()) {
                // Skip setting sequences if our accessor is null, must be a mapped superclass
                ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

     * INTERNAL:
     * Process the sequencing information.
     */
    protected void processSequencingAccessors() {
        if (! m_generatedValues.isEmpty()) {
            DatasourceLogin login = m_session.getProject().getLogin();
   
            Sequence defaultAutoSequence = null;
            TableSequence defaultTableSequence = new TableSequence(DEFAULT_TABLE_GENERATOR);
            NativeSequence defaultObjectNativeSequence = new NativeSequence(DEFAULT_SEQUENCE_GENERATOR, false);
            NativeSequence defaultIdentityNativeSequence = new NativeSequence(DEFAULT_IDENTITY_GENERATOR, 1, true);

            // override default table name with platform's, in case current one
            // is not legal for this platform (e.g. SEQUENCE for Symfoware)
            Sequence seq = m_session.getDatasourcePlatform().getDefaultSequence();
            if (seq instanceof TableSequence) {
                defaultTableSequence.setTableName(((TableSequence)seq).getTableName());
            }

            // Sequences keyed on generator names.
            Hashtable<String, Sequence> sequences = new Hashtable<String, Sequence>();
           
            for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
                String sequenceGeneratorName = sequenceGenerator.getName();
               
                String seqName;
                if (sequenceGenerator.getSequenceName() != null && (! sequenceGenerator.getSequenceName().equals(""))) {
                    seqName = sequenceGenerator.getSequenceName();
                } else {
                    // TODO: Log a message.
                    seqName = sequenceGeneratorName;
                }
               
                Integer allocationSize = sequenceGenerator.getAllocationSize();
                if (allocationSize == null) {
                    // Default value, same as annotation default.
                    allocationSize = Integer.valueOf(50);
                }
               
                Integer initialValue = sequenceGenerator.getInitialValue();
                if (initialValue == null) {
                    // Default value, same as annotation default.
                    initialValue = Integer.valueOf(1);
                }
               
                NativeSequence sequence = new NativeSequence(seqName, allocationSize, initialValue, false);
                sequence.setQualifier(sequenceGenerator.getQualifier());
                sequences.put(sequenceGeneratorName, sequence);
               
                if (sequenceGeneratorName.equals(DEFAULT_AUTO_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_AUTO_GENERATOR.
                    // The sequence it defines will be used as a defaultSequence.
                    defaultAutoSequence = sequence;
                } else if (sequenceGeneratorName.equals(DEFAULT_SEQUENCE_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_SEQUENCE_GENERATOR.
                    // All sequences of GeneratorType SEQUENCE referencing
                    // non-defined generators will use a clone of the sequence
                    // defined by this generator.
                    defaultObjectNativeSequence = sequence;
                }
            }

            for (TableGeneratorMetadata tableGenerator : m_tableGenerators.values()) {
                String tableGeneratorName = tableGenerator.getGeneratorName();
               
                String seqName;
                if (tableGenerator.getPkColumnValue() != null && (! tableGenerator.getPkColumnValue().equals(""))) {
                    seqName = tableGenerator.getPkColumnValue();
                } else {
                    // TODO: Log a message.
                    seqName = tableGeneratorName;
                }
               
                Integer allocationSize = tableGenerator.getAllocationSize();
                if (allocationSize == null) {
                    // Default value, same as annotation default.
                    allocationSize = Integer.valueOf(50);
                }
               
                Integer initialValue = tableGenerator.getInitialValue();
                if (initialValue == null) {
                    // Default value, same as annotation default.
                    initialValue = Integer.valueOf(0);
                }
               
                TableSequence sequence = new TableSequence(seqName, allocationSize, initialValue);
                sequences.put(tableGeneratorName, sequence);

                // Get the database table from the table generator.
                sequence.setTable(tableGenerator.getDatabaseTable());
               
                if (tableGenerator.getPkColumnName() != null && (! tableGenerator.getPkColumnName().equals(""))) {
                    sequence.setNameFieldName(tableGenerator.getPkColumnName());
                }
                   
                if (tableGenerator.getValueColumnName() != null && (! tableGenerator.getValueColumnName().equals(""))) {
                    sequence.setCounterFieldName(tableGenerator.getValueColumnName());
                }

                if (tableGeneratorName.equals(DEFAULT_AUTO_GENERATOR)) {
                    // TableGenerator defined with DEFAULT_AUTO_GENERATOR.
                    // The sequence it defines will be used as a defaultSequence.
                    defaultAutoSequence = sequence;
                } else if (tableGeneratorName.equals(DEFAULT_TABLE_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_TABLE_GENERATOR.
                    // All sequences of GenerationType TABLE referencing non-
                    // defined generators will use a clone of the sequence
                    // defined by this generator.
                    defaultTableSequence = sequence;
                }
            }

            // Finally loop through descriptors and set sequences as required
            // into Descriptors and Login
            boolean usesAuto = false;
            for (MetadataClass entityClass : m_generatedValues.keySet()) {
                // 266912: skip setting sequences if our accessor is null for mappedSuperclasses
                ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
                if(null != accessor) {
                    MetadataDescriptor descriptor = accessor.getDescriptor();
                    GeneratedValueMetadata generatedValue = m_generatedValues.get(entityClass);
                    String generatorName = generatedValue.getGenerator();

                    if (generatorName == null) {
                        // Value was loaded from XML (and it wasn't specified) so
                        // assign it the annotation default of ""
                        generatorName = "";
                    }

                    Sequence sequence = null;
                    if (! generatorName.equals("")) {
                        sequence = sequences.get(generatorName);
                    }

                    if (sequence == null) {
                        String strategy = generatedValue.getStrategy();

                        // A null strategy will default to AUTO.
                        if (strategy == null || strategy.equals(GenerationType.AUTO.name())) {
                            usesAuto = true;
                        } else if (strategy.equals(GenerationType.TABLE.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultTableSequence;
                            } else {
                                sequence = (Sequence)defaultTableSequence.clone();
                                sequence.setName(generatorName);
                            }
                        } else if (strategy.equals(GenerationType.SEQUENCE.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultObjectNativeSequence;
                            } else {
                                sequence = (Sequence)defaultObjectNativeSequence.clone();
                                sequence.setName(generatorName);
                            }
                        } else if (strategy.equals(GenerationType.IDENTITY.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultIdentityNativeSequence;
                            } else {
                                sequence = (Sequence)defaultIdentityNativeSequence.clone();
                                sequence.setName(generatorName);
                            }
                        }
                    }

                    if (sequence != null) {
                        descriptor.setSequenceNumberName(sequence.getName());
                        login.addSequence(sequence);
                    } else {
                        String seqName;

                        if (generatorName.equals("")) {
                            if (defaultAutoSequence != null) {
                                seqName = defaultAutoSequence.getName();
                            } else {
                                seqName = DEFAULT_AUTO_GENERATOR;
                            }
                        } else {
                            seqName = generatorName;
                        }

                        descriptor.setSequenceNumberName(seqName);
                    }
                }

                if (usesAuto) {
                    if (defaultAutoSequence != null) {
                        login.setDefaultSequence(defaultAutoSequence);
                    }
                }
            }
        }
    }
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

     * INTERNAL:
     * Process the sequencing information.
     */
    protected void processSequencingAccessors() {
        if (! m_generatedValues.isEmpty()) {
            DatasourceLogin login = m_session.getProject().getLogin();
   
            Sequence defaultAutoSequence = null;
            TableSequence defaultTableSequence = new TableSequence(DEFAULT_TABLE_GENERATOR);
            NativeSequence defaultObjectNativeSequence = new NativeSequence(DEFAULT_SEQUENCE_GENERATOR, false);
            NativeSequence defaultIdentityNativeSequence = new NativeSequence(DEFAULT_IDENTITY_GENERATOR, 1, true);
           
            // Sequences keyed on generator names.
            Hashtable<String, Sequence> sequences = new Hashtable<String, Sequence>();
           
            for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
                String sequenceGeneratorName = sequenceGenerator.getName();
               
                String seqName;
                if (sequenceGenerator.getSequenceName() != null && (! sequenceGenerator.getSequenceName().equals(""))) {
                    seqName = sequenceGenerator.getSequenceName();
                } else {
                    // TODO: Log a message.
                    seqName = sequenceGeneratorName;
                }
               
                Integer allocationSize = sequenceGenerator.getAllocationSize();
                if (allocationSize == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    allocationSize = new Integer(50);
                }
               
                NativeSequence sequence = new NativeSequence(seqName, allocationSize, false);
                sequence.setQualifier(sequenceGenerator.getQualifier());
                sequences.put(sequenceGeneratorName, sequence);
               
                if (sequenceGeneratorName.equals(DEFAULT_AUTO_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_AUTO_GENERATOR.
                    // The sequence it defines will be used as a defaultSequence.
                    defaultAutoSequence = sequence;
                } else if (sequenceGeneratorName.equals(DEFAULT_SEQUENCE_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_SEQUENCE_GENERATOR.
                    // All sequences of GeneratorType SEQUENCE referencing
                    // non-defined generators will use a clone of the sequence
                    // defined by this generator.
                    defaultObjectNativeSequence = sequence;
                }
            }

            for (TableGeneratorMetadata tableGenerator : m_tableGenerators.values()) {
                String tableGeneratorName = tableGenerator.getGeneratorName();
               
                String seqName;
                if (tableGenerator.getPkColumnValue() != null && (! tableGenerator.getPkColumnValue().equals(""))) {
                    seqName = tableGenerator.getPkColumnValue();
                } else {
                    // TODO: Log a message.
                    seqName = tableGeneratorName;
                }
               
                Integer allocationSize = tableGenerator.getAllocationSize();
                if (allocationSize == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    allocationSize = new Integer(50);
                }
               
                Integer initialValue = tableGenerator.getInitialValue();
                if (initialValue == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    initialValue = new Integer(0);
                }
               
                TableSequence sequence = new TableSequence(seqName, allocationSize, initialValue);
                sequences.put(tableGeneratorName, sequence);

                // Get the database table from the table generator.
                sequence.setTable(tableGenerator.getDatabaseTable());
               
                if (tableGenerator.getPkColumnName() != null && (! tableGenerator.getPkColumnName().equals(""))) {
                    sequence.setNameFieldName(tableGenerator.getPkColumnName());
                }
                   
                if (tableGenerator.getValueColumnName() != null && (! tableGenerator.getValueColumnName().equals(""))) {
                    sequence.setCounterFieldName(tableGenerator.getValueColumnName());
                }

                if (tableGeneratorName.equals(DEFAULT_AUTO_GENERATOR)) {
                    // TableGenerator defined with DEFAULT_AUTO_GENERATOR.
                    // The sequence it defines will be used as a defaultSequence.
                    defaultAutoSequence = sequence;
                } else if (tableGeneratorName.equals(DEFAULT_TABLE_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_TABLE_GENERATOR.
                    // All sequences of GenerationType TABLE referencing non-
                    // defined generators will use a clone of the sequence
                    // defined by this generator.
                    defaultTableSequence = sequence;
                }
            }

            // Finally loop through descriptors and set sequences as required
            // into Descriptors and Login
            boolean usesAuto = false;
            for (MetadataClass entityClass : m_generatedValues.keySet()) {
                // 266912: skip setting sequences if our accessor is null for mappedSuperclasses
                ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
                if(null != accessor) {
                    MetadataDescriptor descriptor = accessor.getDescriptor();
                    GeneratedValueMetadata generatedValue = m_generatedValues.get(entityClass);
                    String generatorName = generatedValue.getGenerator();

                    if (generatorName == null) {
                        // Value was loaded from XML (and it wasn't specified) so
                        // assign it the annotation default of ""
                        generatorName = "";
                    }

                    Sequence sequence = null;
                    if (! generatorName.equals("")) {
                        sequence = sequences.get(generatorName);
                    }

                    if (sequence == null) {
                        String strategy = generatedValue.getStrategy();

                        // A null strategy will default to AUTO.
                        if (strategy == null || strategy.equals(GenerationType.AUTO.name())) {
                            usesAuto = true;
                        } else if (strategy.equals(GenerationType.TABLE.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultTableSequence;
                            } else {
                                sequence = (Sequence)defaultTableSequence.clone();
                                sequence.setName(generatorName);
                            }
                        } else if (strategy.equals(GenerationType.SEQUENCE.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultObjectNativeSequence;
                            } else {
                                sequence = (Sequence)defaultObjectNativeSequence.clone();
                                sequence.setName(generatorName);
                            }
                        } else if (strategy.equals(GenerationType.IDENTITY.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultIdentityNativeSequence;
                            } else {
                                sequence = (Sequence)defaultIdentityNativeSequence.clone();
                                sequence.setName(generatorName);
                            }
                        }
                    }

                    if (sequence != null) {
                        descriptor.setSequenceNumberName(sequence.getName());
                        login.addSequence(sequence);
                    } else {
                        String seqName;

                        if (generatorName.equals("")) {
                            if (defaultAutoSequence != null) {
                                seqName = defaultAutoSequence.getName();
                            } else {
                                seqName = DEFAULT_AUTO_GENERATOR;
                            }
                        } else {
                            seqName = generatorName;
                        }

                        descriptor.setSequenceNumberName(seqName);
                    }
                }

                if (usesAuto) {
                    if (defaultAutoSequence != null) {
                        login.setDefaultSequence(defaultAutoSequence);
                    }
                }
            }
        }
    }
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

     * Override the default login creation method.
     * If persistenceInfo is available, use the information from it to setup the login
     * and possibly to set readConnectionPool.
     */
    protected void updateLogins(Map m){
        DatasourceLogin login = (DatasourceLogin)this.session.getDatasourceLogin();

        String eclipselinkPlatform = PropertiesHandler.getPropertyValueLogDebug(PersistenceUnitProperties.TARGET_DATABASE, m, this.session);
        if (eclipselinkPlatform != null) {
            login.setPlatformClassName(eclipselinkPlatform, this.persistenceUnitInfo.getClassLoader());
        }       
        // Check for EIS platform, need to use an EIS login.
        boolean isEIS = false;
        if (login.getDatasourcePlatform() instanceof EISPlatform) {
            isEIS = true;
            EISLogin newLogin = new EISLogin();
            newLogin.setDatasourcePlatform(login.getDatasourcePlatform());
            this.session.setDatasourceLogin(newLogin);
            if (this.session.isServerSession()) {
               for (ConnectionPool pool : ((ServerSession)this.session).getConnectionPools().values()) {
                   pool.setLogin(newLogin);
               }
            }
            login = newLogin;
        }
       
        // Check for EIS or custom (JDBC) Connector class.
        Object connectorValue = getConfigPropertyLogDebug(PersistenceUnitProperties.NOSQL_CONNECTION_SPEC, m, this.session);
        String connectorProperty = PersistenceUnitProperties.NOSQL_CONNECTION_SPEC;
        if (connectorValue == null) {
            connectorValue = getConfigPropertyLogDebug(PersistenceUnitProperties.JDBC_CONNECTOR, m, this.session);
            connectorProperty = PersistenceUnitProperties.JDBC_CONNECTOR;
        }
        if (connectorValue instanceof Connector) {
            login.setConnector((Connector)connectorValue);
        } else if (connectorValue instanceof String) {
            Class cls = null;
            // Try both class loaders.
            try {
                cls = findClassForProperty((String)connectorValue, connectorProperty, this.persistenceUnitInfo.getClassLoader());
            } catch (Throwable failed) {
                cls = findClassForProperty((String)connectorValue, connectorProperty, getClass().getClassLoader());               
            }
            Connector connector = null;
            try {
                Constructor constructor = cls.getConstructor();
                connector = (Connector)constructor.newInstance();
            } catch (Exception exception) {
                throw EntityManagerSetupException.failedToInstantiateProperty((String)connectorValue, connectorProperty, exception);
            }
            if (connector != null) {
                login.setConnector(connector);
            }
        } else if (connectorValue != null) {
            // Assume JCA connection spec.
            ((EISConnectionSpec)login.getConnector()).setConnectionSpecObject(connectorValue);
        }
       
        // Check for EIS ConnectionFactory.
        Object factoryValue = getConfigPropertyLogDebug(PersistenceUnitProperties.NOSQL_CONNECTION_FACTORY, m, this.session);
        if (factoryValue instanceof String) {
            // JNDI name.
            ((EISConnectionSpec)login.getConnector()).setName((String)factoryValue);
        } else if (factoryValue != null) {
            ((EISConnectionSpec)login.getConnector()).setConnectionFactoryObject(factoryValue);
        }
       
        // Process EIS or JDBC connection properties.
        Map propertiesMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.NOSQL_PROPERTY, m, session);
        if (propertiesMap.isEmpty()) {
            propertiesMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.JDBC_PROPERTY, m, session);
        }
        for (Iterator iterator = propertiesMap.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry entry = (Map.Entry)iterator.next();
            String property = (String)entry.getKey();
            Object value = entry.getValue();
            login.setProperty(property, value);
        }       
       
        // Note: This call does not checked the stored persistenceUnitInfo or extended properties because
        // the map passed into this method should represent the full set of properties we expect to process

        String user = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_USER, m, this.session);
        String password = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_PASSWORD, m, this.session);
        if(user != null) {
            login.setUserName(user);
        }
        if (password != null) {
            login.setPassword(this.securableObjectHolder.getSecurableObject().decryptPassword(password));
        }
       
        PersistenceUnitTransactionType transactionType = this.persistenceUnitInfo.getTransactionType();
        //bug 5867753: find and override the transaction type using properties
        String transTypeString = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.TRANSACTION_TYPE, m, this.session);
        if (transTypeString != null && transTypeString.length() > 0) {
            transactionType = PersistenceUnitTransactionType.valueOf(transTypeString);
        }
        //find the jta datasource
        javax.sql.DataSource jtaDatasource = getDatasourceFromProperties(m, PersistenceUnitProperties.JTA_DATASOURCE, this.persistenceUnitInfo.getJtaDataSource());

        //find the non jta datasource 
        javax.sql.DataSource nonjtaDatasource = getDatasourceFromProperties(m, PersistenceUnitProperties.NON_JTA_DATASOURCE, this.persistenceUnitInfo.getNonJtaDataSource());

        if (isValidationOnly(m, false) && transactionType == PersistenceUnitTransactionType.JTA && jtaDatasource == null) {
            updateLoginDefaultConnector(login, m);
            return;
        }
       
        login.setUsesExternalTransactionController(transactionType == PersistenceUnitTransactionType.JTA);

        // Avoid processing data-source if EIS, as container may pass in a default one.
        if (isEIS) {
            return;
        }
       
        javax.sql.DataSource mainDatasource = null;
        javax.sql.DataSource readDatasource = null;
        if (login.shouldUseExternalTransactionController()) {
            // JtaDataSource is guaranteed to be non null - otherwise exception would've been thrown earlier
            mainDatasource = jtaDatasource;
            // only define readDatasource if there is jta mainDatasource
            readDatasource = nonjtaDatasource;
        } else {
            // JtaDataSource will be ignored because transactionType is RESOURCE_LOCAL
            if (jtaDatasource != null) {
                session.log(SessionLog.WARNING, SessionLog.TRANSACTION, "resource_local_persistence_init_info_ignores_jta_data_source", this.persistenceUnitInfo.getPersistenceUnitName());
            }
            if (nonjtaDatasource != null) {
                mainDatasource = nonjtaDatasource;
            } else {
                updateLoginDefaultConnector(login, m);
                return;
            }
        }

        // mainDatasource is guaranteed to be non null - TODO: No it is not, if they did not set one it is null, should raise error, not null-pointer.
        if (!(login.getConnector() instanceof JNDIConnector)) {
            JNDIConnector jndiConnector;
            if (mainDatasource instanceof DataSourceImpl) {
                //Bug5209363  Pass in the datasource name instead of the dummy datasource
                jndiConnector = new JNDIConnector(((DataSourceImpl)mainDatasource).getName());               
            } else {
                jndiConnector = new JNDIConnector(mainDatasource);                               
            }
            login.setConnector(jndiConnector);
            String useInternalConnectionPool = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.CONNECTION_POOL_INTERNALLY_POOL_DATASOURCE, m, this.session);
            if (!"true".equalsIgnoreCase(useInternalConnectionPool)){
                login.setUsesExternalConnectionPooling(true);
            }
        }

        if (this.session.isServerSession()) {
            // set readLogin
            if (readDatasource != null) {
                DatasourceLogin readLogin = login.clone();
                readLogin.dontUseExternalTransactionController();
                JNDIConnector jndiConnector;
                if (readDatasource instanceof DataSourceImpl) {
                    //Bug5209363  Pass in the datasource name instead of the dummy datasource
                    jndiConnector = new JNDIConnector(((DataSourceImpl)readDatasource).getName());
                } else {
                    jndiConnector = new JNDIConnector(readDatasource);                   
                }
                readLogin.setConnector(jndiConnector);
                ((ServerSession)this.session).setReadConnectionPool(readLogin);
            }
        }
       
    }
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

            if (sequence != null) {
                serverSession.getSequencingControl().setShouldUseSeparateConnection(Boolean.parseBoolean(sequence));
            }
            String sequenceDataSource = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_DATASOURCE, m, serverSession);
            if (sequenceDataSource != null) {
                DatasourceLogin login = this.session.getLogin().clone();
                login.dontUseExternalTransactionController();
                JNDIConnector jndiConnector = new JNDIConnector(sequenceDataSource);
                login.setConnector(jndiConnector);
                serverSession.getSequencingControl().setLogin(login);
            }       
            // Sizes and shared option are irrelevant for external connection pool
            if (!serverSession.getReadConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
                value = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MIN, m, serverSession);
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

     * INTERNAL:
     * Process the sequencing information.
     */
    protected void processSequencingAccessors() {
        if (! m_generatedValues.isEmpty()) {
            DatasourceLogin login = m_session.getProject().getLogin();
   
            Sequence defaultAutoSequence = null;
            TableSequence defaultTableSequence = new TableSequence(DEFAULT_TABLE_GENERATOR);
            NativeSequence defaultObjectNativeSequence = new NativeSequence(DEFAULT_SEQUENCE_GENERATOR, false);
            NativeSequence defaultIdentityNativeSequence = new NativeSequence(DEFAULT_IDENTITY_GENERATOR, 1, true);
           
            // Sequences keyed on generator names.
            Hashtable<String, Sequence> sequences = new Hashtable<String, Sequence>();
           
            for (SequenceGeneratorMetadata sequenceGenerator : m_sequenceGenerators.values()) {
                String sequenceGeneratorName = sequenceGenerator.getName();
               
                String seqName;
                if (sequenceGenerator.getSequenceName() != null && (! sequenceGenerator.getSequenceName().equals(""))) {
                    seqName = sequenceGenerator.getSequenceName();
                } else {
                    // TODO: Log a message.
                    seqName = sequenceGeneratorName;
                }
               
                Integer allocationSize = sequenceGenerator.getAllocationSize();
                if (allocationSize == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    allocationSize = new Integer(50);
                }
               
                NativeSequence sequence = new NativeSequence(seqName, allocationSize, false);
                sequence.setQualifier(sequenceGenerator.getQualifier());
                sequences.put(sequenceGeneratorName, sequence);
               
                if (sequenceGeneratorName.equals(DEFAULT_AUTO_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_AUTO_GENERATOR.
                    // The sequence it defines will be used as a defaultSequence.
                    defaultAutoSequence = sequence;
                } else if (sequenceGeneratorName.equals(DEFAULT_SEQUENCE_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_SEQUENCE_GENERATOR.
                    // All sequences of GeneratorType SEQUENCE referencing
                    // non-defined generators will use a clone of the sequence
                    // defined by this generator.
                    defaultObjectNativeSequence = sequence;
                }
            }

            for (TableGeneratorMetadata tableGenerator : m_tableGenerators.values()) {
                String tableGeneratorName = tableGenerator.getGeneratorName();
               
                String seqName;
                if (tableGenerator.getPkColumnValue() != null && (! tableGenerator.getPkColumnValue().equals(""))) {
                    seqName = tableGenerator.getPkColumnValue();
                } else {
                    // TODO: Log a message.
                    seqName = tableGeneratorName;
                }
               
                Integer allocationSize = tableGenerator.getAllocationSize();
                if (allocationSize == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    allocationSize = new Integer(50);
                }
               
                Integer initialValue = tableGenerator.getInitialValue();
                if (initialValue == null) {
                    // Default value, same as annotation default.
                    // TODO: Log a message.
                    initialValue = new Integer(0);
                }
               
                TableSequence sequence = new TableSequence(seqName, allocationSize, initialValue);
                sequences.put(tableGeneratorName, sequence);

                // Get the database table from the table generator.
                sequence.setTable(tableGenerator.getDatabaseTable());
               
                if (tableGenerator.getPkColumnName() != null && (! tableGenerator.getPkColumnName().equals(""))) {
                    sequence.setNameFieldName(tableGenerator.getPkColumnName());
                }
                   
                if (tableGenerator.getValueColumnName() != null && (! tableGenerator.getValueColumnName().equals(""))) {
                    sequence.setCounterFieldName(tableGenerator.getValueColumnName());
                }

                if (tableGeneratorName.equals(DEFAULT_AUTO_GENERATOR)) {
                    // TableGenerator defined with DEFAULT_AUTO_GENERATOR.
                    // The sequence it defines will be used as a defaultSequence.
                    defaultAutoSequence = sequence;
                } else if (tableGeneratorName.equals(DEFAULT_TABLE_GENERATOR)) {
                    // SequenceGenerator defined with DEFAULT_TABLE_GENERATOR.
                    // All sequences of GenerationType TABLE referencing non-
                    // defined generators will use a clone of the sequence
                    // defined by this generator.
                    defaultTableSequence = sequence;
                }
            }

            // Finally loop through descriptors and set sequences as required
            // into Descriptors and Login
            boolean usesAuto = false;
            for (MetadataClass entityClass : m_generatedValues.keySet()) {
                // 266912: skip setting sequences if our accessor is null for mappedSuperclasses
                ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
                if(null != accessor) {
                    MetadataDescriptor descriptor = accessor.getDescriptor();
                    GeneratedValueMetadata generatedValue = m_generatedValues.get(entityClass);
                    String generatorName = generatedValue.getGenerator();

                    if (generatorName == null) {
                        // Value was loaded from XML (and it wasn't specified) so
                        // assign it the annotation default of ""
                        generatorName = "";
                    }

                    Sequence sequence = null;
                    if (! generatorName.equals("")) {
                        sequence = sequences.get(generatorName);
                    }

                    if (sequence == null) {
                        String strategy = generatedValue.getStrategy();

                        // A null strategy will default to AUTO.
                        if (strategy == null || strategy.equals(GenerationType.AUTO.name())) {
                            usesAuto = true;
                        } else if (strategy.equals(GenerationType.TABLE.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultTableSequence;
                            } else {
                                sequence = (Sequence)defaultTableSequence.clone();
                                sequence.setName(generatorName);
                            }
                        } else if (strategy.equals(GenerationType.SEQUENCE.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultObjectNativeSequence;
                            } else {
                                sequence = (Sequence)defaultObjectNativeSequence.clone();
                                sequence.setName(generatorName);
                            }
                        } else if (strategy.equals(GenerationType.IDENTITY.name())) {
                            if (generatorName.equals("")) {
                                sequence = defaultIdentityNativeSequence;
                            } else {
                                sequence = (Sequence)defaultIdentityNativeSequence.clone();
                                sequence.setName(generatorName);
                            }
                        }
                    }

                    if (sequence != null) {
                        descriptor.setSequenceNumberName(sequence.getName());
                        login.addSequence(sequence);
                    } else {
                        String seqName;

                        if (generatorName.equals("")) {
                            if (defaultAutoSequence != null) {
                                seqName = defaultAutoSequence.getName();
                            } else {
                                seqName = DEFAULT_AUTO_GENERATOR;
                            }
                        } else {
                            seqName = generatorName;
                        }

                        descriptor.setSequenceNumberName(seqName);
                    }
                }

                if (usesAuto) {
                    if (defaultAutoSequence != null) {
                        login.setDefaultSequence(defaultAutoSequence);
                    }
                }
            }
        }
    }
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

            // Use a temporary sequence generator to build a qualifier to set on
            // the default generator. Don't use this generator as the default
            // auto generator though.
            SequenceGeneratorMetadata tempGenerator = new SequenceGeneratorMetadata(DEFAULT_AUTO_GENERATOR, getPersistenceUnitDefaultCatalog(), getPersistenceUnitDefaultSchema());
            DatasourceLogin login = m_session.getProject().getLogin();
            login.setTableQualifier(tempGenerator.processQualifier());
               
            // 3 - Loop through generated values and set sequences for each.
            for (MetadataClass entityClass : m_generatedValues.keySet()) {
                // Skip setting sequences if our accessor is null, must be a mapped superclass
                ClassAccessor accessor = m_allAccessors.get(entityClass.getName());
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

     * Override the default login creation method.
     * If persistenceInfo is available, use the information from it to setup the login
     * and possibly to set readConnectionPool.
     */
    protected void updateLogins(Map m){
        DatasourceLogin login = (DatasourceLogin)this.session.getDatasourceLogin();

        String eclipselinkPlatform = PropertiesHandler.getPropertyValueLogDebug(PersistenceUnitProperties.TARGET_DATABASE, m, this.session);
        if (eclipselinkPlatform != null) {
            login.setPlatformClassName(eclipselinkPlatform, this.persistenceUnitInfo.getClassLoader());
        }       
        // Check for EIS platform, need to use an EIS login.
        boolean isEIS = false;
        if (login.getDatasourcePlatform() instanceof EISPlatform) {
            isEIS = true;
            EISLogin newLogin = new EISLogin();
            newLogin.setDatasourcePlatform(login.getDatasourcePlatform());
            this.session.setDatasourceLogin(newLogin);
            if (this.session.isServerSession()) {
               for (ConnectionPool pool : ((ServerSession)this.session).getConnectionPools().values()) {
                   pool.setLogin(newLogin);
               }
            }
            login = newLogin;
        }
       
        // Check for EIS or custom (JDBC) Connector class.
        Object connectorValue = getConfigPropertyLogDebug(PersistenceUnitProperties.NOSQL_CONNECTION_SPEC, m, this.session);
        String connectorProperty = PersistenceUnitProperties.NOSQL_CONNECTION_SPEC;
        if (connectorValue == null) {
            connectorValue = getConfigPropertyLogDebug(PersistenceUnitProperties.JDBC_CONNECTOR, m, this.session);
            connectorProperty = PersistenceUnitProperties.JDBC_CONNECTOR;
        }
        if (connectorValue instanceof Connector) {
            login.setConnector((Connector)connectorValue);
        } else if (connectorValue instanceof String) {
            Class cls = null;
            // Try both class loaders.
            try {
                cls = findClassForProperty((String)connectorValue, connectorProperty, this.persistenceUnitInfo.getClassLoader());
            } catch (Throwable failed) {
                cls = findClassForProperty((String)connectorValue, connectorProperty, getClass().getClassLoader());               
            }
            Connector connector = null;
            try {
                Constructor constructor = cls.getConstructor();
                connector = (Connector)constructor.newInstance();
            } catch (Exception exception) {
                throw EntityManagerSetupException.failedToInstantiateProperty((String)connectorValue, connectorProperty, exception);
            }
            if (connector != null) {
                login.setConnector(connector);
            }
        } else if (connectorValue != null) {
            // Assume JCA connection spec.
            ((EISConnectionSpec)login.getConnector()).setConnectionSpecObject(connectorValue);
        }
       
        // Check for EIS ConnectionFactory.
        Object factoryValue = getConfigPropertyLogDebug(PersistenceUnitProperties.NOSQL_CONNECTION_FACTORY, m, this.session);
        if (factoryValue instanceof String) {
            // JNDI name.
            ((EISConnectionSpec)login.getConnector()).setName((String)factoryValue);
        } else if (factoryValue != null) {
            ((EISConnectionSpec)login.getConnector()).setConnectionFactoryObject(factoryValue);
        }
       
        // Process EIS or JDBC connection properties.
        Map propertiesMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.NOSQL_PROPERTY, m, session);
        if (propertiesMap.isEmpty()) {
            propertiesMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.JDBC_PROPERTY, m, session);
        }
        for (Iterator iterator = propertiesMap.entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry entry = (Map.Entry)iterator.next();
            String property = (String)entry.getKey();
            Object value = entry.getValue();
            login.setProperty(property, value);
        }       
       
        // Note: This call does not checked the stored persistenceUnitInfo or extended properties because
        // the map passed into this method should represent the full set of properties we expect to process

        String user = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_USER, m, this.session);
        String password = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_PASSWORD, m, this.session);
        if(user != null) {
            login.setUserName(user);
        }
        if (password != null) {
            login.setPassword(this.securableObjectHolder.getSecurableObject().decryptPassword(password));
        }
       
        PersistenceUnitTransactionType transactionType = this.persistenceUnitInfo.getTransactionType();
        //bug 5867753: find and override the transaction type using properties
        String transTypeString = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.TRANSACTION_TYPE, m, this.session);
        if (transTypeString != null && transTypeString.length() > 0) {
            transactionType = PersistenceUnitTransactionType.valueOf(transTypeString);
        }
        //find the jta datasource
        javax.sql.DataSource jtaDatasource = getDatasourceFromProperties(m, PersistenceUnitProperties.JTA_DATASOURCE, this.persistenceUnitInfo.getJtaDataSource());

        //find the non jta datasource 
        javax.sql.DataSource nonjtaDatasource = getDatasourceFromProperties(m, PersistenceUnitProperties.NON_JTA_DATASOURCE, this.persistenceUnitInfo.getNonJtaDataSource());

        if (isValidationOnly(m, false) && transactionType == PersistenceUnitTransactionType.JTA && jtaDatasource == null) {
            updateLoginDefaultConnector(login, m);
            return;
        }
       
        login.setUsesExternalTransactionController(transactionType == PersistenceUnitTransactionType.JTA);

        // Avoid processing data-source if EIS, as container may pass in a default one.
        if (isEIS) {
            return;
        }
       
        javax.sql.DataSource mainDatasource = null;
        javax.sql.DataSource readDatasource = null;
        if (login.shouldUseExternalTransactionController()) {
            // JtaDataSource is guaranteed to be non null - otherwise exception would've been thrown earlier
            mainDatasource = jtaDatasource;
            // only define readDatasource if there is jta mainDatasource
            readDatasource = nonjtaDatasource;
        } else {
            // JtaDataSource will be ignored because transactionType is RESOURCE_LOCAL
            if (jtaDatasource != null) {
                session.log(SessionLog.WARNING, SessionLog.TRANSACTION, "resource_local_persistence_init_info_ignores_jta_data_source", this.persistenceUnitInfo.getPersistenceUnitName());
            }
            if (nonjtaDatasource != null) {
                mainDatasource = nonjtaDatasource;
            } else {
                updateLoginDefaultConnector(login, m);
                return;
            }
        }

        // mainDatasource is guaranteed to be non null - TODO: No it is not, if they did not set one it is null, should raise error, not null-pointer.
        if (!(login.getConnector() instanceof JNDIConnector)) {
            JNDIConnector jndiConnector;
            if (mainDatasource instanceof DataSourceImpl) {
                //Bug5209363  Pass in the datasource name instead of the dummy datasource
                jndiConnector = new JNDIConnector(((DataSourceImpl)mainDatasource).getName());               
            } else {
                jndiConnector = new JNDIConnector(mainDatasource);                               
            }
            login.setConnector(jndiConnector);
            login.setUsesExternalConnectionPooling(true);
        }

        if (this.session.isServerSession()) {
            // set readLogin
            if (readDatasource != null) {
                DatasourceLogin readLogin = login.clone();
                readLogin.dontUseExternalTransactionController();
                JNDIConnector jndiConnector;
                if (readDatasource instanceof DataSourceImpl) {
                    //Bug5209363  Pass in the datasource name instead of the dummy datasource
                    jndiConnector = new JNDIConnector(((DataSourceImpl)readDatasource).getName());
                } else {
                    jndiConnector = new JNDIConnector(readDatasource);                   
                }
                readLogin.setConnector(jndiConnector);
                ((ServerSession)this.session).setReadConnectionPool(readLogin);
            }
        }
       
    }
View Full Code Here

Examples of org.eclipse.persistence.sessions.DatasourceLogin

            if (sequence != null) {
                serverSession.getSequencingControl().setShouldUseSeparateConnection(Boolean.parseBoolean(sequence));
            }
            String sequenceDataSource = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_DATASOURCE, m, serverSession);
            if (sequenceDataSource != null) {
                DatasourceLogin login = this.session.getLogin().clone();
                login.dontUseExternalTransactionController();
                JNDIConnector jndiConnector = new JNDIConnector(sequenceDataSource);
                login.setConnector(jndiConnector);
                serverSession.getSequencingControl().setLogin(login);
            }       
            // Sizes and shared option are irrelevant for external connection pool
            if (!serverSession.getReadConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
                value = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MIN, m, serverSession);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.