/** * Used by subclasses to resolve deferred values on demand. This is useful when a certain value * comes from a generated key of another master object. */ protected Object getValue(Map<String, Object> valueMap, DbAttribute attribute) { Object value = valueMap.get(attribute.getName()); // if a value is a Factory, resolve it here... // slight chance that a normal value will implement Factory interface??? if (value instanceof Factory) { value = ((Factory) value).create(); valueMap.put(attribute.getName(), value); // update replacement id if (attribute.isPrimaryKey()) { // sanity check if (value == null) { String name = attribute.getEntity() != null ? attribute.getEntity().getName() : "<null>"; throw new CayenneRuntimeException( "Failed to generate PK: " + name + "." + attribute.getName()); } ObjectId id = getObjectId(); if (id != null) { // always override with fresh value as this is what's in the // DB id.getReplacementIdMap().put(attribute.getName(), value); } } } return value; }
@Override public void nodeRemoved(Object nodeId) { ObjectId id = (ObjectId) nodeId; final MutableObjectChange objectChangeSet = changeSet.getOrCreate(id, ObjectChangeType.DELETE); // TODO: rewrite with SelectById query after Cayenne upgrade ObjectIdQuery query = new ObjectIdQuery(id, true, ObjectIdQuery.CACHE); QueryResponse result = channel.onQuery(null, query); @SuppressWarnings("unchecked") List<DataRow> rows = result.firstList(); if (rows.isEmpty()) { LOGGER.warn( "No DB snapshot for object to be deleted, no changes will be recorded. ID: " + id); return; } final DataRow row = rows.get(0); ClassDescriptor descriptor = channel.getEntityResolver().getClassDescriptor(id.getEntityName()); final PostCommitEntity entity = entityFactory.getEntity(id); descriptor.visitProperties( new PropertyVisitor() { @Override public boolean visitAttribute(AttributeProperty property) { if (!entity.isIncluded(property.getName())) { return true; } Object value; if (entity.isConfidential(property.getName())) { value = Confidential.getInstance(); } else { String key = property.getAttribute().getDbAttributeName(); value = row.get(key); } if (value != null) { objectChangeSet.attributeChanged(property.getName(), value, null); } return true; } @Override public boolean visitToOne(ToOneProperty property) { // TODO record FK changes? return true; } @Override public boolean visitToMany(ToManyProperty property) { return true; } }); }
/** * An internal version of {@link #localObject(Object)} that operates on ObjectId instead of * Persistent, and wouldn't attempt to look up an object in the parent channel. * * @since 3.1 */ Persistent findOrCreateObject(ObjectId id) { if (id == null) { throw new IllegalArgumentException("Null ObjectId"); } // have to synchronize almost the entire method to prevent multiple // threads from // messing up dataobjects per CAY-845. Originally only parts of "else" // were // synchronized, but we had to expand the lock scope to ensure // consistent // behavior. synchronized (getGraphManager()) { Persistent cachedObject = (Persistent) getGraphManager().getNode(id); // return an existing object if (cachedObject != null) { int state = cachedObject.getPersistenceState(); // TODO: Andrus, 1/24/2006 implement smart merge for modified // objects... if (state != PersistenceState.MODIFIED && state != PersistenceState.DELETED) { ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(id.getEntityName()); descriptor.injectValueHolders(cachedObject); } return cachedObject; } // create and register a hollow object ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(id.getEntityName()); Persistent localObject = (Persistent) descriptor.createObject(); localObject.setObjectContext(this); localObject.setObjectId(id); getGraphManager().registerNode(id, localObject); localObject.setPersistenceState(PersistenceState.HOLLOW); return localObject; } }
@Override public PostCommitEntity getEntity(ObjectId id) { String entityName = id.getEntityName(); PostCommitEntity descriptor = entities.get(entityName); if (descriptor == null) { PostCommitEntity newDescriptor = createDescriptor(entityName); PostCommitEntity existingDescriptor = entities.putIfAbsent(entityName, newDescriptor); descriptor = (existingDescriptor != null) ? existingDescriptor : newDescriptor; } return descriptor; }
/** * 検索条件を設定した SelectQuery を返します。 <br> * * @param rundata * @param context * @return */ protected SelectQuery<TurbineUser> getSelectQuery(RunData rundata, Context context) { ObjectId oid = new ObjectId("TurbineUser", TurbineUser.USER_ID_PK_COLUMN, 3); Expression exp_base = ExpressionFactory.matchAllDbExp(oid.getIdSnapshot(), Expression.GREATER_THAN); SelectQuery<TurbineUser> query = Database.query(TurbineUser.class, exp_base) .where( Operations.eq(TurbineUser.COMPANY_ID_PROPERTY, Integer.valueOf(1)), Operations.ne(TurbineUser.DISABLED_PROPERTY, "T")); String filter = ALEipUtils.getTemp(rundata, context, LIST_FILTER_STR); String filter_role = ALEipUtils.getTemp(rundata, context, LIST_FILTER_ROLE_STR); currentPost = filter; currentRole = filter_role; if (target_keyword != null && !target_keyword.getValue().equals("")) { String transWord = ALStringUtil.convertHiragana2Katakana( ALStringUtil.convertH2ZKana(target_keyword.getValue())); transWord = transWord.replace(" ", "").replace(" ", ""); // 全角/半角スペースを削除 String[] transWords = transWord.split(""); // 1文字ずつに分解 for (int i = 0; i < transWords.length; i++) { Expression exp11 = ExpressionFactory.likeExp( TurbineUser.FIRST_NAME_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp12 = ExpressionFactory.likeExp( TurbineUser.LAST_NAME_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp13 = ExpressionFactory.likeExp( TurbineUser.FIRST_NAME_KANA_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp14 = ExpressionFactory.likeExp( TurbineUser.LAST_NAME_KANA_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp15 = ExpressionFactory.likeExp( TurbineUser.EMAIL_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp16 = ExpressionFactory.likeExp( TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY + "." + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY + "." + TurbineGroup.GROUP_ALIAS_NAME_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp17 = ExpressionFactory.likeExp( TurbineUser.LOGIN_NAME_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp21 = ExpressionFactory.likeExp( TurbineUser.OUT_TELEPHONE_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp22 = ExpressionFactory.likeExp( TurbineUser.IN_TELEPHONE_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp23 = ExpressionFactory.likeExp( TurbineUser.CELLULAR_PHONE_PROPERTY, "%" + target_keyword.getValue() + "%"); Expression exp31 = ExpressionFactory.likeExp(TurbineUser.FIRST_NAME_PROPERTY, "%" + transWords[i] + "%"); Expression exp32 = ExpressionFactory.likeExp(TurbineUser.LAST_NAME_PROPERTY, "%" + transWords[i] + "%"); Expression exp33 = ExpressionFactory.likeExp( TurbineUser.FIRST_NAME_KANA_PROPERTY, "%" + transWords[i] + "%"); Expression exp34 = ExpressionFactory.likeExp( TurbineUser.LAST_NAME_KANA_PROPERTY, "%" + transWords[i] + "%"); Expression exp35 = ExpressionFactory.likeExp( TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY + "." + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY + "." + TurbineGroup.GROUP_ALIAS_NAME_PROPERTY, "%" + transWords[i] + "%"); query.andQualifier( exp11 .orExp(exp12) .orExp(exp13) .orExp(exp14) .orExp(exp15) .orExp(exp16) .orExp(exp17) .orExp(exp21) .orExp(exp22) .orExp(exp23) .orExp(exp31) .orExp(exp32) .orExp(exp33) .orExp(exp34) .orExp(exp35)); } } // ユーザーの状態によるフィルターが指定されている場合。 if (filter_role != null && !filter_role.equals("")) { // 管理者かどうか if (filter_role.equals(AccountUtils.ROLE_ADMIN.toString())) { try { Group group = JetspeedSecurity.getGroup("LoginUser"); Role adminrole = JetspeedSecurity.getRole("admin"); List<TurbineUserGroupRole> admins = Database.query(TurbineUserGroupRole.class) .where( Operations.eq(TurbineUserGroupRole.TURBINE_ROLE_PROPERTY, adminrole.getId()), Operations.eq(TurbineUserGroupRole.TURBINE_GROUP_PROPERTY, group.getId()), Operations.ne(TurbineUserGroupRole.TURBINE_USER_PROPERTY, 1)) .distinct(true) .fetchList(); List<Integer> admin_ids = new ArrayList<Integer>(); admin_ids.add(Integer.valueOf(1)); for (TurbineUserGroupRole tugr : admins) { admin_ids.add(tugr.getTurbineUser().getUserId()); } query.andQualifier(ExpressionFactory.inDbExp(TurbineUser.USER_ID_PK_COLUMN, admin_ids)); } catch (Exception ex) { logger.error("AccountUserSelectData.getSelectQuery", ex); } } // 有効ユーザーかどうか if (filter_role.equals(AccountUtils.ROLE_ACTIVE.toString())) { query.andQualifier(ExpressionFactory.matchExp(TurbineUser.DISABLED_PROPERTY, "F")); } // 有効ユーザーかどうか if (filter_role.equals(AccountUtils.ROLE_IN_ACTIVE.toString())) { query.andQualifier(ExpressionFactory.matchExp(TurbineUser.DISABLED_PROPERTY, "N")); } } // 部署によるフィルターが指定されている場合。 if (filter != null && !filter.equals("")) { String groupName = (ALEipManager.getInstance().getPostMap().get(Integer.valueOf(filter))) .getGroupName() .getValue(); query.where( Operations.eq( TurbineUser.TURBINE_USER_GROUP_ROLE_PROPERTY + "." + TurbineUserGroupRole.TURBINE_GROUP_PROPERTY + "." + TurbineGroup.GROUP_NAME_PROPERTY, groupName)); } query.distinct(); return query; }