Refine search
public void customize(Session session) throws SQLException { ... for (ClassDescriptor descriptor : session.getDescriptors().values()) { if (!descriptor.getTables().isEmpty() && descriptor.getAlias().equalsIgnoreCase(descriptor.getTableName())) { tableName = TABLE_PREFIX + clazz.getSimpleName(); descriptor.setTableName(tableName); } }
Session session = em.unwrap(Session.class); session.getDescriptor(Employee.class).getOptimisticLockingPolicy().getWriteLockValue(object, id, session);
protected String getSequenceTableName(org.eclipse.persistence.sessions.Session session) { String sequenceTableName = null; if (session.getProject().usesSequencing()) { org.eclipse.persistence.sequencing.Sequence sequence = session.getLogin().getDefaultSequence(); if (sequence instanceof org.eclipse.persistence.sequencing.TableSequence) { sequenceTableName = ((org.eclipse.persistence.sequencing.TableSequence)sequence).getTableName(); } } return sequenceTableName; } }
/** * Looks up the active UnitOfWork using either the global JTA TX or acquires * a new one from the active session. THis method should be used if a session * has already been acquired. */ public UnitOfWork acquireUnitOfWork(Session session) { if (session.hasExternalTransactionController()) { return session.getActiveUnitOfWork(); } return session.acquireUnitOfWork(); }
/** * INTERNAL: * Define the deployment time data associated with logging and profiling * */ protected void updateDeploymentTimeData() { this.deployedSessionLog = (SessionLog)((AbstractSessionLog)session.getSessionLog()).clone(); if (session.getProfiler() == null) { this.deployedSessionProfileWeight = -1;//there is no profiler } else { this.deployedSessionProfileWeight = session.getProfiler().getProfileWeight(); } }
private void destroy(Session session) { try { if (session.isConnected()) { ((DatabaseSession) session).logout(); } } catch (Throwable ignore) { // EL Bug 321843 - Must handle errors from logout. LOG.logThrowable(SessionLog.WARNING, AbstractSessionLog.CONNECTION, ignore); } sessions.remove(session.getName()); session = null; }
public void removeLifecycle(EntityManagerFactory entityManagerFactory, JpaGpsDevice device) throws JpaGpsDeviceException { CompassGpsInterfaceDevice gps = (CompassGpsInterfaceDevice) device.getGps(); JpaEntityManager entityManager = (JpaEntityManager) entityManagerFactory.createEntityManager(); Session session = entityManager.getServerSession(); entityManager.close(); Map descriptors = session.getDescriptors(); for (Object o : descriptors.values()) { ClassDescriptor classDescriptor = (ClassDescriptor) o; Class mappedClass = classDescriptor.getJavaClass(); // if we have a parent class that is mapped in JPA and in Compass, then don't add an event listner // since we will add it to the parent descriptor and it will notify this class as well if (classDescriptor.isChildDescriptor()) { Class parentClass = classDescriptor.getInheritancePolicy().getParentDescriptor().getJavaClass(); if (gps.hasMappingForEntityForMirror(parentClass, Cascade.ALL)) { classDescriptor.getDescriptorEventManager().removeListener(dummyEventListener); continue; } } if (gps.hasMappingForEntityForMirror(mappedClass, Cascade.ALL)) { classDescriptor.getDescriptorEventManager().removeListener(eventListener); } } } }
Object value = xrService.getORSession().getActiveSession().executeQuery(query); getDatasourcePlatform().getConversionManager()). convertObject((Blob) value, ClassConstants.APBYTE); if (xrService.descriptorsByQName.containsKey(resultType)) { XMLDescriptor xdesc = xrService.descriptorsByQName.get(resultType); ClassDescriptor desc = xrService.getORSession().getDescriptorForAlias(xdesc.getAlias()); if (desc.isAggregateDescriptor() && !desc.isObjectRelationalDataTypeDescriptor() && !desc.isRelationalDescriptor()) { if (isCollection()) { XRDynamicEntity_CollectionWrapper xrCollWrapper = new XRDynamicEntity_CollectionWrapper(); ClassDescriptor desc = xrService.getORSession().getDescriptorForAlias(xdesc.getAlias()); targetObject = desc.getObjectBuilder().buildNewInstance(); Object[] objs = new Object[1];
/** * Checks class descriptors for {@link @DisableVersioning} annotations at the class level and removes the version * database mapping for optimistic locking. * * @param session the current session. */ protected void handleDisableVersioning(Session session) { Map<Class, ClassDescriptor> descriptors = session.getDescriptors(); if (descriptors == null || descriptors.isEmpty()) { return; } for (ClassDescriptor classDescriptor : descriptors.values()) { if (classDescriptor != null && AnnotationUtils.findAnnotation(classDescriptor.getJavaClass(), DisableVersioning.class) != null) { OptimisticLockingPolicy olPolicy = classDescriptor.getOptimisticLockingPolicy(); if (olPolicy != null) { classDescriptor.setOptimisticLockingPolicy(null); } } } }
@Override public void customize(final Session session) throws Exception { if (JPAThreadContext.infos.containsKey("properties")) { final String prefix = ((Properties) JPAThreadContext.infos.get("properties")).getProperty("openejb.jpa.table_prefix"); final List<DatabaseTable> tables = new ArrayList<DatabaseTable>(); for (final ClassDescriptor cd : session.getDescriptors().values()) { for (final DatabaseTable table : cd.getTables()) { update(prefix, tables, table); } for (final DatabaseMapping mapping : cd.getMappings()) { if (mapping instanceof ManyToManyMapping) { update(prefix, tables, ((ManyToManyMapping) mapping).getRelationTable()); } else if (mapping instanceof DirectCollectionMapping) { update(prefix, tables, ((DirectCollectionMapping) mapping).getReferenceTable()); } // TODO: else check we need to update something } } final Sequence sequence = session.getDatasourcePlatform().getDefaultSequence(); if (sequence instanceof TableSequence) { final TableSequence ts = ((TableSequence) sequence); ts.setName(prefix + ts.getName()); } } }
/** * Checks class descriptors for {@link @RemoveMapping} and {@link RemoveMappings} annotations at the class level * and removes any specified mappings from the ClassDescriptor. * * @param session the current session. */ protected void handleRemoveMapping(Session session) { Map<Class, ClassDescriptor> descriptors = session.getDescriptors(); if (descriptors == null || descriptors.isEmpty()) { return; } for (ClassDescriptor classDescriptor : descriptors.values()) { List<DatabaseMapping> mappingsToRemove = new ArrayList<DatabaseMapping>(); List<RemoveMapping> removeMappings = scanForRemoveMappings(classDescriptor); for (RemoveMapping removeMapping : removeMappings) { if (StringUtils.isBlank(removeMapping.name())) { throw DescriptorException.attributeNameNotSpecified(); } DatabaseMapping databaseMapping = classDescriptor.getMappingForAttributeName(removeMapping.name()); if (databaseMapping == null) { throw DescriptorException.mappingForAttributeIsMissing(removeMapping.name(), classDescriptor); } mappingsToRemove.add(databaseMapping); } for (DatabaseMapping mappingToRemove : mappingsToRemove) { classDescriptor.removeMappingForAttributeName(mappingToRemove.getAttributeName()); } } }
@Override public void customize(Session session) throws Exception { Map<Class, ClassDescriptor> descriptors = session.getDescriptors(); for (ClassDescriptor classDescriptor : descriptors.values()) { for (DatabaseMapping databaseMapping : classDescriptor.getMappings()) { if (databaseMapping.isAggregateObjectMapping()) { AggregateObjectMapping m = (AggregateObjectMapping) databaseMapping; for (DatabaseMapping refMapping : refDesc.getMappings()) { if (refMapping.isDirectToFieldMapping()) { DirectToFieldMapping refDirectMapping = (DirectToFieldMapping) refMapping;
/** * This method will return the objects's Id. * If the descriptor associated with the domain object is null - an IllegalArgumentException is thrown. * If the CMPPolicy associated with the domain object's descriptor is null * the Id will be determined using the ObjectBuilder on the descriptor - which may return * the Id stored in the weaved _persistence_primaryKey field. * @See {@link JpaCache#getId(Object)} */ public Object getId(Object object) { getEntityManagerFactory().verifyOpen(); ClassDescriptor aDescriptor = getSession().getDescriptor(object.getClass()); // Handle a null descriptor from a detached entity (closed EntityManager), or the entity exists in another session if(null == aDescriptor) { throw new IllegalArgumentException(ExceptionLocalization.buildMessage( "cache_impl_object_has_no_descriptor_is_not_a_persistent_type", new Object[] {object})); } // Handle a null CMPPolicy from a MappedSuperclass if(!aDescriptor.hasCMPPolicy()) { // the following code gets the key either from the weaved _persistence_primaryKey field or using valueFromObject() if not bytecode enhanced return aDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(object, (AbstractSession)getSession()); } else { // Get identifier via EMF return getEntityManagerFactory().getIdentifier(object); } }
@Override public Object convertObjectValueToDataValue(Object objectValue, Session session) { if (session.getPlatform() instanceof PostgreSQLPlatform) { return objectValue; } else if (session.getPlatform() instanceof SQLServerPlatform) { return objectValue != null ? objectValue.toString().toUpperCase() : null; // for correct binding of batch query results } else if (session.getPlatform() instanceof OraclePlatform || session.getPlatform() instanceof MySQLPlatform) { return objectValue != null ? objectValue.toString().replace("-", "") : null; } else { return objectValue != null ? objectValue.toString() : null; } }
private void setCacheable(MetaClass metaClass, ClassDescriptor desc, Session session) { String property = (String) session.getProperty("eclipselink.cache.shared.default"); boolean defaultCache = property == null || Boolean.valueOf(property); if ((defaultCache && !desc.isIsolated()) || desc.getCacheIsolation() == CacheIsolationType.SHARED || desc.getCacheIsolation() == CacheIsolationType.PROTECTED) { metaClass.getAnnotations().put("cacheable", true); desc.getCachePolicy().setCacheCoordinationType(CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS); } }
public Object convertDataValueToObjectValue(Object dataValue, Session session) { if ("".equals(dataValue)) { return Boolean.TRUE; } return session.getDatasourcePlatform().getConversionManager().convertObject(dataValue, Boolean.class); }
if (session.isUnitOfWork()) { shouldLoadResultIntoSelectionObject = !((UnitOfWork)session).isObjectRegistered(entity); } else { shouldLoadResultIntoSelectionObject = !session.getIdentityMapAccessor().containsObjectInIdentityMap(entity); ClassDescriptor.DeletePredicate deletePredicate = session.getClassDescriptor(entity).getDeletePredicate(); boolean isDeleted = deletePredicate != null && deletePredicate.isDeleted(entity); if (isDeleted && CubaUtil.isSoftDeletion()) { Boolean prevSoftDeletion = CubaUtil.setSoftDeletion(false); try { result = session.executeQuery(query); } finally { CubaUtil.setSoftDeletion(prevSoftDeletion); result = session.executeQuery(query);
public class MySessionCustomizer implements SessionCustomizer { private static String schemaName; public static void setSchemaName(String schemaName) { MySessionCustomizer.schemaName = schemaName; } @Override public void customize(Session session) throws Exception { if (StringUtils.hasText(this.schemaName)) { session.getLogin().setTableQualifier(this.schemaName); } } }
Object proxyTypeValue = session.getProperty(PersistenceUnitProperties.ORACLE_PROXY_TYPE); try { proxyType = ((Integer)session.getPlatform().getConversionManager().convertObject(proxyTypeValue, Integer.class)).intValue(); } catch (ConversionException conversionException) { throw ValidationException.oracleJDBC10_1_0_2ProxyConnectorRequiresIntProxytype(); String proxyUserName = (String)session.getProperty(OracleConnection.PROXY_USER_NAME); if(proxyUserName != null) { proxyProperties.setProperty(OracleConnection.PROXY_USER_NAME, proxyUserName); String distinguishedName = (String)session.getProperty(OracleConnection.PROXY_DISTINGUISHED_NAME); if(distinguishedName != null) { proxyProperties.setProperty(OracleConnection.PROXY_DISTINGUISHED_NAME, distinguishedName); Object certificate = session.getProperty(OracleConnection.PROXY_CERTIFICATE); if(certificate != null) { proxyProperties.put(OracleConnection.PROXY_CERTIFICATE, certificate); ValidationException.unknownProxyType(proxyType, "OracleConnection.PROXYTYPE_USER_NAME", "OracleConnection.PROXYTYPE_DISTINGUISHED_NAME", "OracleConnection.PROXYTYPE_CERTIFICATE"); String proxyUserPassword = (String)session.getProperty(OracleConnection.PROXY_USER_PASSWORD); Object proxyRoles = session.getProperty(OracleConnection.PROXY_ROLES);
@Override public Object invoke(XRServiceAdapter xrService, Invocation invocation) { DatabaseQuery query = classDescriptor.getQueryManager().getQuery(getFindByPKQuery()); query = ((JPAQuery) query).processSQLQuery(xrService.getORSession().getActiveSession()); UnitOfWork uow = xrService.getORSession().acquireUnitOfWork(); Object toBeDeleted;