idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
16,100
public String getRemoteClassName ( ) { String strClassName = this . getClass ( ) . getName ( ) . toString ( ) ; int iThinPos = strClassName . indexOf ( Constants . THIN_SUBPACKAGE ) ; return strClassName . substring ( 0 , iThinPos ) + strClassName . substring ( iThinPos + Constants . THIN_SUBPACKAGE . length ( ) ) ; }
Get the remote class name . Just remove thin from this class name! .
16,101
public void setupKeys ( ) { KeyAreaInfo keyArea = null ; keyArea = new KeyAreaInfo ( this , Constants . UNIQUE , ID_KEY ) ; keyArea . addKeyField ( ID , Constants . ASCENDING ) ; }
Set up all the key areas for this record . Override this to add the key areas .
16,102
public synchronized void addPropertyChangeListener ( java . beans . PropertyChangeListener listener ) { if ( propertyChange == null ) propertyChange = new java . beans . PropertyChangeSupport ( this ) ; propertyChange . addPropertyChangeListener ( listener ) ; }
The addPropertyChangeListener method was generated to support the propertyChange field .
16,103
public synchronized void removePropertyChangeListener ( java . beans . PropertyChangeListener listener ) { if ( propertyChange != null ) propertyChange . removePropertyChangeListener ( listener ) ; }
The removePropertyChangeListener method was generated to support the propertyChange field .
16,104
public String getString ( String strResource ) { String strResult = null ; if ( m_menuResourceBundle == null ) { m_menuResourceBundle = new ResourceBundle [ 10 ] ; Class < ? > classResource = this . getClass ( ) ; Locale locale = Locale . getDefault ( ) ; for ( int i = 0 ; i < 10 ; i ++ ) { m_menuResourceBundle [ i ] = null ; if ( classResource != null ) { m_menuResourceBundle [ i ] = this . getRecordResource ( classResource , locale ) ; classResource = classResource . getSuperclass ( ) ; if ( classResource != null ) if ( ( classResource . getName ( ) . equals ( Constants . ROOT_PACKAGE + "base.db.Record" ) ) || ( classResource . getName ( ) . equals ( FieldList . class . getName ( ) ) ) ) classResource = null ; } } } for ( int i = 0 ; i < 10 ; i ++ ) { if ( m_menuResourceBundle [ i ] != null ) { strResult = null ; try { strResult = m_menuResourceBundle [ i ] . getString ( strResource ) ; } catch ( MissingResourceException ex ) { strResult = null ; } if ( ( strResult != null ) && ( strResult . length ( ) > 0 ) ) return strResult ; } } return strResource ; }
Get the string that matches this key . This method traverses the class hierarchy for a matching string that matches this key value . If the resource bundle hasn t been read yet reads the bundle from the . res package .
16,105
public ResourceBundle getRecordResource ( Class < ? > classResource , Locale locale ) { ClassLoader classLoader = this . getClass ( ) . getClassLoader ( ) ; ResourceBundle resourceBundle = null ; String typicalResourceClassName = null ; try { typicalResourceClassName = Util . convertClassName ( classResource . getName ( ) , Constants . RES_SUBPACKAGE , 2 ) + "Resources" ; resourceBundle = ClassServiceUtility . getClassService ( ) . getResourceBundle ( typicalResourceClassName , locale , null , classLoader ) ; } catch ( MissingResourceException ex ) { resourceBundle = null ; } int i = - 1 ; while ( resourceBundle == null ) { String resourceClassName = Util . convertClassName ( classResource . getName ( ) , Constants . RES_SUBPACKAGE , i ) ; if ( resourceClassName == null ) return null ; if ( resourceClassName . equals ( typicalResourceClassName ) ) return null ; resourceClassName = resourceClassName + "Resources" ; try { resourceBundle = ClassServiceUtility . getClassService ( ) . getResourceBundle ( resourceClassName , locale , null , classLoader ) ; } catch ( MissingResourceException ex ) { resourceBundle = null ; } i -- ; } return resourceBundle ; }
Get the record resource bundle .
16,106
public HasData hasData ( ) { boolean scalar = values . containsKey ( "" ) ; boolean vector = scalar ? getCount ( ) > 1 : getCount ( ) > 0 ; return scalar && vector ? HasData . BOTH : scalar ? HasData . SCALAR : vector ? HasData . VECTOR : HasData . NONE ; }
Returns the type of data contained in the parameter .
16,107
public Object get ( String subscript ) { if ( ! values . containsKey ( subscript ) ) { throw new RuntimeException ( "Subscript not found" ) ; } return values . get ( subscript ) ; }
Returns the subscripted vector value . A runtime exception is thrown if no vector value exists at the specified subscript .
16,108
public void assign ( Iterable < ? > source ) { clear ( ) ; int i = 0 ; for ( Object value : source ) { values . put ( Integer . toString ( ++ i ) , value ) ; } }
Copies source values as integer - indexed vector values .
16,109
public void assignArray ( Object source ) { int len = Array . getLength ( source ) ; List < Object > list = new ArrayList < Object > ( len ) ; for ( int i = 0 ; i < len ; i ++ ) { list . add ( Array . get ( source , i ) ) ; } assign ( list ) ; }
Copies source values from an input array as integer - indexed vector values .
16,110
public void put ( Object [ ] subscript , Object value ) { put ( BrokerUtil . buildSubscript ( subscript ) , value ) ; }
Adds a vector value at the specified subscript .
16,111
public int handleMessage ( BaseMessage message ) { try { int iMessageType = Integer . parseInt ( ( String ) message . get ( MessageConstants . MESSAGE_TYPE_PARAM ) ) ; if ( ( iMessageType == Constants . AFTER_UPDATE_TYPE ) || ( iMessageType == Constants . CACHE_UPDATE_TYPE ) ) { SwingUtilities . invokeLater ( new UpdateScreenRecord ( iMessageType ) ) ; } } catch ( NumberFormatException ex ) { } return super . handleMessage ( message ) ; }
Handle this message . Basically if I get a message that the current record changed I re - read the record .
16,112
public void add ( final ITopicNode specTopic , final String key ) { if ( specTopic == null ) return ; final Integer topicId = specTopic . getDBId ( ) ; if ( ! topics . containsKey ( topicId ) ) { topics . put ( topicId , new LinkedList < ITopicNode > ( ) ) ; } if ( ! topicsKeys . containsKey ( key ) ) { topicsKeys . put ( key , new LinkedList < ITopicNode > ( ) ) ; } topics . get ( topicId ) . add ( specTopic ) ; topicsKeys . get ( key ) . add ( specTopic ) ; }
Add a SpecTopic to the database .
16,113
public void setDatabaseDuplicateIds ( ) { for ( final Entry < Integer , List < ITopicNode > > topicTitleEntry : topics . entrySet ( ) ) { final List < ITopicNode > topics = topicTitleEntry . getValue ( ) ; if ( topics . size ( ) > 1 ) { for ( int i = 1 ; i < topics . size ( ) ; i ++ ) { topics . get ( i ) . setDuplicateId ( Integer . toString ( i ) ) ; } } } }
Sets the Duplicate IDs for all the SpecTopics in the Database .
16,114
public boolean isUniqueSpecTopic ( final SpecTopic topic ) { return topics . containsKey ( topic . getDBId ( ) ) ? topics . get ( topic . getDBId ( ) ) . size ( ) == 1 : false ; }
Checks if a topic is unique in the database .
16,115
public List < SpecTopic > getAllSpecTopics ( ) { final ArrayList < SpecTopic > specTopics = new ArrayList < SpecTopic > ( ) ; for ( final Entry < Integer , List < ITopicNode > > topicEntry : topics . entrySet ( ) ) { for ( final ITopicNode topic : topicEntry . getValue ( ) ) { if ( topic instanceof SpecTopic ) { specTopics . add ( ( SpecTopic ) topic ) ; } } } return specTopics ; }
Get a List of all the SpecTopics in the Database .
16,116
public List < ITopicNode > getAllTopicNodes ( ) { final ArrayList < ITopicNode > topicNodes = new ArrayList < ITopicNode > ( ) ; for ( final Entry < Integer , List < ITopicNode > > topicEntry : topics . entrySet ( ) ) { topicNodes . addAll ( topicEntry . getValue ( ) ) ; } return topicNodes ; }
Get a List of all the Topic nodes in the Database .
16,117
public List < SpecNode > getAllSpecNodes ( ) { final ArrayList < SpecNode > retValue = new ArrayList < SpecNode > ( ) ; retValue . addAll ( levels ) ; for ( final Entry < Integer , List < ITopicNode > > topicEntry : topics . entrySet ( ) ) { for ( final ITopicNode topic : topicEntry . getValue ( ) ) { if ( topic instanceof SpecNode ) { retValue . add ( ( SpecNode ) topic ) ; } } } return retValue ; }
Get a List of all the SpecNodes in the Database .
16,118
public Set < String > getIdAttributes ( final BuildData buildData ) { final Set < String > ids = new HashSet < String > ( ) ; for ( final Level level : levels ) { ids . add ( level . getUniqueLinkId ( buildData . isUseFixedUrls ( ) ) ) ; } for ( final Entry < Integer , List < ITopicNode > > topicEntry : topics . entrySet ( ) ) { final List < ITopicNode > topics = topicEntry . getValue ( ) ; for ( final ITopicNode topic : topics ) { if ( topic instanceof SpecTopic ) { final SpecTopic specTopic = ( SpecTopic ) topic ; ids . add ( specTopic . getUniqueLinkId ( buildData . isUseFixedUrls ( ) ) ) ; } } } return ids ; }
Get a list of all the ID Attributes of all the topics and levels held in the database .
16,119
@ SuppressWarnings ( "unchecked" ) public < T extends BaseTopicWrapper < T > > List < T > getAllTopics ( boolean ignoreRevisions ) { final List < T > topics = new ArrayList < T > ( ) ; for ( final Entry < Integer , List < ITopicNode > > entry : this . topics . entrySet ( ) ) { final Integer topicId = entry . getKey ( ) ; if ( ! this . topics . get ( topicId ) . isEmpty ( ) ) { if ( ignoreRevisions ) { topics . add ( ( T ) entry . getValue ( ) . get ( 0 ) . getTopic ( ) ) ; } else { final List < T > specTopicTopics = getUniqueTopicsFromSpecTopics ( entry . getValue ( ) ) ; topics . addAll ( specTopicTopics ) ; } } } return topics ; }
Get all of the Topics that exist in the database . You can either choose to ignore revisions meaning two topics with the same ID but different revisions are classed as the same topic . Or choose to take note of revisions meaning if two topics have different revisions but the same ID they are still classed as different topics .
16,120
@ SuppressWarnings ( "unchecked" ) protected < T extends BaseTopicWrapper < T > > List < T > getUniqueTopicsFromSpecTopics ( final List < ITopicNode > topics ) { final Map < Integer , T > revisionToTopic = new HashMap < Integer , T > ( ) ; for ( final ITopicNode specTopic : topics ) { final T topic = ( T ) specTopic . getTopic ( ) ; final Integer topicRevision = topic . getTopicRevision ( ) ; if ( ! revisionToTopic . containsKey ( topicRevision ) ) { revisionToTopic . put ( topicRevision , topic ) ; } } final List < T > retValue = new ArrayList < T > ( ) ; for ( final Entry < Integer , T > entry : revisionToTopic . entrySet ( ) ) { retValue . add ( entry . getValue ( ) ) ; } return retValue ; }
Get a list of Unique Topics from a list of SpecTopics .
16,121
@ SuppressWarnings ( "unchecked" ) protected List < Task > loadSubtasks ( EntityConfig config , Reagent subtasksPhrase , boolean warnIfMissing ) { final List < Task > subtasks = new LinkedList < Task > ( ) ; final List < Element > taskElements = ( List < Element > ) config . getValue ( subtasksPhrase ) ; final Grammar grammar = config . getGrammar ( ) ; for ( final Element taskElement : taskElements ) { final Task task = grammar . newTask ( taskElement , this ) ; subtasks . add ( task ) ; } if ( warnIfMissing && subtasks . size ( ) == 0 && log . isWarnEnabled ( ) ) { log . warn ( "POSSIBLE PROGRAMMING ERROR: Class '" + getClass ( ) . getName ( ) + "' has an empty collection of " + subtasksPhrase . getName ( ) + "\n\t\tSource: " + config . getSource ( ) + "\n\t\tEntity Name: " + config . getEntryName ( ) ) ; } return subtasks ; }
Abstracts the loading of subtasks for a Reagent into a single menthod
16,122
protected void performSubtasks ( TaskRequest req , TaskResponse res , List < Task > tasks ) { if ( req == null ) { String msg = "Argument 'req' cannot be null." ; throw new IllegalArgumentException ( msg ) ; } if ( res == null ) { String msg = "Argument 'res' cannot be null." ; throw new IllegalArgumentException ( msg ) ; } if ( tasks == null ) { String msg = "Child tasks have not been initialized. Subclasses " + "of AbstractContainerTask must call super.init() " + "within their own init() method." ; throw new IllegalStateException ( msg ) ; } for ( Task k : tasks ) { k . perform ( req , res ) ; } }
Executes a List of Tasks as children of this Task
16,123
public void free ( ) { m_DBObject = null ; while ( m_listener != null ) { this . removeListener ( m_listener , true ) ; } if ( m_vScreenField != null ) { while ( ! m_vScreenField . isEmpty ( ) ) { ScreenComponent sField = this . getComponent ( 0 ) ; sField . free ( ) ; } m_vScreenField . removeAllElements ( ) ; m_vScreenField = null ; } super . free ( ) ; }
Free this field .
16,124
public static BaseField cloneField ( BaseField fieldToClone ) throws CloneNotSupportedException { BaseField field = null ; String strClassName = fieldToClone . getClass ( ) . getName ( ) ; field = ( BaseField ) ClassServiceUtility . getClassService ( ) . makeObjectFromClassName ( strClassName ) ; if ( field != null ) { field . init ( null , fieldToClone . getFieldName ( ) , fieldToClone . getMaxLength ( ) , fieldToClone . getFieldDesc ( ) , fieldToClone . getDefault ( ) ) ; field . setRecord ( fieldToClone . getRecord ( ) ) ; } return field ; }
Creates a new object of the exact same class as this field . The clone method will clone a field that can contain the same kind of data but may not be the exact same field class .
16,125
public void removeListener ( BaseListener listener , boolean bFreeListener ) { if ( m_listener != null ) { if ( m_listener == listener ) { m_listener = ( FieldListener ) listener . getNextListener ( ) ; listener . unlink ( bFreeListener ) ; } else m_listener . removeListener ( listener , bFreeListener ) ; } }
Remove this listener from the chain .
16,126
public static final String addQuotes ( String szTableNames , char charStart , char charEnd ) { String strFileName = szTableNames ; if ( charStart == - 1 ) charStart = DBConstants . SQL_START_QUOTE ; if ( charEnd == - 1 ) charEnd = DBConstants . SQL_END_QUOTE ; for ( int iIndex = 0 ; iIndex < strFileName . length ( ) ; iIndex ++ ) { if ( ( strFileName . charAt ( iIndex ) == charStart ) || ( strFileName . charAt ( iIndex ) == charEnd ) ) { strFileName = strFileName . substring ( 0 , iIndex ) + strFileName . substring ( iIndex , iIndex + 1 ) + strFileName . substring ( iIndex , iIndex + 1 ) + strFileName . substring ( iIndex + 1 , strFileName . length ( ) ) ; iIndex ++ ; } } if ( ( charStart != ' ' ) && ( charEnd != ' ' ) ) strFileName = charStart + strFileName + charEnd ; return strFileName ; }
Add these quotes to this string .
16,127
public void displayField ( ) { if ( m_vScreenField == null ) return ; for ( Enumeration < Object > e = m_vScreenField . elements ( ) ; e . hasMoreElements ( ) ; ) { ScreenComponent sField = ( ScreenComponent ) e . nextElement ( ) ; sField . fieldToControl ( ) ; } }
Display this field using all this field s screen fields .
16,128
public void setEnableListeners ( boolean [ ] rgbEnabled ) { int iIndex = 0 ; FieldListener fieldBehavior = this . getListener ( ) ; while ( fieldBehavior != null ) { boolean bEnable = true ; if ( ( rgbEnabled != null ) && ( iIndex < rgbEnabled . length ) ) bEnable = rgbEnabled [ iIndex ] ; fieldBehavior . setEnabledListener ( bEnable ) ; fieldBehavior = ( FieldListener ) fieldBehavior . getNextListener ( ) ; iIndex ++ ; } }
Get the status of the the FieldChanged behaviors?
16,129
public Object getData ( ) { Object objData = null ; FieldListener nextListener = ( FieldListener ) this . getNextValidListener ( DBConstants . SCREEN_MOVE ) ; if ( nextListener != null ) { boolean bOldState = nextListener . setEnabledListener ( false ) ; objData = nextListener . doGetData ( ) ; nextListener . setEnabledListener ( bOldState ) ; } else objData = this . doGetData ( ) ; return objData ; }
Get the physical binary data from this field . Behaviors are often used to initiate a complicated action only when the system asks for this data .
16,130
public String getFieldName ( boolean bAddQuotes , boolean bIncludeFileName ) { if ( ! bAddQuotes ) if ( ! bIncludeFileName ) return super . getFieldName ( bAddQuotes , bIncludeFileName ) ; String strFieldName = Constants . BLANK ; if ( bIncludeFileName ) if ( this . getRecord ( ) != null ) { strFieldName = this . getRecord ( ) . getTableNames ( bAddQuotes ) ; if ( strFieldName . length ( ) != 0 ) strFieldName += "." ; } strFieldName += Record . formatTableNames ( m_strFieldName , bAddQuotes ) ; return strFieldName ; }
Get this field s name .
16,131
public boolean isSameType ( FieldInfo field ) { boolean bSameType = false ; if ( this . getClass ( ) . getName ( ) . equals ( field . getClass ( ) . getName ( ) ) ) bSameType = true ; else { Object data = this . getData ( ) ; Class < ? > classData = this . getDataClass ( ) ; if ( data != null ) classData = data . getClass ( ) ; Object fieldData = field . getData ( ) ; Class < ? > classField = field . getDataClass ( ) ; if ( fieldData != null ) classField = fieldData . getClass ( ) ; if ( classData . equals ( classField ) ) bSameType = true ; } return bSameType ; }
Are the data in these fields the same type?
16,132
public int moveFieldToThis ( FieldInfo field , boolean bDisplayOption , int iMoveMode ) { if ( this . isSameType ( field ) ) { Object data = field . getData ( ) ; return this . setData ( data , bDisplayOption , iMoveMode ) ; } else { String tempString = field . getString ( ) ; return this . setString ( tempString , bDisplayOption , iMoveMode ) ; } }
Move data to this field from another field . If the data types are the same data is moved otherwise a string conversion is done .
16,133
public int setSFieldToProperty ( ) { int iErrorCode = DBConstants . NORMAL_RETURN ; m_bJustChanged = false ; for ( int iComponent = 0 ; ; iComponent ++ ) { ScreenComponent sField = this . getComponent ( iComponent ) ; if ( sField == null ) break ; iErrorCode = sField . setSFieldToProperty ( null , DBConstants . DISPLAY , DBConstants . READ_MOVE ) ; } if ( iErrorCode == DBConstants . NORMAL_RETURN ) if ( ! this . isJustModified ( ) ) if ( this . getComponent ( 0 ) != null ) { ScreenComponent sField = this . getComponent ( 0 ) ; ComponentParent parentScreen = sField . getParentScreen ( ) ; String strParam = this . getFieldName ( false , true ) ; String strParamValue = parentScreen . getProperty ( strParam ) ; if ( strParamValue != null ) this . setString ( strParamValue , DBConstants . DISPLAY , DBConstants . READ_MOVE ) ; } return iErrorCode ; }
This is a utility method to simplify setting a single field to the field s property .
16,134
public static ScreenComponent createScreenComponent ( String componentType , ScreenLoc itsLocation , ComponentParent targetScreen , Convert converter , int iDisplayFieldDesc , Map < String , Object > properties ) { String screenFieldClass = null ; if ( ! componentType . contains ( "." ) ) screenFieldClass = ScreenModel . BASE_PACKAGE + componentType ; else if ( componentType . startsWith ( "." ) ) screenFieldClass = DBConstants . ROOT_PACKAGE + componentType . substring ( 1 ) ; else screenFieldClass = componentType ; ScreenComponent screenField = ( ScreenComponent ) ClassServiceUtility . getClassService ( ) . makeObjectFromClassName ( screenFieldClass ) ; if ( screenField == null ) { Utility . getLogger ( ) . warning ( "Screen component not found " + componentType ) ; screenField = ( ScreenComponent ) ClassServiceUtility . getClassService ( ) . makeObjectFromClassName ( ScreenModel . BASE_PACKAGE + ScreenModel . EDIT_TEXT ) ; } screenField . init ( itsLocation , targetScreen , converter , iDisplayFieldDesc , properties ) ; return screenField ; }
Create a screen component of this type .
16,135
public void setStartDate ( Date dateStart ) { try { dateStart = m_productItem . getStartDate ( ) ; Date timeNew = m_productItem . setRemoteStartDate ( dateStart ) ; if ( ! timeNew . equals ( dateStart ) ) { Date timeEnd = m_productItem . getRemoteEndDate ( ) ; String strDescription = m_productItem . getRemoteDescription ( ) ; String [ ] rgstrMeals = m_productItem . getMealCache ( timeNew , timeEnd ) ; m_productItem . setCacheData ( timeNew , timeEnd , strDescription , rgstrMeals ) ; } } catch ( Exception ex ) { ex . printStackTrace ( ) ; } try { Thread . sleep ( 2000 ) ; } catch ( InterruptedException e ) { } m_productItem . setStatus ( m_productItem . getStatus ( ) & ~ ( 1 << 1 ) ) ; }
Set the new start date for the remote item .
16,136
public void setEndDate ( Date dateEnd ) { try { dateEnd = m_productItem . getEndDate ( ) ; Date timeNew = m_productItem . setRemoteEndDate ( dateEnd ) ; if ( ! timeNew . equals ( dateEnd ) ) { Date dateStart = m_productItem . getStartDate ( ) ; String [ ] rgstrMeals = m_productItem . getMealCache ( dateStart , dateEnd ) ; m_productItem . setCacheData ( null , timeNew , null , rgstrMeals ) ; } } catch ( Exception ex ) { ex . printStackTrace ( ) ; } try { Thread . sleep ( 2000 ) ; } catch ( InterruptedException e ) { } m_productItem . setStatus ( m_productItem . getStatus ( ) & ~ ( 1 << 1 ) ) ; }
Set the new end date for the remote item .
16,137
public void doNewRecord ( boolean bDisplayOption ) { super . doNewRecord ( bDisplayOption ) ; BaseField fldTarget = null ; if ( typeFieldName != null ) fldTarget = this . getOwner ( ) . getField ( typeFieldName ) ; else fldTarget = this . getOwner ( ) . getField ( m_iTypeField ) ; boolean [ ] rgbEnabled = fldTarget . setEnableListeners ( false ) ; InitOnceFieldHandler listener = ( InitOnceFieldHandler ) fldTarget . getListener ( InitOnceFieldHandler . class . getName ( ) ) ; if ( listener != null ) listener . setFirstTime ( true ) ; fldTarget . setValue ( m_iTargetValue , DBConstants . DISPLAY , DBConstants . INIT_MOVE ) ; fldTarget . setModified ( false ) ; fldTarget . setEnableListeners ( rgbEnabled ) ; }
DoNewRecord Method .
16,138
public boolean doRemoteCriteria ( StringBuffer strbFilter , boolean bIncludeFileName , Vector < BaseField > vParamList ) { BaseField fldTarget = null ; if ( typeFieldName != null ) fldTarget = this . getOwner ( ) . getField ( typeFieldName ) ; else fldTarget = this . getOwner ( ) . getField ( m_iTypeField ) ; String strToCompare = Integer . toString ( m_iTargetValue ) ; boolean bDontSkip = this . fieldCompare ( fldTarget , strToCompare , DBConstants . EQUALS , strbFilter , bIncludeFileName , vParamList ) ; if ( strbFilter != null ) bDontSkip = true ; if ( bDontSkip ) return super . doRemoteCriteria ( strbFilter , bIncludeFileName , vParamList ) ; else return false ; }
Add the criteria to the SQL string .
16,139
public void initRemoteStub ( ObjectOutputStream daOut ) { try { daOut . writeInt ( m_iTypeField ) ; daOut . writeUTF ( typeFieldName ) ; daOut . writeInt ( m_iTargetValue ) ; } catch ( IOException ex ) { ex . printStackTrace ( ) ; } }
InitRemoteStub Method .
16,140
public void initRemoteSkel ( ObjectInputStream daIn ) { try { int iTypeField = daIn . readInt ( ) ; String typeFieldName = daIn . readUTF ( ) ; int iTargetValue = daIn . readInt ( ) ; this . init ( iTypeField , typeFieldName , iTargetValue ) ; } catch ( IOException ex ) { ex . printStackTrace ( ) ; } }
InitRemoteSkel Method .
16,141
public int handleMessage ( BaseMessage message ) { String strClassName = this . getMessageProcessorClassName ( message ) ; if ( ( strClassName == null ) || ( strClassName . length ( ) == 0 ) ) return this . handleOtherMessage ( message ) ; message . consume ( ) ; String strParams = Utility . addURLParam ( null , DBParams . PROCESS , strClassName ) ; App application = m_application ; if ( message . getProcessedByClientSession ( ) instanceof RemoteTask ) if ( message . getProcessedByClientSession ( ) instanceof Task ) application = ( ( Task ) message . getProcessedByClientSession ( ) ) . getApplication ( ) ; MessageProcessRunnerTask task = new MessageProcessRunnerTask ( application , strParams , null ) ; task . setMessage ( message ) ; m_application . getTaskScheduler ( ) . addTask ( task ) ; return DBConstants . NORMAL_RETURN ; }
Handle this message . Get the name of this process and run it .
16,142
public String getMessageProcessorClassName ( BaseMessage message ) { String strClass = ( String ) message . getMessageHeader ( ) . get ( DBParams . PROCESS ) ; if ( ( strClass == null ) || ( strClass . length ( ) == 0 ) ) { String strMessageCode = ( String ) message . getMessageHeader ( ) . get ( BaseMessageHeader . MESSAGE_CODE ) ; if ( ( strMessageCode == null ) || ( strMessageCode . length ( ) == 0 ) ) strMessageCode = ( String ) message . get ( BaseMessageHeader . MESSAGE_CODE ) ; if ( strMessageCode != null ) if ( strMessageCode . length ( ) > 0 ) if ( message instanceof BaseMessage ) { MessageProcessInfoModel recMessageProcessInfo = ( MessageProcessInfoModel ) Record . makeRecordFromClassName ( MessageProcessInfoModel . THICK_CLASS , ( RecordOwner ) m_application . getSystemRecordOwner ( ) ) ; recMessageProcessInfo . setupMessageHeaderFromCode ( ( BaseMessage ) message , strMessageCode , null ) ; recMessageProcessInfo . free ( ) ; strClass = ( String ) message . getMessageHeader ( ) . get ( DBParams . PROCESS ) ; } } String strPackage = ( String ) message . getMessageHeader ( ) . get ( BaseMessageHeader . BASE_PACKAGE ) ; if ( strPackage != null ) if ( strPackage . length ( ) > 0 ) if ( strPackage . charAt ( strPackage . length ( ) - 1 ) != '.' ) strPackage = strPackage + '.' ; if ( ( strClass == null ) || ( strClass . length ( ) == 0 ) ) strClass = m_strProcessClassName ; if ( strClass != null ) if ( strClass . length ( ) > 0 ) { if ( strClass . indexOf ( '.' ) == - 1 ) if ( strPackage != null ) strClass = strPackage + strClass ; if ( strClass . charAt ( 0 ) == '.' ) strClass = DBConstants . ROOT_PACKAGE + strClass . substring ( 1 ) ; } return strClass ; }
Get the message processor class name .
16,143
public void setOwner ( ListenerOwner owner ) { super . setOwner ( owner ) ; if ( owner == null ) return ; if ( m_fldThisFile == null ) if ( thisFileFieldName != null ) m_fldThisFile = this . getOwner ( ) . getField ( thisFileFieldName ) ; if ( m_fldThisFile2 == null ) if ( thisFileFieldName2 != null ) m_fldThisFile2 = this . getOwner ( ) . getField ( thisFileFieldName2 ) ; if ( m_fldThisFile3 == null ) if ( thisFileFieldName3 != null ) m_fldThisFile3 = this . getOwner ( ) . getField ( thisFileFieldName3 ) ; }
Set the record that owns this listener . This method looks up up all the fields in the record .
16,144
public CTX toEqualTo ( R equalsTo ) { to ( rs -> rs . isEqualTo ( equalsTo ) ) ; return context . self ( ) ; }
Convenient method to just check equality
16,145
public static EventType getEventType ( Key key ) { Key ek = findAncestor ( Repository . EVENTTYPE , key ) ; return EventType . values ( ) [ ( int ) ek . getId ( ) - 1 ] ; }
Returns current EventType from EventType Event or Reservation keys
16,146
public static Date getEventDate ( Key key ) { Key ek = findAncestor ( Repository . EVENT , key ) ; return new Date ( ek . getId ( ) ) ; }
Returns current Event Date from Event or Reservation keys
16,147
public void format ( PrintStream out , String [ ] headers , String [ ] ... rows ) { int [ ] columnWidth = computeEachColumnWidth ( this . defaultColumnWidth , headers , rows ) ; printRow ( out , columnWidth , headers ) ; printTableSeperatir ( out , headers , columnWidth ) ; for ( String [ ] row : rows ) { printRow ( out , columnWidth , row ) ; } }
Prints a table
16,148
public static boolean isIpv4 ( String hostName ) { int periodCount = 0 ; int numberCount = 0 ; int lowerCount = 0 ; int upperCount = 0 ; int otherCount = 0 ; for ( int i = 0 ; i < hostName . length ( ) ; i ++ ) { char myChar = hostName . charAt ( i ) ; if ( myChar == '.' ) { periodCount ++ ; } else if ( myChar >= '0' && myChar <= '9' ) { numberCount ++ ; } else if ( myChar >= 'a' & myChar <= 'z' ) { lowerCount ++ ; } else if ( myChar >= 'A' & myChar <= 'Z' ) { upperCount ++ ; } else { otherCount ++ ; } } if ( periodCount == 3 && numberCount >= 4 && lowerCount == 0 && upperCount == 0 && otherCount == 0 ) { return true ; } else { return false ; } }
Return true of the string is an IP address instead of a hostname . No this is not a perfect algorithm but is is close enough . If no number
16,149
public MessageFieldDesc addMessageFieldDesc ( String strParam , Class < ? > classRawObject , boolean bRequired , Object objRawDefault ) { return new MessageFieldDesc ( this , strParam , classRawObject , bRequired , objRawDefault ) ; }
Add the data description for this param .
16,150
public MessageDataDesc getMessageDataDesc ( String strParam ) { if ( strParam == null ) return this ; if ( strParam . equals ( this . getKey ( ) ) ) return this ; if ( m_messageDataDescChildren == null ) { m_messageDataDescChildren = new HashMap < String , MessageDataDesc > ( ) ; this . setupMessageDataDesc ( ) ; } return ( MessageDataDesc ) m_messageDataDescChildren . get ( strParam ) ; }
Get the data description for this param .
16,151
public boolean isSingleDetail ( Rec record ) { boolean bSingleDetail = true ; if ( Boolean . toString ( false ) . equals ( this . getMessage ( ) . getMessageHeader ( ) . get ( BaseMessageHeader . SINGLE_DETAIL_PARAM ) ) ) return false ; return bSingleDetail ; }
Does this message only include a single booking detail item? .
16,152
public int putRawRecordData ( Rec record ) { if ( this . getNodeType ( ) == BaseMessageRecordDesc . NON_UNIQUE_NODE ) this . getMessage ( ) . createNewNode ( this . getFullKey ( null ) ) ; return super . putRawRecordData ( record ) ; }
Move the correct fields from this current record to the map . If this method is used is must be overidden to move the correct fields .
16,153
public void putRawProperties ( PropertyOwner propertyOwner ) { if ( m_messageDataDescChildren != null ) { for ( String strKey : m_messageDataDescChildren . keySet ( ) ) { m_messageDataDescChildren . get ( strKey ) . putRawProperties ( propertyOwner ) ; } } }
Move the data from this propertyowner to this message .
16,154
public void put ( String strKey , Object objValue ) { if ( this . getMessageFieldDesc ( strKey ) != null ) this . getMessageFieldDesc ( strKey ) . put ( objValue ) ; else if ( this . getMessage ( ) != null ) this . getMessage ( ) . putNative ( this . getFullKey ( strKey ) , objValue ) ; }
Convenience method - Put the value for this param in the map . If it is not the correct object type convert it first .
16,155
public Object get ( String strKey ) { Object data = null ; if ( this . getMessageFieldDesc ( strKey ) != null ) data = this . getMessageFieldDesc ( strKey ) . get ( ) ; else if ( this . getMessage ( ) != null ) data = this . getMessage ( ) . getNative ( this . getFullKey ( strKey ) ) ; return data ; }
Convenience method - Get the data at this key .
16,156
public void moveRequestInfoToReply ( Message messageRequest ) { if ( m_messageDataDescChildren != null ) { for ( String strKey : m_messageDataDescChildren . keySet ( ) ) { MessageDataDesc messageDataDesc = m_messageDataDescChildren . get ( strKey ) ; MessageDataDesc requestMessageDataDesc = ( ( BaseMessage ) messageRequest ) . getMessageDataDesc ( messageDataDesc . getFullKey ( null ) ) ; if ( requestMessageDataDesc != null ) messageDataDesc . moveRequestInfoToReply ( messageRequest ) ; } } }
Move the pertinenent information from the request to this reply message . Override this to actually move information .
16,157
public static JWT verify ( String jwt , String secret ) { return verify ( jwt , secret == null ? null : secret . getBytes ( StandardCharsets . UTF_8 ) ) ; }
Verify whether the JWT is valid . If valid return the decoded instance .
16,158
public void removeAppointments ( Anniversary recAnniversary ) { SubFileFilter listener = new SubFileFilter ( this ) ; recAnniversary . addListener ( listener ) ; try { recAnniversary . close ( ) ; while ( recAnniversary . hasNext ( ) ) { recAnniversary . next ( ) ; recAnniversary . edit ( ) ; recAnniversary . remove ( ) ; } } catch ( DBException ex ) { ex . printStackTrace ( ) ; } finally { recAnniversary . removeListener ( listener , true ) ; } }
RemoveAppointments Method .
16,159
public void addAppointments ( Anniversary recAnniversary , Calendar calStart , Calendar calEnd ) { try { Converter . initGlobals ( ) ; Calendar calendar = Converter . gCalendar ; Record recRepeat = ( ( ReferenceField ) this . getField ( AnnivMaster . REPEAT_INTERVAL_ID ) ) . getReference ( ) ; String strRepeat = null ; if ( recRepeat != null ) strRepeat = recRepeat . getField ( RepeatInterval . DESCRIPTION ) . toString ( ) ; char chRepeat ; if ( ( strRepeat == null ) || ( strRepeat . length ( ) == 0 ) ) chRepeat = 'Y' ; else chRepeat = strRepeat . toUpperCase ( ) . charAt ( 0 ) ; int iRepeatCode ; if ( chRepeat == 'D' ) iRepeatCode = Calendar . DATE ; else if ( chRepeat == 'W' ) iRepeatCode = Calendar . WEEK_OF_YEAR ; else if ( chRepeat == 'M' ) iRepeatCode = Calendar . MONTH ; else iRepeatCode = Calendar . YEAR ; short sRepeatCount = ( short ) this . getField ( AnnivMaster . REPEAT_COUNT ) . getValue ( ) ; if ( sRepeatCount == 0 ) sRepeatCount = 1 ; Date timeStart = ( ( DateTimeField ) this . getField ( AnnivMaster . START_DATE_TIME ) ) . getDateTime ( ) ; Date timeEnd = ( ( DateTimeField ) this . getField ( AnnivMaster . END_DATE_TIME ) ) . getDateTime ( ) ; long lTimeLength = - 1 ; if ( timeEnd != null ) lTimeLength = timeEnd . getTime ( ) - timeStart . getTime ( ) ; calendar . setTime ( timeStart ) ; for ( int i = 0 ; i < 100 ; i ++ ) { if ( ( calendar . after ( calStart ) ) && ( calendar . before ( calEnd ) ) ) { timeStart = calendar . getTime ( ) ; timeEnd = null ; if ( lTimeLength != - 1 ) timeEnd = new Date ( timeStart . getTime ( ) + lTimeLength ) ; recAnniversary . addNew ( ) ; ( ( DateTimeField ) recAnniversary . getField ( Anniversary . START_DATE_TIME ) ) . setDateTime ( timeStart , false , DBConstants . SCREEN_MOVE ) ; if ( timeEnd != null ) ( ( DateTimeField ) recAnniversary . getField ( Anniversary . END_DATE_TIME ) ) . setDateTime ( timeEnd , false , DBConstants . SCREEN_MOVE ) ; recAnniversary . getField ( Anniversary . DESCRIPTION ) . moveFieldToThis ( this . getField ( AnnivMaster . DESCRIPTION ) ) ; ( ( ReferenceField ) recAnniversary . getField ( Anniversary . ANNIV_MASTER_ID ) ) . setReference ( this ) ; recAnniversary . getField ( Anniversary . CALENDAR_CATEGORY_ID ) . moveFieldToThis ( this . getField ( AnnivMaster . CALENDAR_CATEGORY_ID ) ) ; recAnniversary . getField ( Anniversary . HIDDEN ) . moveFieldToThis ( this . getField ( AnnivMaster . HIDDEN ) ) ; recAnniversary . add ( ) ; } calendar . add ( iRepeatCode , sRepeatCount ) ; } } catch ( DBException ex ) { ex . printStackTrace ( ) ; } }
AddAppointments Method .
16,160
public Record openMainRecord ( ) { Record record = null ; if ( this . getProperty ( DBParams . APPLET ) != null ) return null ; String strParamRecord = this . getProperty ( DBParams . RECORD ) ; if ( ( strParamRecord != null ) && ( strParamRecord . length ( ) > 0 ) ) record = Record . makeRecordFromClassName ( strParamRecord , this ) ; return record ; }
Open the main file . DataAccessScreens check for a record param .
16,161
public void addPasswordProperty ( String strProperty ) { if ( m_setPropertiesDescriptions == null ) m_setPropertiesDescriptions = new HashSet < String > ( ) ; if ( strProperty != null ) m_setPropertiesDescriptions . add ( strProperty ) ; else m_setPropertiesDescriptions . remove ( strProperty ) ; }
Add this to the list of properties that must be encrypted .
16,162
public void processThisMessage ( ) { Utility . getLogger ( ) . info ( "On message called in receiving process" ) ; try { BaseMessage messageIn = this . getMessage ( ) ; if ( messageIn != null ) { BaseMessage messageReply = this . createReplyMessage ( messageIn ) ; this . moveScreenParamsToMessage ( messageReply ) ; this . getTransport ( ) . setupReplyMessage ( messageReply , messageIn , MessageInfoTypeModel . REPLY , MessageTypeModel . MESSAGE_IN ) ; this . getTransport ( ) . processIncomingMessage ( messageReply , null ) ; } } catch ( Exception ex ) { ex . printStackTrace ( ) ; Debug . print ( ex , "Error in processing or replying to a message" ) ; } }
This is the application code for handling the message . Once the message is received the application can retrieve the soap part the attachment part if there are any or any other information from the message .
16,163
public BaseMessage createReplyMessage ( BaseMessage messageIn ) { BaseMessage replyMessage = ( BaseMessage ) this . getMessageProcessInfo ( ) . createReplyMessage ( messageIn ) ; if ( replyMessage == null ) replyMessage = new TreeMessage ( null , null ) ; if ( replyMessage . getExternalMessage ( ) == null ) new ExternalMapTrxMessageIn ( replyMessage , null ) ; return replyMessage ; }
Given this message in create the reply message .
16,164
public boolean printData ( PrintWriter out , int iPrintOptions ) { this . addHiddenParam ( out , TrxMessageHeader . LOG_TRX_ID , this . getProperty ( TrxMessageHeader . LOG_TRX_ID ) ) ; return super . printData ( out , iPrintOptions ) ; }
PrintData Method .
16,165
public void addPropertiesFieldBehavior ( BaseField fldDisplay , String strProperty ) { BaseField fldProperties = this . getField ( MessageInfo . MESSAGE_PROPERTIES ) ; FieldListener listener = new CopyConvertersHandler ( new PropertiesConverter ( fldProperties , strProperty ) ) ; listener . setRespondsToMode ( DBConstants . INIT_MOVE , false ) ; listener . setRespondsToMode ( DBConstants . READ_MOVE , false ) ; fldDisplay . addListener ( listener ) ; listener = new CopyConvertersHandler ( fldDisplay , new PropertiesConverter ( fldProperties , strProperty ) ) ; listener . setRespondsToMode ( DBConstants . SCREEN_MOVE , false ) ; fldProperties . addListener ( listener ) ; }
AddPropertiesFieldBehavior Method .
16,166
public DB forSite ( final long siteId ) { return siteId == this . siteId ? this : new DB ( this . connectionSupplier , siteId , this . taxonomyTermCaches . keySet ( ) , this . taxonomyCacheTimeout , this . userCache , this . usernameCache , this . metrics ) ; }
Creates a database for another site with shared user caches metrics and taxonomy terms .
16,167
private User userFromResultSet ( final ResultSet rs ) throws SQLException { String niceName = Strings . nullToEmpty ( rs . getString ( 3 ) ) . trim ( ) ; String displayName = Strings . nullToEmpty ( rs . getString ( 4 ) ) . trim ( ) ; String useDisplayName = displayName . isEmpty ( ) ? niceName : displayName ; return new User ( rs . getLong ( 1 ) , rs . getString ( 2 ) , useDisplayName , niceName , rs . getString ( 5 ) , rs . getTimestamp ( 6 ) . getTime ( ) , rs . getString ( 7 ) , ImmutableList . of ( ) ) ; }
Creates a user from a result set .
16,168
public User selectUser ( final long userId ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectUserTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( selectUserByIdSQL ) ; stmt . setLong ( 1 , userId ) ; rs = stmt . executeQuery ( ) ; return rs . next ( ) ? userFromResultSet ( rs ) : null ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } }
Selects a user from the database .
16,169
public User resolveUser ( final long userId ) throws SQLException { metrics . userCacheTries . mark ( ) ; User user = userCache . getIfPresent ( userId ) ; if ( user != null ) { metrics . userCacheHits . mark ( ) ; return user ; } else { user = selectUser ( userId ) ; if ( user != null ) { userCache . put ( userId , user ) ; } return user ; } }
Resolves a user by id possibly with the internal cache .
16,170
public User resolveUser ( final String username ) throws SQLException { metrics . usernameCacheTries . mark ( ) ; User user = usernameCache . getIfPresent ( username ) ; if ( user != null ) { metrics . usernameCacheHits . mark ( ) ; return user ; } else { user = selectUser ( username ) ; if ( user != null ) { usernameCache . put ( username , user ) ; } return user ; } }
Resolves a user by username possibly with the internal cache .
16,171
public boolean deleteUser ( final long userId ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( deleteUserSQL ) ; stmt . setLong ( 1 , userId ) ; return stmt . executeUpdate ( ) > 0 ; } finally { SQLUtil . closeQuietly ( conn , stmt ) ; } }
Deletes a user by id .
16,172
public List < Meta > userMetadata ( final long userId , final String key ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; List < Meta > meta = Lists . newArrayListWithExpectedSize ( 16 ) ; Timer . Context ctx = metrics . userMetadataTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( selectUserMetaKeySQL ) ; stmt . setLong ( 1 , userId ) ; stmt . setString ( 2 , key ) ; rs = stmt . executeQuery ( ) ; while ( rs . next ( ) ) { meta . add ( new Meta ( rs . getLong ( 1 ) , rs . getString ( 2 ) , rs . getString ( 3 ) ) ) ; } return meta ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } }
Selects user metadata with a specified key .
16,173
public void clearUserMeta ( final long userId ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . clearUserMetaTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( deleteUserMetaSQL ) ; stmt . setLong ( 1 , userId ) ; stmt . executeUpdate ( ) ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Clears all metadata for a user .
16,174
public void deletePost ( final long postId ) throws SQLException { clearPostMeta ( postId ) ; Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . deletePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( deletePostIdSQL ) ; stmt . setLong ( 1 , postId ) ; stmt . executeUpdate ( ) ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Deletes a post with a specified id including all associated metadata .
16,175
private Post . Builder postFromResultSet ( final ResultSet rs ) throws SQLException { Post . Builder post = Post . newBuilder ( ) ; post . setId ( rs . getLong ( 1 ) ) ; post . setAuthorId ( rs . getLong ( 2 ) ) ; Timestamp ts = rs . getTimestamp ( 3 ) ; post . setPublishTimestamp ( ts != null ? ts . getTime ( ) : 0L ) ; post . setContent ( Strings . emptyToNull ( rs . getString ( 4 ) ) ) ; post . setTitle ( Strings . emptyToNull ( rs . getString ( 5 ) ) ) ; post . setExcerpt ( Strings . emptyToNull ( rs . getString ( 6 ) ) ) ; post . setStatus ( Post . Status . fromString ( rs . getString ( 7 ) ) ) ; post . setSlug ( Strings . emptyToNull ( rs . getString ( 8 ) ) ) ; ts = rs . getTimestamp ( 9 ) ; post . setModifiedTimestamp ( ts != null ? ts . getTime ( ) : 0L ) ; post . setParentId ( rs . getLong ( 10 ) ) ; post . setGUID ( Strings . emptyToNull ( rs . getString ( 11 ) ) ) ; post . setType ( Post . Type . fromString ( rs . getString ( 12 ) ) ) ; post . setMimeType ( rs . getString ( 13 ) ) ; return post ; }
Builds a post from a result set .
16,176
public List < Post > selectAuthorPosts ( final long userId , final Post . Sort sort , final Paging paging , final boolean withResolve ) throws SQLException { if ( paging . limit < 1 || paging . start < 0 ) { return ImmutableList . of ( ) ; } List < Post . Builder > builders = Lists . newArrayListWithExpectedSize ( paging . limit < 1024 ? paging . limit : 1024 ) ; StringBuilder sql = new StringBuilder ( selectPostSQL ) ; sql . append ( postsTableName ) ; sql . append ( " WHERE post_author=?" ) ; appendPagingSortSQL ( sql , sort , paging ) ; Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectAuthorPostsTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( sql . toString ( ) ) ; stmt . setLong ( 1 , userId ) ; if ( paging . interval != null ) { stmt . setTimestamp ( 2 , new Timestamp ( paging . interval . getStartMillis ( ) ) ) ; stmt . setTimestamp ( 3 , new Timestamp ( paging . interval . getStartMillis ( ) ) ) ; stmt . setInt ( 4 , paging . start ) ; stmt . setInt ( 5 , paging . limit ) ; } else { stmt . setInt ( 2 , paging . start ) ; stmt . setInt ( 3 , paging . limit ) ; } rs = stmt . executeQuery ( ) ; while ( rs . next ( ) ) { builders . add ( postFromResultSet ( rs ) ) ; } } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } List < Post > posts = Lists . newArrayListWithExpectedSize ( builders . size ( ) ) ; for ( Post . Builder builder : builders ) { if ( withResolve ) { posts . add ( resolve ( builder ) . build ( ) ) ; } else { posts . add ( builder . build ( ) ) ; } } return posts ; }
Selects a page of posts for an author .
16,177
public long selectMaxPostId ( ) throws SQLException { Connection conn = null ; Statement stmt = null ; ResultSet rs = null ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . createStatement ( ) ; rs = stmt . executeQuery ( selectMaxPostIdSQL ) ; return rs . next ( ) ? rs . getLong ( 1 ) : 0L ; } finally { closeQuietly ( conn , stmt , rs ) ; } }
Selects the current maximum post id .
16,178
public List < Post > selectPosts ( final Post . Type type , final Post . Status status , final Post . Sort sort , final Paging paging , final boolean withResolve ) throws SQLException { return selectPosts ( type != null ? EnumSet . of ( type ) : null , status , sort , paging , withResolve ) ; }
Selects a page of posts with a specific type .
16,179
public List < Post > selectPosts ( final EnumSet < Post . Type > types , final Post . Status status , final Post . Sort sort , final Paging paging , final boolean withResolve ) throws SQLException { if ( paging . limit < 1 || paging . start < 0 ) { return ImmutableList . of ( ) ; } List < Post . Builder > builders = Lists . newArrayListWithExpectedSize ( paging . limit < 1024 ? paging . limit : 1024 ) ; StringBuilder sql = new StringBuilder ( selectPostSQL ) ; sql . append ( postsTableName ) ; sql . append ( " WHERE post_status=?" ) ; appendPostTypes ( types , sql ) ; appendPagingSortSQL ( sql , sort , paging ) ; Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectPostsTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( sql . toString ( ) ) ; stmt . setString ( 1 , status . toString ( ) . toLowerCase ( ) ) ; if ( paging . interval != null ) { stmt . setTimestamp ( 2 , new Timestamp ( paging . interval . getStartMillis ( ) ) ) ; stmt . setTimestamp ( 3 , new Timestamp ( paging . interval . getEndMillis ( ) ) ) ; stmt . setInt ( 4 , paging . start ) ; stmt . setInt ( 5 , paging . limit ) ; } else { stmt . setInt ( 2 , paging . start ) ; stmt . setInt ( 3 , paging . limit ) ; } rs = stmt . executeQuery ( ) ; while ( rs . next ( ) ) { builders . add ( postFromResultSet ( rs ) ) ; } } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } List < Post > posts = Lists . newArrayListWithExpectedSize ( builders . size ( ) ) ; for ( Post . Builder builder : builders ) { if ( withResolve ) { posts . add ( resolve ( builder ) . build ( ) ) ; } else { posts . add ( builder . build ( ) ) ; } } return posts ; }
Selects a page of posts with a set of specified types .
16,180
public List < Long > selectPostIds ( final Post . Type type , final Post . Status status , final Collection < TaxonomyTerm > terms , final Post . Sort sort , final Paging paging ) throws SQLException { return selectPostIds ( type != null ? EnumSet . of ( type ) : null , status , terms , sort , paging ) ; }
Selects a page of posts with a specified type .
16,181
public List < Long > selectPostIds ( final EnumSet < Post . Type > types , final Post . Status status , final Collection < TaxonomyTerm > terms , final Post . Sort sort , final Paging paging ) throws SQLException { if ( paging . limit < 1 || paging . start < 0 ) { return ImmutableList . of ( ) ; } List < Long > ids = Lists . newArrayListWithExpectedSize ( paging . limit < 1024 ? paging . limit : 1024 ) ; StringBuilder sql = new StringBuilder ( "SELECT ID FROM " ) ; sql . append ( postsTableName ) ; if ( terms != null && terms . size ( ) > 0 ) { sql . append ( "," ) . append ( termRelationshipsTableName ) ; sql . append ( " WHERE post_status=? AND object_id=ID AND " ) ; if ( terms . size ( ) == 1 ) { sql . append ( "term_taxonomy_id=" ) . append ( terms . iterator ( ) . next ( ) . id ) ; } else { sql . append ( "term_taxonomy_id IN (" ) ; Iterator < TaxonomyTerm > iter = terms . iterator ( ) ; sql . append ( iter . next ( ) . id ) ; while ( iter . hasNext ( ) ) { sql . append ( "," ) . append ( iter . next ( ) . id ) ; } sql . append ( ")" ) ; } } else { sql . append ( " WHERE post_status=?" ) ; } appendPostTypes ( types , sql ) ; appendPagingSortSQL ( sql , sort , paging ) ; Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectPostIdsTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( sql . toString ( ) ) ; stmt . setString ( 1 , status . toString ( ) . toLowerCase ( ) ) ; if ( paging . interval != null ) { stmt . setTimestamp ( 2 , new Timestamp ( paging . interval . getStartMillis ( ) ) ) ; stmt . setTimestamp ( 3 , new Timestamp ( paging . interval . getEndMillis ( ) ) ) ; stmt . setInt ( 4 , paging . start ) ; stmt . setInt ( 5 , paging . limit ) ; } else { stmt . setInt ( 2 , paging . start ) ; stmt . setInt ( 3 , paging . limit ) ; } rs = stmt . executeQuery ( ) ; while ( rs . next ( ) ) { ids . add ( rs . getLong ( 1 ) ) ; } } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } return ids ; }
Selects a page of posts with associated terms and a set of types .
16,182
public void deleteChildren ( final long parentId ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . deleteChildrenTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( deleteChildrenSQL ) ; stmt . setLong ( 1 , parentId ) ; stmt . executeUpdate ( ) ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Deletes all children .
16,183
public List < Post > selectChildren ( final long parentId , final boolean withResolve ) throws SQLException { List < Post . Builder > builders = Lists . newArrayListWithExpectedSize ( 4 ) ; Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectChildrenTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( selectChildrenSQL ) ; stmt . setLong ( 1 , parentId ) ; rs = stmt . executeQuery ( ) ; while ( rs . next ( ) ) { builders . add ( postFromResultSet ( rs ) ) ; } } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } List < Post > posts = Lists . newArrayListWithExpectedSize ( builders . size ( ) ) ; for ( Post . Builder builder : builders ) { if ( withResolve ) { posts . add ( resolve ( builder ) . build ( ) ) ; } else { posts . add ( builder . build ( ) ) ; } } return posts ; }
Gets all children for a post .
16,184
private StringBuilder appendPostTypes ( final EnumSet < Post . Type > types , final StringBuilder sql ) { int typesCount = types != null ? types . size ( ) : 0 ; switch ( typesCount ) { case 0 : break ; case 1 : sql . append ( " AND post_type=" ) . append ( String . format ( "'%s'" , types . iterator ( ) . next ( ) . toString ( ) ) ) ; break ; default : sql . append ( " AND post_type IN (" ) ; sql . append ( inJoiner . join ( types . stream ( ) . map ( t -> String . format ( "'%s'" , t . toString ( ) ) ) . collect ( Collectors . toSet ( ) ) ) ) ; sql . append ( ")" ) ; break ; } return sql ; }
Appends post type constraint .
16,185
private StringBuilder appendPagingSortSQL ( final StringBuilder sql , final Post . Sort sort , final Paging paging ) { if ( paging . interval != null ) { sql . append ( " AND post_date" ) ; sql . append ( paging . startIsOpen ? " >" : " >=" ) ; sql . append ( "?" ) ; sql . append ( " AND post_date" ) ; sql . append ( paging . endIsOpen ? " <" : " <=" ) ; sql . append ( "?" ) ; } switch ( sort ) { case ASC : sql . append ( " ORDER BY post_date ASC" ) ; break ; case DESC : sql . append ( " ORDER BY post_date DESC" ) ; break ; case ASC_MOD : sql . append ( " ORDER BY post_modified ASC" ) ; break ; case DESC_MOD : sql . append ( " ORDER BY post_modified DESC" ) ; break ; case ID_ASC : sql . append ( " ORDER BY ID ASC" ) ; break ; case ID_DESC : sql . append ( " ORDER BY ID DESC" ) ; break ; default : sql . append ( " ORDER BY post_date DESC" ) ; break ; } sql . append ( " LIMIT ?,?" ) ; return sql ; }
Appends paging interval constraint if required paging and sort .
16,186
public Post . Builder resolve ( final Post . Builder post ) throws SQLException { Timer . Context ctx = metrics . resolvePostTimer . time ( ) ; try { User author = resolveUser ( post . getAuthorId ( ) ) ; if ( author != null ) { List < Meta > meta = userMetadata ( post . getAuthorId ( ) ) ; if ( meta . size ( ) > 0 ) { author = author . withMetadata ( meta ) ; } post . setAuthor ( author ) ; } List < Meta > meta = selectPostMeta ( post . getId ( ) ) ; if ( meta . size ( ) > 0 ) { post . setMetadata ( meta ) ; } List < TaxonomyTerm > terms = selectPostTerms ( post . getId ( ) ) ; if ( terms . size ( ) > 0 ) { post . setTaxonomyTerms ( terms ) ; } List < Post > children = selectChildren ( post . getId ( ) , false ) ; if ( children . size ( ) > 0 ) { post . setChildren ( children ) ; } return post ; } finally { ctx . stop ( ) ; } }
Resolves user author terms and meta for a post .
16,187
public Post . Builder selectPost ( final long postId ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectPostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( selectPostSQL + postsTableName + " WHERE ID=?" ) ; stmt . setLong ( 1 , postId ) ; rs = stmt . executeQuery ( ) ; return rs . next ( ) ? postFromResultSet ( rs ) : null ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } }
Selects a post by id .
16,188
public Map < Long , Post > selectPostMap ( final Collection < Long > postIds , final boolean withResolve ) throws SQLException { Map < Long , Post > postMap = Maps . newHashMapWithExpectedSize ( postIds . size ( ) ) ; Connection conn = null ; Statement stmt = null ; ResultSet rs = null ; Timer . Context ctx = metrics . selectPostMapTimer . time ( ) ; StringBuilder sql = new StringBuilder ( selectPostSQL ) . append ( postsTableName ) . append ( " WHERE ID IN (" ) ; sql . append ( inJoiner . join ( postIds ) ) ; sql . append ( ")" ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . createStatement ( ) ; rs = stmt . executeQuery ( sql . toString ( ) ) ; while ( rs . next ( ) ) { Post . Builder post = postFromResultSet ( rs ) ; postMap . put ( post . getId ( ) , withResolve ? resolve ( post ) . build ( ) : post . build ( ) ) ; } return postMap ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt , rs ) ; } }
Selects posts from a collection of ids into a map .
16,189
public List < Post > selectPosts ( final Collection < Long > postIds , final boolean withResolve ) throws SQLException { if ( postIds == null || postIds . size ( ) == 0 ) { return ImmutableList . of ( ) ; } Map < Long , Post > postMap = selectPostMap ( postIds , withResolve ) ; List < Post > posts = Lists . newArrayListWithExpectedSize ( postMap . size ( ) ) ; for ( long id : postIds ) { Post post = postMap . get ( id ) ; if ( post != null ) { posts . add ( post ) ; } } return posts ; }
Selects posts from a collection of ids into a list in input order .
16,190
public boolean updatePostTimestamps ( long postId , final long publishTimestamp , final long modifiedTimestamp , final TimeZone tz ) throws SQLException { int offset = tz . getOffset ( publishTimestamp ) ; Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . updatePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostTimestampsSQL ) ; stmt . setTimestamp ( 1 , new Timestamp ( publishTimestamp ) ) ; stmt . setTimestamp ( 2 , new Timestamp ( publishTimestamp - offset ) ) ; stmt . setTimestamp ( 3 , new Timestamp ( modifiedTimestamp ) ) ; stmt . setTimestamp ( 4 , new Timestamp ( modifiedTimestamp - offset ) ) ; stmt . setLong ( 5 , postId ) ; return stmt . executeUpdate ( ) > 0 ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates only the timestamp fields for a post .
16,191
public boolean updatePostContent ( long postId , final String content ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . updatePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostContentSQL ) ; stmt . setString ( 1 , content ) ; stmt . setLong ( 2 , postId ) ; return stmt . executeUpdate ( ) > 0 ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates the content for a post .
16,192
public boolean updatePostExcerpt ( long postId , final String excerpt ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . updatePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostExcerptSQL ) ; stmt . setString ( 1 , excerpt ) ; stmt . setLong ( 2 , postId ) ; return stmt . executeUpdate ( ) > 0 ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates the excerpt for a post .
16,193
public boolean updatePostTitle ( long postId , final String title ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . updatePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostTitleSQL ) ; stmt . setString ( 1 , title ) ; stmt . setLong ( 2 , postId ) ; return stmt . executeUpdate ( ) > 0 ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates the title for a post .
16,194
public boolean updatePostGuid ( long postId , final String guid ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . updatePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostGuidSQL ) ; stmt . setString ( 1 , guid ) ; stmt . setLong ( 2 , postId ) ; return stmt . executeUpdate ( ) > 0 ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates the guid for a post .
16,195
public void updatePostStatus ( final long postId , final Post . Status status ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostStatusSQL ) ; stmt . setString ( 1 , status . toString ( ) . toLowerCase ( ) ) ; stmt . setLong ( 2 , postId ) ; stmt . executeUpdate ( ) ; } finally { SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates the status for a post .
16,196
public boolean updatePostAuthor ( final long postId , final long authorId ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostAuthorSQL ) ; stmt . setLong ( 1 , authorId ) ; stmt . setLong ( 2 , postId ) ; return stmt . executeUpdate ( ) > 0 ; } finally { SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates the author of a post .
16,197
public void updateCommentStatus ( final long postId , final Post . CommentStatus commentStatus , final Post . CommentStatus pingStatus ) throws SQLException { Connection conn = null ; PreparedStatement stmt = null ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostCommentStatusSQL ) ; stmt . setString ( 1 , commentStatus . toString ( ) . toLowerCase ( ) ) ; stmt . setString ( 2 , pingStatus . toString ( ) . toLowerCase ( ) ) ; stmt . setLong ( 3 , postId ) ; stmt . executeUpdate ( ) ; } finally { SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates the comment status for a post .
16,198
public Post updatePost ( Post post , final TimeZone tz ) throws SQLException { if ( post . id < 1L ) { throw new SQLException ( "The post id must be specified for update" ) ; } if ( post . modifiedTimestamp < 1 ) { post = post . modifiedNow ( ) ; } int offset = tz . getOffset ( post . publishTimestamp ) ; Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . updatePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostSQL ) ; stmt . setLong ( 1 , post . authorId ) ; stmt . setTimestamp ( 2 , new Timestamp ( post . publishTimestamp ) ) ; stmt . setTimestamp ( 3 , new Timestamp ( post . publishTimestamp - offset ) ) ; stmt . setString ( 4 , Strings . nullToEmpty ( post . content ) ) ; stmt . setString ( 5 , Strings . nullToEmpty ( post . title ) ) ; stmt . setString ( 6 , Strings . nullToEmpty ( post . excerpt ) ) ; stmt . setString ( 7 , post . status . toString ( ) . toLowerCase ( ) ) ; stmt . setString ( 8 , Strings . nullToEmpty ( post . slug ) ) ; stmt . setTimestamp ( 9 , new Timestamp ( post . modifiedTimestamp ) ) ; stmt . setTimestamp ( 10 , new Timestamp ( post . modifiedTimestamp - offset ) ) ; stmt . setLong ( 11 , post . parentId ) ; stmt . setString ( 12 , Strings . nullToEmpty ( post . guid ) ) ; stmt . setString ( 13 , post . type . toString ( ) . toLowerCase ( ) ) ; stmt . setString ( 14 , post . mimeType != null ? post . mimeType : "" ) ; stmt . setLong ( 15 , post . id ) ; stmt . executeUpdate ( ) ; return post ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Updates a post .
16,199
public void touchPost ( final long postId , final TimeZone tz ) throws SQLException { if ( postId < 1L ) { throw new SQLException ( "The post id must be specified for update" ) ; } long modifiedTimestamp = System . currentTimeMillis ( ) ; int offset = tz . getOffset ( modifiedTimestamp ) ; Connection conn = null ; PreparedStatement stmt = null ; Timer . Context ctx = metrics . updatePostTimer . time ( ) ; try { conn = connectionSupplier . getConnection ( ) ; stmt = conn . prepareStatement ( updatePostModifiedSQL ) ; stmt . setTimestamp ( 1 , new Timestamp ( modifiedTimestamp ) ) ; stmt . setTimestamp ( 2 , new Timestamp ( modifiedTimestamp - offset ) ) ; stmt . setLong ( 3 , postId ) ; stmt . executeUpdate ( ) ; } finally { ctx . stop ( ) ; SQLUtil . closeQuietly ( conn , stmt ) ; } }
Touches the last modified time for a post .