📄 queryimpl.java
字号:
m_mc.getQuerySaveQueue().add(this);
return;
}
try {
IQueryDAO dao = null;
QueryRecord record = createRecord();
dao = m_daoProfile.getQueryDAO();
if (dao == null) {
LOG.error(ERROR_NULL_QUERY_DAO_OBJECT);
throw new IllegalArgumentException(ERROR_NULL_QUERY_DAO_OBJECT);
}
if (m_isNew) {
if (LOG.isInfoEnabled()) {
LOG.info(MessageFormat.format(INFO_INSERTING_QUERY,
getId(), getName()));
}
dao.insert(record);
} else {
if (LOG.isInfoEnabled()) {
LOG.info(MessageFormat.format(INFO_UPDATING_QUERY, getId(),
getName()));
}
dao.update(record);
}
m_isNew = false;
m_info = record;
} catch (JAXBException e) {
throw new PersonalizationException(PersonalizationException.Code.SERIALIZATION_ERROR,
e);
} catch (PersonalizationDAOException e) {
throw new PersonalizationException(PersonalizationException.Code.STORE_DATA_ERROR,
e);
}
}
/**
* Sets the IsNew property of this Query.
*
* @param isNew Indicates if the Query is new.
*/
public void setNew(boolean isNew) {
m_isNew = isNew;
}
/**
* Sets the reference to the profile of DAO objects that will be used
* to retrieve and store personalization data.
*
* @param profile Contains references to all DAO objects, cannot
* be <code>null</code>.
*
* @throws NullPointerException Thrown if the <code>profile</code>
* argument is <code>null</code>
*/
public void setPersonalizationDAOProfile(IPersonalizationDAOProfile profile) {
if (profile == null) {
throw new NullPointerException();
}
m_daoProfile = profile;
}
/**
* Sets the User that created this Query.
*
* @param user User that created Query.
*/
public void setCurrentUser(IUser user) {
m_currentUser = user;
}
/**
* Sets the reference to the Query Information. This is typically
* produced by a Data Access Object. It contains metadata on a Query
* such as ID, Name, and Description.
*
* @param info Query Metadata Information, cannot be <code>null</code>.
*
* @throws NullPointerException Thrown if the <code>info</code> argument
* is <code>null</code>.
*/
public void setQueryInfoRecord(QueryInfoRecord rec) {
if (rec == null) {
throw new NullPointerException();
}
m_info = rec;
}
/**
* Sets the reference to the Map Composition that is associated with this
* Query. This method will accept a <code>null</code> argument value.
*
* @param mc Reference to Map Composition associated with this
* Query, can be <code>null</code>.
*/
public void setMapComposition(MapCompositionImpl mc) {
m_mc = mc;
}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof QueryImpl)) {
return false;
}
QueryImpl query = (QueryImpl) obj;
return query.toString().equals(toString());
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return toString().hashCode();
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("ID:[");
sb.append(getId());
sb.append("],Name:[");
sb.append(getName());
sb.append("],Description:[");
sb.append(getDescription());
sb.append("]");
return sb.toString();
}
private QueryRecord createRecord() throws JAXBException {
QueryRecord record = new QueryRecord();
record.setCreator(m_currentUser.getId().getUsername());
record.setId(m_bean.getId());
record.setName(m_bean.getName());
record.setDescription(m_bean.getDescription());
record.setTimeModified(new java.sql.Timestamp(
System.currentTimeMillis()));
byte[] data = marshallBean();
record.setData(data);
if ((m_mc != null) && (m_mc.getId() != null)) {
record.setMapCompositionId(m_mc.getId().toString());
}
if (m_bean instanceof FeatureQueryType) {
record.setQueryType(IQuery.Type.FEATURE.ordinal());
} else if (m_bean instanceof CatalogQueryType) {
record.setQueryType(IQuery.Type.CATALOG.ordinal());
} else {
record.setQueryType(-1);
}
return record;
}
private byte[] marshallBean() throws JAXBException {
JAXBContext ctx = null;
ctx = JAXBContext.newInstance(JAXB_BEAN_PACKAGE_NAME);
Marshaller marshaller = ctx.createMarshaller();
ByteArrayOutputStream out = new ByteArrayOutputStream();
marshaller.marshal(m_bean, out);
byte[] data = out.toByteArray();
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(DEBUG_QUERY_DATA_AFTER_MARSHALLING,
getId(), getName(), new String(data)));
}
return data;
}
private void unmarshallBean(byte[] data) throws JAXBException {
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(
DEBUG_QUERY_DATA_BEFORE_UNMARSHALLING, getId(), getName(),
new String(data)));
}
JAXBContext ctx = null;
ctx = JAXBContext.newInstance(JAXB_BEAN_PACKAGE_NAME);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
m_bean = (QueryType) unmarshaller.unmarshal(new ByteArrayInputStream(
data));
}
public Type getType() {
return m_type;
}
public void setType(Type type) {
m_type = type;
}
/**
* Protects the {@link QueryType} bean from having its ID
* property modified. Don't want callers to be able to change the
* ID. The ID will be managed by this class.
*/
private class ProtectIDModification implements InvocationHandler {
/**
* Reference to the {@link BookmarkType} bean
*/
private QueryType m_bean;
/**
* Constructs a new <code>ProtectIDModification</code> object
* with a reference to a {@link QueryType} bean.
*
* @param bean Reference to {@link QueryType} bean.
*/
public ProtectIDModification(QueryType bean) {
m_bean = bean;
}
/*
* (non-Javadoc)
* @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
*/
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if (!method.getName().equals("setId")) {
return method.invoke(m_bean, args);
} else {
LOG.info("Attempting to setId on QueryType, not allowed.");
}
return Void.TYPE;
}
}
public IUserId getCreator() {
if (m_info != null) {
UserIdImpl userId = new UserIdImpl();
userId.setUsername(m_info.getCreator());
return userId;
}
return m_currentUser.getId();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -