Skip to content

Commit

Permalink
SAK-41216 Enable caching for Sakai Person (sakaiproject#6489)
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored and adrianfish committed Oct 17, 2019
1 parent ae917ec commit b36ebc4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public Object doInHibernate(Session session) throws HibernateException
Query q = session.getNamedQuery(HQL_FIND_SAKAI_PERSON_BY_AGENT_AND_TYPE);
q.setParameter(AGENT_UUID, agentUuid, StringType.INSTANCE);
q.setParameter(TYPE_UUID, recordType.getUuid(), StringType.INSTANCE);
// q.setCacheable(false);
q.setCacheable(true);
return q.uniqueResult();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.SQLException;

import javax.sql.rowset.serial.SerialBlob;

import lombok.extern.slf4j.Slf4j;

import org.sakaiproject.api.common.edu.person.InetOrgPerson;
import org.sakaiproject.api.common.edu.person.OrganizationalPerson;
import org.sakaiproject.api.common.edu.person.Person;
import org.sakaiproject.component.cover.ServerConfigurationService;

import lombok.extern.slf4j.Slf4j;

/**
* @author <a href="mailto:[email protected]">Lance Speelmon </a>
Expand Down Expand Up @@ -537,108 +529,4 @@ public void setSecretary(String secretary)
{
this.secretary = secretary;
}

public Blob getBlobImage()
{
if (this.jpegPhoto == null || jpegPhoto.length < 1 || ServerConfigurationService.getString("profile.photoRepositoryPath", null) != null)
{
return null;
}
try {
return new SerialBlob(this.jpegPhoto);
} catch (SQLException e) {
log.warn(e.getMessage(), e);
return null;
}
}

public void setBlobImage(Blob blobImage)
{
this.jpegPhoto = toByteArray(blobImage);
}

private byte[] toByteArray(Blob fromBlob)
{
if (log.isDebugEnabled())
{
log.debug("toByteArray(Blob " + fromBlob + ")");
}

try
{
if (fromBlob == null || fromBlob.length() < 1)
{
return null;
}
}
catch (SQLException e1)
{
log.error(e1.getMessage(), e1);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try
{
return toByteArray(fromBlob, baos);
}
catch (Exception e)
{
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
finally
{
if (baos != null)
{
try
{
baos.close();
}
catch (IOException ex)
{
log.error(ex.getMessage(), ex);
}
}
}
}

private byte[] toByteArray(Blob fromBlob, ByteArrayOutputStream baos) throws SQLException, IOException
{
if (log.isDebugEnabled())
{
log.debug("toByteArray(Blob " + fromBlob + ", ByteArrayOutputStream " + baos + ")");
}

if (fromBlob == null || fromBlob.length() < 1 || ServerConfigurationService.getString("profile.photoRepositoryPath", null) != null)
{
return null;
}
byte[] buf = new byte[4000];
InputStream is = fromBlob.getBinaryStream();
try
{
for (;;)
{
int dataSize = is.read(buf);

if (dataSize == -1) break;
baos.write(buf, 0, dataSize);
}
}
finally
{
if (is != null)
{
try
{
is.close();
}
catch (IOException ex)
{
log.error(ex.getMessage(), ex);
}
}
}
return baos.toByteArray();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
table="SAKAI_PERSON_T" optimistic-lock="version"
discriminator-value="P">

<!-- Hibernate cannot cache BLOB types :( -->
<!-- <cache usage="read-write" /> -->
<cache usage="read-write" />

<id name="id">
<column name="ID" not-null="true" length="19" />
Expand Down Expand Up @@ -76,8 +75,9 @@
<property name="homePhone" column="HOME_PHONE" />
<property name="homePostalAddress" column="HOME_POSTAL_ADDRESS" />
<property name="initials" column="INITIALS" />
<!-- blobImage is a workaround for Oracle and BLOB handling with jpegPhoto byte[] property -->
<property name="blobImage" type="blob" column="JPEG_PHOTO" />
<property name="jpegPhoto" type="binary">
<column name="JPEG_PHOTO" length="4194304"/>
</property>
<property name="labeledURI" column="LABELED_URI" />
<property name="mail" column="MAIL" />
<property name="manager" column="MANAGER" />
Expand Down
4 changes: 4 additions & 0 deletions kernel/kernel-common/src/main/config/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ log4j.logger.velocity=INFO
#log4j.logger.com.zaxxer.hikari=DEBUG
#log4j.logger.org.springframework=DEBUG

# SQL statements and parameters
#log4j.logger.org.hibernate.SQL=DEBUG
#log4j.logger.org.hibernate.type.descriptor.sql=TRACE

# Ignore erroneous MyFaces warnings
log4j.logger.org.apache.myfaces=WARN
log4j.logger.org.apache.myfaces.el.VariableResolverImpl=ERROR
Expand Down

0 comments on commit b36ebc4

Please sign in to comment.